update 调整权限问题
This commit is contained in:
+7
-7
@@ -1,27 +1,27 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { getAppEnvConfig } from '/@/utils/env.ts';
|
import { getAppEnvConfig } from '/@/utils/env.ts';
|
||||||
import { useUserStoreWithOut } from '/@/store/modules/user.ts';
|
|
||||||
import { getAuthCache } from '/@/utils/auth.ts';
|
import { getAuthCache } from '/@/utils/auth.ts';
|
||||||
import { TOKEN_KEY } from '/@/enum/cacheEnum.ts';
|
import { TOKEN_KEY } from '/@/enum/cacheEnum.ts';
|
||||||
import { useMessage } from '/@/hooks/web/useMessage.ts';
|
import { useMessage } from '/@/hooks/web/useMessage.ts';
|
||||||
import { checkStatus } from '/@/api/checkStatus.ts';
|
|
||||||
import router from '/@/router';
|
import router from '/@/router';
|
||||||
|
import { useUserStore } from '/@/store/modules/user.ts';
|
||||||
import { getBaseLogin, toLoginByNowPath } from '/@/enum/pageEnum.ts';
|
import { getBaseLogin, toLoginByNowPath } from '/@/enum/pageEnum.ts';
|
||||||
|
|
||||||
const { createMessage, createErrorModal } = useMessage();
|
const { createMessage } = useMessage();
|
||||||
const { VITE_GLOB_API_URL } = getAppEnvConfig();
|
const { VITE_GLOB_API_URL } = getAppEnvConfig();
|
||||||
const userStore = useUserStoreWithOut();
|
|
||||||
const token = userStore.getToken;
|
|
||||||
const service = axios.create({
|
const service = axios.create({
|
||||||
baseURL: VITE_GLOB_API_URL,
|
baseURL: VITE_GLOB_API_URL,
|
||||||
timeout: 50000,
|
timeout: 50000,
|
||||||
headers: {
|
headers: {
|
||||||
// 设置后端需要的传参类型
|
// 设置后端需要的传参类型
|
||||||
'Content-Type': 'application/json;charset=UTF-8',
|
'Content-Type': 'application/json;charset=UTF-8',
|
||||||
'X-Access-Token': token || getAuthCache(TOKEN_KEY),
|
'X-Access-Token': getAuthCache(TOKEN_KEY),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
service.interceptors.request.use((config, options) => {
|
service.interceptors.request.use((config, options) => {
|
||||||
|
const userStore = useUserStore();
|
||||||
|
const token = userStore.getToken;
|
||||||
config.headers['X-Access-Token'] = token || getAuthCache(TOKEN_KEY);
|
config.headers['X-Access-Token'] = token || getAuthCache(TOKEN_KEY);
|
||||||
return config;
|
return config;
|
||||||
});
|
});
|
||||||
@@ -37,7 +37,7 @@ service.interceptors.response.use(
|
|||||||
if (!path) {
|
if (!path) {
|
||||||
path = toLoginByNowPath(router.currentRoute.value.path);
|
path = toLoginByNowPath(router.currentRoute.value.path);
|
||||||
}
|
}
|
||||||
createMessage.warn(error.response.data.message);
|
// createMessage.warn(error.response.data.message);
|
||||||
router.replace({
|
router.replace({
|
||||||
path: path,
|
path: path,
|
||||||
});
|
});
|
||||||
|
|||||||
+29
-16
@@ -1,13 +1,12 @@
|
|||||||
import { createRouter, createWebHistory, Router, RouteRecordRaw } from 'vue-router';
|
import { createRouter, createWebHistory, Router, RouteRecordRaw } from 'vue-router';
|
||||||
import { setCurrentPath } from '/@/enum/pageEnum.ts';
|
import { setCurrentPath } from '/@/enum/pageEnum.ts';
|
||||||
import { store } from '/@/store';
|
import { getAuthCache } from '/@/utils/auth.ts';
|
||||||
import { useUserStoreWithOut } from '/@/store/modules/user.ts';
|
|
||||||
|
|
||||||
const routes: Array<RouteRecordRaw> = [
|
const routes: Array<RouteRecordRaw> = [
|
||||||
{
|
{
|
||||||
path: '/',
|
path: '/',
|
||||||
name: 'default',
|
name: 'default',
|
||||||
component: () => import('/@/views/index.vue'),
|
redirect: '/login',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/login',
|
path: '/login',
|
||||||
@@ -63,22 +62,36 @@ const router: Router = createRouter({
|
|||||||
history: createWebHistory('/'),
|
history: createWebHistory('/'),
|
||||||
routes: [...routes],
|
routes: [...routes],
|
||||||
});
|
});
|
||||||
const xian = ['/login', '/home', '/secondScreen', '/transfer'];
|
const xian = ['/home', '/secondScreen', '/transfer'];
|
||||||
const yinchuan = ['/screenLogin', '/secondScreen', '/transfer'];
|
const yinchuan = ['/yinChuanHome', '/transfer'];
|
||||||
router.beforeEach((to, from, next) => {
|
|
||||||
console.log('store', store);
|
|
||||||
let flag1 = store.getters.getFlag1();
|
|
||||||
let flag2 = store.getters.getFlag2();
|
|
||||||
|
|
||||||
if (flag1 && !flag2 && !yinchuan.includes(to.path)) {
|
router.beforeEach((to, from, next) => {
|
||||||
return next('/screenLogin');
|
|
||||||
}
|
|
||||||
if (flag2 && !flag1 && !xian.includes(to.path)) {
|
|
||||||
return next('/login');
|
|
||||||
}
|
|
||||||
if (to.path !== '/login' && to.path !== '/screenLogin') {
|
if (to.path !== '/login' && to.path !== '/screenLogin') {
|
||||||
setCurrentPath(to.path);
|
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;
|
export default router;
|
||||||
|
|||||||
@@ -195,9 +195,9 @@
|
|||||||
if (code == 200) {
|
if (code == 200) {
|
||||||
let flag1 = result?.codeList?.find((item) => ['emergency:screen:show:yinchuan'].includes(item));
|
let flag1 = result?.codeList?.find((item) => ['emergency:screen:show:yinchuan'].includes(item));
|
||||||
let flag2 = result?.codeList?.find((item) => ['emergency:screen:show:xian'].includes(item));
|
let flag2 = result?.codeList?.find((item) => ['emergency:screen:show:xian'].includes(item));
|
||||||
userStore.setFlag1(flag1);
|
userStore.setFlag1(flag1 || '');
|
||||||
userStore.setFlag2(flag2);
|
userStore.setFlag2(flag2 || '');
|
||||||
|
debugger;
|
||||||
if (!flag1 && !flag2) {
|
if (!flag1 && !flag2) {
|
||||||
userStore.setToken('', false);
|
userStore.setToken('', false);
|
||||||
userStore.setUserInfo({});
|
userStore.setUserInfo({});
|
||||||
@@ -216,7 +216,7 @@
|
|||||||
} else {
|
} else {
|
||||||
if (flag1 && route.path == PageEnum.BASE_LOGIN_YINCHUAN) {
|
if (flag1 && route.path == PageEnum.BASE_LOGIN_YINCHUAN) {
|
||||||
goPath = PageEnum.YINCHUAN_HOME;
|
goPath = PageEnum.YINCHUAN_HOME;
|
||||||
} else if (flag2 && route.path == PageEnum.BASE_HOME) {
|
} else if (flag2 && route.path == PageEnum.BASE_LOGIN) {
|
||||||
goPath = PageEnum.BASE_HOME;
|
goPath = PageEnum.BASE_HOME;
|
||||||
} else {
|
} else {
|
||||||
userStore.setToken('', false);
|
userStore.setToken('', false);
|
||||||
@@ -232,7 +232,6 @@
|
|||||||
description: `${t('login.loginSuccessDesc')}: ${userInfo.realname}`,
|
description: `${t('login.loginSuccessDesc')}: ${userInfo.realname}`,
|
||||||
duration: 3,
|
duration: 3,
|
||||||
});
|
});
|
||||||
|
|
||||||
setBaseLogin(route.path);
|
setBaseLogin(route.path);
|
||||||
router.replace(goPath);
|
router.replace(goPath);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user