优化路由逻辑,合并用户类型获取逻辑,简化代码结构,提升可读性和维护性。

This commit is contained in:
zyh
2025-08-28 21:26:57 +08:00
parent bec5961f2c
commit b9752b9a51

View File

@@ -1,6 +1,6 @@
import { createRouter, createWebHistory } from 'vue-router'
import { isLoggedIn } from '@/utils/auth'
import { canAccessRoute } from '@/utils/permission'
import { canAccessRoute, getCurrentUserType } from '@/utils/permission'
const AdminLayout = () => import('@/layouts/AdminLayout.vue')
const Login = () => import('@/views/Login.vue')
@@ -24,7 +24,6 @@ export const routes = [
path: '',
redirect: (to) => {
// 根据用户类型重定向到不同的默认页面
const { getCurrentUserType } = require('@/utils/permission')
const userType = getCurrentUserType()
if (userType?.toLowerCase() === 'agent') {
@@ -58,7 +57,6 @@ router.beforeEach((to, from, next) => {
// 检查路由权限
if (to.name && !canAccessRoute(to.name)) {
// 根据用户类型跳转到有权限的默认页面
const { getCurrentUserType } = require('@/utils/permission')
const userType = getCurrentUserType()
if (userType?.toLowerCase() === 'agent') {