This commit is contained in:
2026-06-22 14:44:15 +08:00
parent 0af7df1766
commit 34de6d5679
6 changed files with 70 additions and 17 deletions

View File

@ -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',

View File

@ -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. 白名单页面(实名认证、活体认证、登录/注册相关页面)

View File

@ -14,10 +14,19 @@ const pathToIconMap: Record<string, string> = {
"/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;
};

View File

@ -38,7 +38,7 @@
<div class="user-details">
<span class="user-name">{{ userStore.userInfo?.username || '-' }}</span>
<el-tag size="small" :type="tagType">
{{ roleName }}
{{ roleNameComputed }}
</el-tag>
</div>
</div>
@ -52,7 +52,7 @@
</div>
<div class="info-row">
<span class="info-label">账户类型</span>
<span class="info-value">{{ roleName }}</span>
<span class="info-value">{{ roleNameComputed }}</span>
</div>
</div>
</div>
@ -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')}`

View File

@ -81,12 +81,10 @@
</div>
</div>
</div>
<!-- 承包商首页 -->
<!-- 承包商/特殊做市商/普通做市商 首页 -->
<MarketMakerDashboard
v-else-if="userRoleId === 2 || userRoleId === 3 ||userRoleId === 4"
v-else-if="userRoleId === 2 || userRoleId === 3 || userRoleId === 4"
:role-id="userRoleId"
role-name="承包商"
page-title="承包商首页"
/>
<Agent v-else />
</template>

View File

@ -45,7 +45,7 @@
</div>
<!-- IOS -->
<div class="download-item">
<div class="download-item" v-if="false">
<div class="item-left">
<div class="icon-box ios">
<svg viewBox="0 0 1024 1024" width="32" height="32">