bug
This commit is contained in:
parent
0af7df1766
commit
34de6d5679
|
|
@ -27,8 +27,27 @@ export const handleRouter = (list: any[]):any[] => {
|
||||||
|
|
||||||
export const setRouter = () => {
|
export const setRouter = () => {
|
||||||
|
|
||||||
const menuList = getStorage('menusInfo')
|
const menuList = (getStorage('menusInfo') as any[]) || []
|
||||||
const token = getStorage('token')
|
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) {
|
if (token && menuList.length > 0) {
|
||||||
const routeList = handleRouter(menuList).filter(
|
const routeList = handleRouter(menuList).filter(
|
||||||
(item) => item.path && item.path !== '/dashboard',
|
(item) => item.path && item.path !== '/dashboard',
|
||||||
|
|
|
||||||
|
|
@ -117,16 +117,33 @@ router.beforeEach(async (to, _from) => {
|
||||||
|
|
||||||
// 2. ✅ 动态路由恢复(只执行一次)
|
// 2. ✅ 动态路由恢复(只执行一次)
|
||||||
if (isLoggedIn && !dynamicRoutesReady) {
|
if (isLoggedIn && !dynamicRoutesReady) {
|
||||||
const menuList = getStorage('menusInfo')
|
const menuList = (getStorage('menusInfo') as any[]) || []
|
||||||
if (menuList?.length > 0) {
|
|
||||||
|
// 🌟 核心:无论任何角色,始终确保首页路由存在
|
||||||
|
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(
|
const routeList = handleRouter(menuList).filter(
|
||||||
(item) => item.path && item.path !== '/dashboard',
|
(item) => item.path && item.path !== '/dashboard',
|
||||||
)
|
)
|
||||||
routeList.forEach((route) => router.addRoute('Layout', route))
|
routeList.forEach((route) => router.addRoute('Layout', route))
|
||||||
dynamicRoutesReady = true
|
|
||||||
// 返回目标路由以触发重新匹配
|
|
||||||
return to.redirectedFrom?.fullPath || true
|
|
||||||
}
|
}
|
||||||
|
dynamicRoutesReady = true
|
||||||
|
// 返回目标路由以触发重新匹配
|
||||||
|
return to.redirectedFrom?.fullPath || true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 白名单页面(实名认证、活体认证、登录/注册相关页面)
|
// 3. 白名单页面(实名认证、活体认证、登录/注册相关页面)
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,19 @@ const pathToIconMap: Record<string, string> = {
|
||||||
"/menu-11": 'WarningFilled'
|
"/menu-11": 'WarningFilled'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 首页菜单项常量(所有角色共有)
|
||||||
|
export const HOME_MENU_ITEM: ElMenuItem = {
|
||||||
|
id: -1,
|
||||||
|
label: '首页',
|
||||||
|
path: '/dashboard',
|
||||||
|
icon: 'HomeFilled',
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式化后端菜单数据为 el-menu 标准格式
|
* 格式化后端菜单数据为 el-menu 标准格式
|
||||||
* - 路由路径:优先用后端 path 字段,其次用 api 字段
|
* - 路由路径:优先用后端 path 字段,其次用 api 字段
|
||||||
* - 图标映射:仅一级菜单基于 path 字段映射,二级菜单无图标
|
* - 图标映射:仅一级菜单基于 path 字段映射,二级菜单无图标
|
||||||
|
* - 无论任何角色,"首页"始终作为第一个菜单项
|
||||||
* @param rawMenuList 后端返回的 menus_info 数组
|
* @param rawMenuList 后端返回的 menus_info 数组
|
||||||
* @returns 适配 el-menu 的菜单数据
|
* @returns 适配 el-menu 的菜单数据
|
||||||
*/
|
*/
|
||||||
|
|
@ -57,6 +66,14 @@ export const formatMenuToElMenu = (rawMenuList: any[]): ElMenuItem[] => {
|
||||||
return 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">
|
<div class="user-details">
|
||||||
<span class="user-name">{{ userStore.userInfo?.username || '-' }}</span>
|
<span class="user-name">{{ userStore.userInfo?.username || '-' }}</span>
|
||||||
<el-tag size="small" :type="tagType">
|
<el-tag size="small" :type="tagType">
|
||||||
{{ roleName }}
|
{{ roleNameComputed }}
|
||||||
</el-tag>
|
</el-tag>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -52,7 +52,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="info-row">
|
<div class="info-row">
|
||||||
<span class="info-label">账户类型</span>
|
<span class="info-label">账户类型</span>
|
||||||
<span class="info-value">{{ roleName }}</span>
|
<span class="info-value">{{ roleNameComputed }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -106,11 +106,10 @@ import {
|
||||||
import AnimatedNumber from '@/views/agent/user/AnimatedNumber.vue'
|
import AnimatedNumber from '@/views/agent/user/AnimatedNumber.vue'
|
||||||
import { getWalletCapital } from '@/api/modules/capital/withdraw'
|
import { getWalletCapital } from '@/api/modules/capital/withdraw'
|
||||||
import { useUserStore } from '@/stores/modules/user'
|
import { useUserStore } from '@/stores/modules/user'
|
||||||
|
import { ROLE_MAP, type RoleType } from '@/api/types/agent.d'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
roleId: number
|
roleId: number
|
||||||
roleName: string
|
|
||||||
pageTitle: string
|
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
|
|
@ -119,6 +118,9 @@ defineOptions({
|
||||||
|
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
|
|
||||||
|
// 角色名称从 ROLE_MAP 获取
|
||||||
|
const roleNameComputed = computed(() => ROLE_MAP[props.roleId as RoleType] || '-')
|
||||||
|
|
||||||
const formattedDate = computed(() => {
|
const formattedDate = computed(() => {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
return `${now.getFullYear()}/${String(now.getMonth() + 1).padStart(2, '0')}/${String(now.getDate()).padStart(2, '0')}`
|
return `${now.getFullYear()}/${String(now.getMonth() + 1).padStart(2, '0')}/${String(now.getDate()).padStart(2, '0')}`
|
||||||
|
|
|
||||||
|
|
@ -81,12 +81,10 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- 承包商首页 -->
|
<!-- 承包商/特殊做市商/普通做市商 首页 -->
|
||||||
<MarketMakerDashboard
|
<MarketMakerDashboard
|
||||||
v-else-if="userRoleId === 2 || userRoleId === 3 ||userRoleId === 4"
|
v-else-if="userRoleId === 2 || userRoleId === 3 || userRoleId === 4"
|
||||||
:role-id="userRoleId"
|
:role-id="userRoleId"
|
||||||
role-name="承包商"
|
|
||||||
page-title="承包商首页"
|
|
||||||
/>
|
/>
|
||||||
<Agent v-else />
|
<Agent v-else />
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- IOS -->
|
<!-- IOS -->
|
||||||
<div class="download-item">
|
<div class="download-item" v-if="false">
|
||||||
<div class="item-left">
|
<div class="item-left">
|
||||||
<div class="icon-box ios">
|
<div class="icon-box ios">
|
||||||
<svg viewBox="0 0 1024 1024" width="32" height="32">
|
<svg viewBox="0 0 1024 1024" width="32" height="32">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue