提交
This commit is contained in:
parent
054cdc265f
commit
683de566ba
@ -1,6 +1,6 @@
|
|||||||
import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
|
import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
|
||||||
import { useUserStore } from '@/stores/user'
|
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')
|
const modules = import.meta.glob('/src/views/**/*.vue')
|
||||||
@ -220,7 +220,7 @@ const routes: RouteRecordRaw[] = [
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/:pathMatch(.*)*',
|
path: '/:pathMatch(.*)',
|
||||||
name: 'NotFound',
|
name: 'NotFound',
|
||||||
component: () => import('@/views/error/404.vue'),
|
component: () => import('@/views/error/404.vue'),
|
||||||
meta: { title: '404', requiresAuth: false }
|
meta: { title: '404', requiresAuth: false }
|
||||||
@ -237,11 +237,10 @@ const addedRouteNames = new Set<string>()
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据菜单动态添加新路由(只添加静态路由中没有的)
|
* 根据菜单动态添加新路由(只添加静态路由中没有的)
|
||||||
*/
|
*/
|
||||||
export function addDynamicRoutes(menus: MenuInfo[]) {
|
export function addDynamicRoutes(menus: any) { //MenuInfo[]
|
||||||
console.log('[动态路由] 开始处理菜单:', menus)
|
//console.log('[动态路由] 开始处理菜单:', menus)
|
||||||
|
const addRoutes = (menuList: any) => { //MenuInfo[]
|
||||||
const addRoutes = (menuList: MenuInfo[]) => {
|
|
||||||
for (const menu of menuList) {
|
for (const menu of menuList) {
|
||||||
// 只处理菜单类型(type=2),且有 path
|
// 只处理菜单类型(type=2),且有 path
|
||||||
if (menu.type === 2 && menu.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)
|
const pathExists = existingRoutes.some(r => r.path === '/' + menuPath || r.path === menuPath)
|
||||||
|
|
||||||
if (pathExists) {
|
if (pathExists) {
|
||||||
console.log(`[动态路由] 跳过(已存在): ${menuPath}`)
|
// console.log(`[动态路由] 跳过(已存在): ${menuPath}`)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (addedRouteNames.has(routeName)) {
|
if (addedRouteNames.has(routeName)) {
|
||||||
console.log(`[动态路由] 跳过(已添加): ${menuPath}`)
|
//console.log(`[动态路由] 跳过(已添加): ${menuPath}`)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,7 +283,7 @@ export function addDynamicRoutes(menus: MenuInfo[]) {
|
|||||||
const componentPath = `/src/views/${componentName}.vue`
|
const componentPath = `/src/views/${componentName}.vue`
|
||||||
const component = modules[componentPath]
|
const component = modules[componentPath]
|
||||||
|
|
||||||
console.log(`[动态路由] 处理: path=${menuPath}, component=${componentPath}, 组件存在=${!!component}`)
|
//console.log(`[动态路由] 处理: path=${menuPath}, component=${componentPath}, 组件存在=${!!component}`)
|
||||||
|
|
||||||
if (component) {
|
if (component) {
|
||||||
router.addRoute('Layout', {
|
router.addRoute('Layout', {
|
||||||
@ -298,9 +297,9 @@ export function addDynamicRoutes(menus: MenuInfo[]) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
addedRouteNames.add(routeName)
|
addedRouteNames.add(routeName)
|
||||||
console.log(`[动态路由] ✓ 添加成功: ${menuPath}`)
|
//console.log(`[动态路由] ✓ 添加成功: ${menuPath}`)
|
||||||
} else {
|
} else {
|
||||||
console.warn(`[动态路由] ✗ 组件不存在: ${componentPath}`)
|
//console.warn(`[动态路由] ✗ 组件不存在: ${componentPath}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -313,7 +312,7 @@ export function addDynamicRoutes(menus: MenuInfo[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addRoutes(menus)
|
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()
|
const userStore = useUserStore()
|
||||||
|
|
||||||
//document.title = `${to.meta.title || ''} - CSY Admin`
|
//document.title = `${to.meta.title || ''} - CSY Admin`
|
||||||
|
|
||||||
if (to.meta.requiresAuth === false) {
|
if (to.meta.requiresAuth === false) {
|
||||||
next()
|
next()
|
||||||
return
|
return
|
||||||
@ -343,7 +341,7 @@ router.beforeEach(async (to, _from, next) => {
|
|||||||
next({ name: 'Login', query: { redirect: to.fullPath } })
|
next({ name: 'Login', query: { redirect: to.fullPath } })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!userStore.user) {
|
if (!userStore.user) {
|
||||||
try {
|
try {
|
||||||
await userStore.getInfo()
|
await userStore.getInfo()
|
||||||
@ -357,7 +355,6 @@ router.beforeEach(async (to, _from, next) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@ -21,6 +21,7 @@ export default defineConfig({
|
|||||||
proxy: {
|
proxy: {
|
||||||
'/api': {
|
'/api': {
|
||||||
target:'http://192.168.6.107:8080', //'http://192.168.5.230:8888',
|
target:'http://192.168.6.107:8080', //'http://192.168.5.230:8888',
|
||||||
|
//target:'http://192.168.5.230:8888',
|
||||||
changeOrigin: true
|
changeOrigin: true
|
||||||
},
|
},
|
||||||
'/druid': {
|
'/druid': {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user