update
This commit is contained in:
+3
-3
@@ -1,6 +1,6 @@
|
||||
import axios from 'axios';
|
||||
import { getAppEnvConfig } from '/@/utils/env.ts';
|
||||
import { useUserStore } from '/@/store/modules/user.ts';
|
||||
import { useUserStoreWithOut } from '/@/store/modules/user.ts';
|
||||
import { getAuthCache } from '/@/utils/auth.ts';
|
||||
import { TOKEN_KEY } from '/@/enum/cacheEnum.ts';
|
||||
import { useMessage } from '/@/hooks/web/useMessage.ts';
|
||||
@@ -10,8 +10,8 @@ import { getBaseLogin, toLoginByNowPath } from '/@/enum/pageEnum.ts';
|
||||
|
||||
const { createMessage, createErrorModal } = useMessage();
|
||||
const { VITE_GLOB_API_URL } = getAppEnvConfig();
|
||||
const userStore = useUserStore();
|
||||
const { token } = userStore;
|
||||
const userStore = useUserStoreWithOut();
|
||||
const token = userStore.getToken;
|
||||
const service = axios.create({
|
||||
baseURL: VITE_GLOB_API_URL,
|
||||
timeout: 50000,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
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';
|
||||
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
@@ -61,7 +63,19 @@ 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();
|
||||
|
||||
if (flag1 && !flag2 && !yinchuan.includes(to.path)) {
|
||||
return next('/screenLogin');
|
||||
}
|
||||
if (flag2 && !flag1 && !xian.includes(to.path)) {
|
||||
return next('/login');
|
||||
}
|
||||
if (to.path !== '/login' && to.path !== '/screenLogin') {
|
||||
setCurrentPath(to.path);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { getBaseLogin, PageEnum } from '/@/enum/pageEnum.ts';
|
||||
import { getAuthCache, setAuthCache } from '/@/utils/auth.ts';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { LoginInfo, LoginParams, UserInfo } from '/@/store/modules/storeType.ts';
|
||||
import { store } from '/@/store';
|
||||
|
||||
const router = useRouter();
|
||||
export const useUserStore = defineStore({
|
||||
@@ -15,6 +16,8 @@ export const useUserStore = defineStore({
|
||||
//登录返回信息
|
||||
loginInfo: null,
|
||||
themeType: '', // dark 1, light 2
|
||||
flag1: null, //银川权限标识
|
||||
flag2: null, //西安权限标识
|
||||
}),
|
||||
getters: {
|
||||
getUserInfo(): UserInfo {
|
||||
@@ -29,6 +32,12 @@ export const useUserStore = defineStore({
|
||||
getThemeType(): string {
|
||||
return this.themeType || getAuthCache('themeType');
|
||||
},
|
||||
getFlag1(): string {
|
||||
return this.flag1 || getAuthCache('flag1');
|
||||
},
|
||||
getFlag2(): string {
|
||||
return this.flag2 || getAuthCache('flag2');
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
setToken(info: string | undefined) {
|
||||
@@ -46,6 +55,14 @@ export const useUserStore = defineStore({
|
||||
this.themeType = info ? info : '';
|
||||
setAuthCache('themeType', info);
|
||||
},
|
||||
setFlag1(info: string | undefined) {
|
||||
this.flag1 = info ? info : '';
|
||||
setAuthCache('flag1', info);
|
||||
},
|
||||
setFlag2(info: string | undefined) {
|
||||
this.flag2 = info ? info : '';
|
||||
setAuthCache('flag2', info);
|
||||
},
|
||||
/**
|
||||
* 登录事件
|
||||
*/
|
||||
@@ -57,7 +74,7 @@ export const useUserStore = defineStore({
|
||||
// save token
|
||||
this.setToken(token, false);
|
||||
this.setUserInfo(userInfo);
|
||||
return { userInfo };
|
||||
return { userInfo, token };
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
@@ -108,3 +125,7 @@ export const useUserStore = defineStore({
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export function useUserStoreWithOut() {
|
||||
return useUserStore(store);
|
||||
}
|
||||
|
||||
+33
-6
@@ -101,7 +101,7 @@
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { getAuthCache } from '/@/utils/auth.ts';
|
||||
import { TOKEN_KEY } from '/@/enum/cacheEnum.ts';
|
||||
import { getCurrentPath, PageEnum, setBaseLogin, toHomeByLogoutPath, toLoginByNowPath } from '/@/enum/pageEnum.ts';
|
||||
import { getCurrentPath, PageEnum, setBaseLogin, toHomeByLogoutPath } from '/@/enum/pageEnum.ts';
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
const router = useRouter();
|
||||
@@ -191,12 +191,39 @@
|
||||
if (userInfo) {
|
||||
try {
|
||||
let { code, result, message: msg } = await getAuth();
|
||||
let authCode = ['emergency:screen:show:yinchuan', 'emergency:screen:show:xian'];
|
||||
let goPath = '';
|
||||
if (code == 200) {
|
||||
let flag = result?.codeList?.find((item) => authCode.includes(item));
|
||||
if (!flag) {
|
||||
let flag1 = result?.codeList?.find((item) => ['emergency:screen:show:yinchuan'].includes(item));
|
||||
let flag2 = result?.codeList?.find((item) => ['emergency:screen:show:xian'].includes(item));
|
||||
userStore.setFlag1(flag1);
|
||||
userStore.setFlag2(flag2);
|
||||
|
||||
if (!flag1 && !flag2) {
|
||||
userStore.setToken('', false);
|
||||
userStore.setUserInfo({});
|
||||
return message.warn('您没有权限访问大屏,请联系管理员!');
|
||||
}
|
||||
//1如果有权限
|
||||
//1.2若果是有两种权限
|
||||
if (flag1 && flag2) {
|
||||
// 1.2.1 如果是登录地址是西安
|
||||
// 1.2.2 如果是登录地址是银川
|
||||
if (route.path == PageEnum.BASE_LOGIN_YINCHUAN) {
|
||||
goPath = PageEnum.YINCHUAN_HOME;
|
||||
} else {
|
||||
goPath = PageEnum.BASE_HOME;
|
||||
}
|
||||
} else {
|
||||
if (flag1 && route.path == PageEnum.BASE_LOGIN_YINCHUAN) {
|
||||
goPath = PageEnum.YINCHUAN_HOME;
|
||||
} else if (flag2 && route.path == PageEnum.BASE_HOME) {
|
||||
goPath = PageEnum.BASE_HOME;
|
||||
} else {
|
||||
userStore.setToken('', false);
|
||||
userStore.setUserInfo({});
|
||||
return message.warn('没有权限请联系管理员!');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return message.warn(msg);
|
||||
}
|
||||
@@ -205,9 +232,9 @@
|
||||
description: `${t('login.loginSuccessDesc')}: ${userInfo.realname}`,
|
||||
duration: 3,
|
||||
});
|
||||
let path = toHomeByNowPath();
|
||||
|
||||
setBaseLogin(route.path);
|
||||
router.replace({ path: path });
|
||||
router.replace(goPath);
|
||||
} catch (e) {
|
||||
message.warn(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user