优化路由逻辑,合并用户类型获取逻辑,简化代码结构,提升可读性和维护性。
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { createRouter, createWebHistory } from 'vue-router'
|
import { createRouter, createWebHistory } from 'vue-router'
|
||||||
import { isLoggedIn } from '@/utils/auth'
|
import { isLoggedIn } from '@/utils/auth'
|
||||||
import { canAccessRoute } from '@/utils/permission'
|
import { canAccessRoute, getCurrentUserType } from '@/utils/permission'
|
||||||
|
|
||||||
const AdminLayout = () => import('@/layouts/AdminLayout.vue')
|
const AdminLayout = () => import('@/layouts/AdminLayout.vue')
|
||||||
const Login = () => import('@/views/Login.vue')
|
const Login = () => import('@/views/Login.vue')
|
||||||
@@ -24,7 +24,6 @@ export const routes = [
|
|||||||
path: '',
|
path: '',
|
||||||
redirect: (to) => {
|
redirect: (to) => {
|
||||||
// 根据用户类型重定向到不同的默认页面
|
// 根据用户类型重定向到不同的默认页面
|
||||||
const { getCurrentUserType } = require('@/utils/permission')
|
|
||||||
const userType = getCurrentUserType()
|
const userType = getCurrentUserType()
|
||||||
|
|
||||||
if (userType?.toLowerCase() === 'agent') {
|
if (userType?.toLowerCase() === 'agent') {
|
||||||
@@ -58,7 +57,6 @@ router.beforeEach((to, from, next) => {
|
|||||||
// 检查路由权限
|
// 检查路由权限
|
||||||
if (to.name && !canAccessRoute(to.name)) {
|
if (to.name && !canAccessRoute(to.name)) {
|
||||||
// 根据用户类型跳转到有权限的默认页面
|
// 根据用户类型跳转到有权限的默认页面
|
||||||
const { getCurrentUserType } = require('@/utils/permission')
|
|
||||||
const userType = getCurrentUserType()
|
const userType = getCurrentUserType()
|
||||||
|
|
||||||
if (userType?.toLowerCase() === 'agent') {
|
if (userType?.toLowerCase() === 'agent') {
|
||||||
|
|||||||
Reference in New Issue
Block a user