This commit is contained in:
andy 2026-05-27 09:29:57 +08:00
parent 054cdc265f
commit 683de566ba
2 changed files with 14 additions and 16 deletions

View File

@ -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<string>()
/**
*
*/
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()
})

View File

@ -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': {