This commit is contained in:
zxr
2026-05-02 17:20:20 +08:00
248 changed files with 11113 additions and 14648 deletions

View File

@@ -17,7 +17,7 @@ export default function setupPermissionGuard(router: Router) {
const userStore = useUserStore()
const Permission = usePermission()
const permissionsAllow = Permission.accessRouter(to)
if (appStore.menuFromServer) {
// 针对来自服务端的菜单配置进行处理
// Handle routing configuration from the server

View File

@@ -46,22 +46,22 @@ export function loadViewComponent(componentPath: string) {
}
// 构建完整的文件路径
const filePath = `/src/views/${normalizedPath}.vue`
// 从预加载的模块中查找
const modulePath = Object.keys(viewModules).find((path) => path.endsWith(filePath) || path === filePath)
if (modulePath && viewModules[modulePath]) {
return viewModules[modulePath]
}
// 如果找不到,尝试不带 /index 的路径
const directFilePath = `/src/views/${componentPath}.vue`
const directModulePath = Object.keys(viewModules).find((path) => path.endsWith(directFilePath) || path === directFilePath)
if (directModulePath && viewModules[directModulePath]) {
return viewModules[directModulePath]
}
// 如果都找不到,返回一个默认组件或抛出错误
console.warn(`View component not found: ${filePath} or ${directFilePath}`)
return () => import('@/views/redirect/index.vue')
@@ -78,7 +78,7 @@ export function transformMenuToRoutes(menuItems: ServerMenuItem[]): AppRouteReco
for (const item of menuItems) {
// 根据 is_full 决定如何设置 component
let routeComponent: AppRouteRecordRaw['component']
if (item.is_full) {
// 独立页面:直接加载视图组件,不使用布局
if (item.component) {
@@ -158,7 +158,7 @@ function toRelativePath(path: string): string {
*/
function extractRelativePath(childPath: string, parentPath: string): string {
if (!childPath) return ''
// 如果子路径以父路径开头,提取相对部分
if (parentPath && childPath.startsWith(parentPath)) {
let relativePath = childPath.slice(parentPath.length)
@@ -168,7 +168,7 @@ function extractRelativePath(childPath: string, parentPath: string): string {
}
return relativePath
}
// 否则转换为相对路径
return toRelativePath(childPath)
}
@@ -193,7 +193,7 @@ function isLicenseCenterMenuPath(fullPath: string): boolean {
}
function transformChildRoutes(
children: ServerMenuItem[],
children: ServerMenuItem[],
parentComponent?: string,
parentPath?: string,
parentIsFull?: boolean
@@ -203,15 +203,12 @@ function transformChildRoutes(
// 已配置 component 的菜单绝不覆盖;仅对许可页做路径/code 兜底,避免 includes 误匹配
let componentPath = child.component || parentComponent
if (
!child.component &&
(isLicenseCenterMenuPath(childFullPath) || child.code === 'LicenseCenter')
) {
if (!child.component && (isLicenseCenterMenuPath(childFullPath) || child.code === 'LicenseCenter')) {
componentPath = LICENSE_CENTER_VIEW
}
const relativePath = extractRelativePath(childFullPath, parentPath || '')
const route: AppRouteRecordRaw = {
path: relativePath,
name: child.title || child.name || `menu_${child.id}`,
@@ -222,15 +219,13 @@ function transformChildRoutes(
roles: child.roles,
hideInMenu: child.hideInMenu || child.hide_menu,
},
component: componentPath
? loadViewComponent(componentPath)
: () => import('@/views/redirect/index.vue'),
component: componentPath ? loadViewComponent(componentPath) : () => import('@/views/redirect/index.vue'),
}
// 递归处理子菜单的子菜单
if (child.children && child.children.length > 0) {
route.children = transformChildRoutes(
child.children,
child.children,
child.component || parentComponent,
childFullPath, // 传递当前子菜单的完整路径作为下一层的父路径
child.is_full || parentIsFull // 传递 is_full 标志
@@ -242,37 +237,38 @@ function transformChildRoutes(
}
// 本地菜单数据 - 接口未准备好时使用
export const localMenuData: AppRouteRecordRaw[] = [{
path: '/dashboard',
name: 'dashboard',
component: DEFAULT_LAYOUT,
meta: {
locale: '仪表盘',
requiresAuth: true,
icon: 'icon-dashboard',
order: 0,
export const localMenuData: AppRouteRecordRaw[] = [
{
path: '/dashboard',
name: 'dashboard',
component: DEFAULT_LAYOUT,
meta: {
locale: '仪表盘',
requiresAuth: true,
icon: 'icon-dashboard',
order: 0,
},
children: [
{
path: 'workplace',
name: 'Workplace',
component: () => import('@/views/dashboard/workplace/index.vue'),
meta: {
locale: 'menu.dashboard.workplace',
requiresAuth: true,
},
},
{
path: 'monitor',
name: 'Monitor',
component: () => import('@/views/dashboard/monitor/index.vue'),
meta: {
locale: 'menu.dashboard.monitor',
requiresAuth: true,
},
},
],
},
children: [
{
path: 'workplace',
name: 'Workplace',
component: () => import('@/views/dashboard/workplace/index.vue'),
meta: {
locale: 'menu.dashboard.workplace',
requiresAuth: true,
},
},
{
path: 'monitor',
name: 'Monitor',
component: () => import('@/views/dashboard/monitor/index.vue'),
meta: {
locale: 'menu.dashboard.monitor',
requiresAuth: true,
},
},
],
},
{
path: '/overview',
name: 'Overview',