From 34de6d56794a875b8516b87cb464cf65af41b911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8?= Date: Mon, 22 Jun 2026 14:44:15 +0800 Subject: [PATCH] bug --- src/router/handleRouter.ts | 21 ++++++++++++++- src/router/index.ts | 27 +++++++++++++++---- src/utils/menuFormat/index.ts | 21 +++++++++++++-- .../components/marketMaker/index.vue | 10 ++++--- src/views/dashboard/index.vue | 6 ++--- src/views/trade/exe/index.vue | 2 +- 6 files changed, 70 insertions(+), 17 deletions(-) diff --git a/src/router/handleRouter.ts b/src/router/handleRouter.ts index 359d202..75372a8 100644 --- a/src/router/handleRouter.ts +++ b/src/router/handleRouter.ts @@ -27,8 +27,27 @@ export const handleRouter = (list: any[]):any[] => { export const setRouter = () => { - const menuList = getStorage('menusInfo') + const menuList = (getStorage('menusInfo') as any[]) || [] const token = getStorage('token') + + // 检查是否已存在 dashboard 路由 + const hasDashboardRoute = router.getRoutes().some( + (route) => route.path === '/dashboard', + ) + + // 🌟 核心:无论什么角色,始终确保首页路由存在 + if (token && !hasDashboardRoute) { + router.addRoute('Layout', { + path: '/dashboard', + name: 'Dashboard', + component: () => import('@/views/dashboard/index.vue'), + meta: { + title: '首页', + keepAlive: false, + }, + }) + } + if (token && menuList.length > 0) { const routeList = handleRouter(menuList).filter( (item) => item.path && item.path !== '/dashboard', diff --git a/src/router/index.ts b/src/router/index.ts index 9c761d2..0057b4c 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -117,16 +117,33 @@ router.beforeEach(async (to, _from) => { // 2. ✅ 动态路由恢复(只执行一次) if (isLoggedIn && !dynamicRoutesReady) { - const menuList = getStorage('menusInfo') - if (menuList?.length > 0) { + const menuList = (getStorage('menusInfo') as any[]) || [] + + // 🌟 核心:无论任何角色,始终确保首页路由存在 + const hasDashboardRoute = router.getRoutes().some( + (route) => route.path === '/dashboard', + ) + if (!hasDashboardRoute) { + router.addRoute('Layout', { + path: '/dashboard', + name: 'Dashboard', + component: () => import('@/views/dashboard/index.vue'), + meta: { + title: '首页', + keepAlive: false, + }, + }) + } + + if (menuList.length > 0) { const routeList = handleRouter(menuList).filter( (item) => item.path && item.path !== '/dashboard', ) routeList.forEach((route) => router.addRoute('Layout', route)) - dynamicRoutesReady = true - // 返回目标路由以触发重新匹配 - return to.redirectedFrom?.fullPath || true } + dynamicRoutesReady = true + // 返回目标路由以触发重新匹配 + return to.redirectedFrom?.fullPath || true } // 3. 白名单页面(实名认证、活体认证、登录/注册相关页面) diff --git a/src/utils/menuFormat/index.ts b/src/utils/menuFormat/index.ts index 8fb3659..6862357 100644 --- a/src/utils/menuFormat/index.ts +++ b/src/utils/menuFormat/index.ts @@ -14,10 +14,19 @@ const pathToIconMap: Record = { "/menu-11": 'WarningFilled' }; +// 首页菜单项常量(所有角色共有) +export const HOME_MENU_ITEM: ElMenuItem = { + id: -1, + label: '首页', + path: '/dashboard', + icon: 'HomeFilled', +}; + /** * 格式化后端菜单数据为 el-menu 标准格式 * - 路由路径:优先用后端 path 字段,其次用 api 字段 * - 图标映射:仅一级菜单基于 path 字段映射,二级菜单无图标 + * - 无论任何角色,"首页"始终作为第一个菜单项 * @param rawMenuList 后端返回的 menus_info 数组 * @returns 适配 el-menu 的菜单数据 */ @@ -57,6 +66,14 @@ export const formatMenuToElMenu = (rawMenuList: any[]): ElMenuItem[] => { return elMenuItem; }; - // 遍历一级菜单,标记 isFirstLevel = true - return rawMenuList.map(menu => formatSubMenu(menu, true)); + // 格式化后的菜单列表 + const formatted = rawMenuList.map(menu => formatSubMenu(menu, true)); + + // 🌟 核心:确保"首页"始终存在于菜单列表中(不区分角色) + const hasDashboard = formatted.some(menu => menu.path === '/dashboard'); + if (!hasDashboard) { + formatted.unshift({ ...HOME_MENU_ITEM }); + } + + return formatted; }; diff --git a/src/views/dashboard/components/marketMaker/index.vue b/src/views/dashboard/components/marketMaker/index.vue index b469069..1e220cf 100644 --- a/src/views/dashboard/components/marketMaker/index.vue +++ b/src/views/dashboard/components/marketMaker/index.vue @@ -38,7 +38,7 @@
{{ userStore.userInfo?.username || '-' }} - {{ roleName }} + {{ roleNameComputed }}
@@ -52,7 +52,7 @@
账户类型 - {{ roleName }} + {{ roleNameComputed }}
@@ -106,11 +106,10 @@ import { import AnimatedNumber from '@/views/agent/user/AnimatedNumber.vue' import { getWalletCapital } from '@/api/modules/capital/withdraw' import { useUserStore } from '@/stores/modules/user' +import { ROLE_MAP, type RoleType } from '@/api/types/agent.d' const props = defineProps<{ roleId: number - roleName: string - pageTitle: string }>() defineOptions({ @@ -119,6 +118,9 @@ defineOptions({ const userStore = useUserStore() +// 角色名称从 ROLE_MAP 获取 +const roleNameComputed = computed(() => ROLE_MAP[props.roleId as RoleType] || '-') + const formattedDate = computed(() => { const now = new Date() return `${now.getFullYear()}/${String(now.getMonth() + 1).padStart(2, '0')}/${String(now.getDate()).padStart(2, '0')}` diff --git a/src/views/dashboard/index.vue b/src/views/dashboard/index.vue index 5745989..c82a656 100644 --- a/src/views/dashboard/index.vue +++ b/src/views/dashboard/index.vue @@ -81,12 +81,10 @@ - + diff --git a/src/views/trade/exe/index.vue b/src/views/trade/exe/index.vue index 537fe9e..310cb14 100644 --- a/src/views/trade/exe/index.vue +++ b/src/views/trade/exe/index.vue @@ -45,7 +45,7 @@ -
+