diff --git a/frontend/src/App.vue b/frontend/src/App.vue index de9856197c..189c613617 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -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(); } diff --git a/frontend/src/api/http/checkStatus.ts b/frontend/src/api/http/checkStatus.ts index da28f18877..c6dc5e5c39 100644 --- a/frontend/src/api/http/checkStatus.ts +++ b/frontend/src/api/http/checkStatus.ts @@ -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; } diff --git a/frontend/src/api/modules/user/index.ts b/frontend/src/api/modules/user/index.ts index 5fad5fb397..4ade260fba 100644 --- a/frontend/src/api/modules/user/index.ts +++ b/frontend/src/api/modules/user/index.ts @@ -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({ url: GetMenuListUrl }); } + +export function getPublicKeyRequest() { + return MSR.get({ url: getPublicKeyUrl }, { ignoreCancelToken: true }); +} diff --git a/frontend/src/api/requrls/user.ts b/frontend/src/api/requrls/user.ts index e828467c48..e05a14851a 100644 --- a/frontend/src/api/requrls/user.ts +++ b/frontend/src/api/requrls/user.ts @@ -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'; diff --git a/frontend/src/hooks/useUser.ts b/frontend/src/hooks/useUser.ts index ae3a71b382..84dbb8becd 100644 --- a/frontend/src/hooks/useUser.ts +++ b/frontend/src/hooks/useUser.ts @@ -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, }; }