update 调整权限问题

This commit is contained in:
zk
2024-06-27 14:41:46 +08:00
parent 752405b9a4
commit 292a32a311
3 changed files with 40 additions and 28 deletions
+29 -16
View File
@@ -1,13 +1,12 @@
import { createRouter, createWebHistory, Router, RouteRecordRaw } from 'vue-router';
import { setCurrentPath } from '/@/enum/pageEnum.ts';
import { store } from '/@/store';
import { useUserStoreWithOut } from '/@/store/modules/user.ts';
import { getAuthCache } from '/@/utils/auth.ts';
const routes: Array<RouteRecordRaw> = [
{
path: '/',
name: 'default',
component: () => import('/@/views/index.vue'),
redirect: '/login',
},
{
path: '/login',
@@ -63,22 +62,36 @@ const router: Router = createRouter({
history: createWebHistory('/'),
routes: [...routes],
});
const xian = ['/login', '/home', '/secondScreen', '/transfer'];
const yinchuan = ['/screenLogin', '/secondScreen', '/transfer'];
router.beforeEach((to, from, next) => {
console.log('store', store);
let flag1 = store.getters.getFlag1();
let flag2 = store.getters.getFlag2();
const xian = ['/home', '/secondScreen', '/transfer'];
const yinchuan = ['/yinChuanHome', '/transfer'];
if (flag1 && !flag2 && !yinchuan.includes(to.path)) {
return next('/screenLogin');
}
if (flag2 && !flag1 && !xian.includes(to.path)) {
return next('/login');
}
router.beforeEach((to, from, next) => {
if (to.path !== '/login' && to.path !== '/screenLogin') {
setCurrentPath(to.path);
}
next();
let flag1 = getAuthCache('flag1')?.includes('yinchuan');
let flag2 = getAuthCache('flag2')?.includes('xian');
if (flag1 && flag2) {
next();
} else {
// 检查是否有权访问目标页面
if (yinchuan.includes(to.path)) {
// 如果在 yinchuan 列表中,并且有权限,则导航到目标页面
if (flag1) {
next();
} else {
next({ path: '/screenLogin' });
}
}
if (xian.includes(to.path)) {
// 如果在 xian 列表中,并且有权限,则导航到目标页面
if (flag2) {
next();
} else {
next({ path: '/login' });
}
}
next();
}
});
export default router;