From 683de566ba363bb9b189675c6299bf4b5cbf2620 Mon Sep 17 00:00:00 2001 From: andy <1042025947@qq.com> Date: Wed, 27 May 2026 09:29:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.ts | 29 +++++++++++++---------------- vite.config.ts | 1 + 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/router/index.ts b/src/router/index.ts index ae21a99..d36eb22 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,6 +1,6 @@ import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router' import { useUserStore } from '@/stores/user' -import type { MenuInfo } from '@/api/auth' +//import type { MenuInfo } from '@/api/auth' // 动态导入所有页面组件 const modules = import.meta.glob('/src/views/**/*.vue') @@ -220,7 +220,7 @@ const routes: RouteRecordRaw[] = [ ] }, { - path: '/:pathMatch(.*)*', + path: '/:pathMatch(.*)', name: 'NotFound', component: () => import('@/views/error/404.vue'), meta: { title: '404', requiresAuth: false } @@ -237,11 +237,10 @@ const addedRouteNames = new Set() /** * 根据菜单动态添加新路由(只添加静态路由中没有的) - */ -export function addDynamicRoutes(menus: MenuInfo[]) { - console.log('[动态路由] 开始处理菜单:', menus) - - const addRoutes = (menuList: MenuInfo[]) => { + */ +export function addDynamicRoutes(menus: any) { //MenuInfo[] + //console.log('[动态路由] 开始处理菜单:', menus) + const addRoutes = (menuList: any) => { //MenuInfo[] for (const menu of menuList) { // 只处理菜单类型(type=2),且有 path if (menu.type === 2 && menu.path) { @@ -253,12 +252,12 @@ export function addDynamicRoutes(menus: MenuInfo[]) { const pathExists = existingRoutes.some(r => r.path === '/' + menuPath || r.path === menuPath) if (pathExists) { - console.log(`[动态路由] 跳过(已存在): ${menuPath}`) + // console.log(`[动态路由] 跳过(已存在): ${menuPath}`) continue } if (addedRouteNames.has(routeName)) { - console.log(`[动态路由] 跳过(已添加): ${menuPath}`) + //console.log(`[动态路由] 跳过(已添加): ${menuPath}`) continue } @@ -284,7 +283,7 @@ export function addDynamicRoutes(menus: MenuInfo[]) { const componentPath = `/src/views/${componentName}.vue` const component = modules[componentPath] - console.log(`[动态路由] 处理: path=${menuPath}, component=${componentPath}, 组件存在=${!!component}`) + //console.log(`[动态路由] 处理: path=${menuPath}, component=${componentPath}, 组件存在=${!!component}`) if (component) { router.addRoute('Layout', { @@ -298,9 +297,9 @@ export function addDynamicRoutes(menus: MenuInfo[]) { } }) addedRouteNames.add(routeName) - console.log(`[动态路由] ✓ 添加成功: ${menuPath}`) + //console.log(`[动态路由] ✓ 添加成功: ${menuPath}`) } else { - console.warn(`[动态路由] ✗ 组件不存在: ${componentPath}`) + //console.warn(`[动态路由] ✗ 组件不存在: ${componentPath}`) } } } @@ -313,7 +312,7 @@ export function addDynamicRoutes(menus: MenuInfo[]) { } addRoutes(menus) - console.log('[动态路由] 当前所有路由:', router.getRoutes().map(r => r.path)) + //console.log('[动态路由] 当前所有路由:', router.getRoutes().map(r => r.path)) } /** @@ -333,7 +332,6 @@ router.beforeEach(async (to, _from, next) => { const userStore = useUserStore() //document.title = `${to.meta.title || ''} - CSY Admin` - if (to.meta.requiresAuth === false) { next() return @@ -343,7 +341,7 @@ router.beforeEach(async (to, _from, next) => { next({ name: 'Login', query: { redirect: to.fullPath } }) return } - + if (!userStore.user) { try { await userStore.getInfo() @@ -357,7 +355,6 @@ router.beforeEach(async (to, _from, next) => { return } } - next() }) diff --git a/vite.config.ts b/vite.config.ts index 2beb901..ea60498 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -21,6 +21,7 @@ export default defineConfig({ proxy: { '/api': { target:'http://192.168.6.107:8080', //'http://192.168.5.230:8888', + //target:'http://192.168.5.230:8888', changeOrigin: true }, '/druid': {