bug
This commit is contained in:
parent
0af7df1766
commit
34de6d5679
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -117,17 +117,34 @@ 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
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 白名单页面(实名认证、活体认证、登录/注册相关页面)
|
||||
// 这些页面即使未实名认证也可以访问
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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')}`
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
|
|
|
|||
Loading…
Reference in New Issue