feat: 获取公钥跟islogin接口拆分
This commit is contained in:
parent
f3f5a826f3
commit
6db5bbe95d
|
@ -23,6 +23,7 @@
|
|||
import { getLocalStorage, setLocalStorage } from '@/utils/local-storage';
|
||||
import { watchStyle, watchTheme, setFavicon } from '@/utils/theme';
|
||||
import { WorkbenchRouteEnum } from './enums/routeEnum';
|
||||
import { getPublicKeyRequest } from './api/modules/user';
|
||||
// import MsEmpty from '@/components/pure/ms-empty/index.vue';
|
||||
|
||||
const appStore = useAppStore();
|
||||
|
@ -76,10 +77,17 @@
|
|||
router.push(WorkbenchRouteEnum.WORKBENCH);
|
||||
}
|
||||
};
|
||||
// 获取公钥
|
||||
const getPublicKey = async () => {
|
||||
if (getLocalStorage('salt')) return;
|
||||
const publicKey = await getPublicKeyRequest();
|
||||
setLocalStorage('salt', publicKey);
|
||||
};
|
||||
|
||||
// 白名单,不需要验证是否登录的页面
|
||||
const whiteList = ['#/invite'];
|
||||
onMounted(async () => {
|
||||
await getPublicKey();
|
||||
if (!whiteList.includes(window.location.hash)) {
|
||||
await checkIsLogin();
|
||||
}
|
||||
|
|
|
@ -5,23 +5,17 @@ import useUser from '@/hooks/useUser';
|
|||
|
||||
export default function checkStatus(status: number, msg: string, errorMessageMode: ErrorMessageMode = 'message'): void {
|
||||
const { t } = useI18n();
|
||||
const { logout, setSalt, isLoginPage } = useUser();
|
||||
const { logout, isLoginPage } = useUser();
|
||||
let errMessage = '';
|
||||
switch (status) {
|
||||
case 400:
|
||||
errMessage = `${msg}`;
|
||||
break;
|
||||
case 401: {
|
||||
if (msg.length === 216) {
|
||||
// 216是salt的长度
|
||||
setSalt(msg);
|
||||
} else {
|
||||
errMessage = msg || t('api.errMsg401');
|
||||
}
|
||||
if (!isLoginPage()) {
|
||||
// 不是登录页再调用logout
|
||||
logout();
|
||||
errMessage = t('api.errMsg401');
|
||||
errMessage = msg || t('api.errMsg401');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import MSR from '@/api/http/index';
|
||||
import { LoginUrl, LogoutUrl, GetMenuListUrl, isLoginUrl } from '@/api/requrls/user';
|
||||
import { LoginUrl, LogoutUrl, GetMenuListUrl, isLoginUrl, getPublicKeyUrl } from '@/api/requrls/user';
|
||||
import type { RouteRecordNormalized } from 'vue-router';
|
||||
import type { LoginData, LoginRes } from '@/models/user';
|
||||
|
||||
|
@ -18,3 +18,7 @@ export function logout() {
|
|||
export function getMenuList() {
|
||||
return MSR.post<RouteRecordNormalized[]>({ url: GetMenuListUrl });
|
||||
}
|
||||
|
||||
export function getPublicKeyRequest() {
|
||||
return MSR.get<string>({ url: getPublicKeyUrl }, { ignoreCancelToken: true });
|
||||
}
|
||||
|
|
|
@ -2,3 +2,4 @@ export const LoginUrl = '/login';
|
|||
export const isLoginUrl = '/is-login';
|
||||
export const LogoutUrl = '/signout';
|
||||
export const GetMenuListUrl = '/api/user/menu';
|
||||
export const getPublicKeyUrl = '/get-key';
|
||||
|
|
|
@ -21,17 +21,12 @@ export default function useUser() {
|
|||
});
|
||||
};
|
||||
|
||||
const setSalt = (salt: string) => {
|
||||
localStorage.setItem('salt', salt);
|
||||
};
|
||||
|
||||
const isLoginPage = () => {
|
||||
return window.location.hash.indexOf('login') > -1;
|
||||
};
|
||||
|
||||
return {
|
||||
logout,
|
||||
setSalt,
|
||||
isLoginPage,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue