diff --git a/frontend/src/assets/svg/401.svg b/frontend/src/assets/svg/401.svg new file mode 100644 index 00000000..d02779fa --- /dev/null +++ b/frontend/src/assets/svg/401.svg @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 0b5adb2f..00fad166 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -21,6 +21,7 @@ import Appearance from '@/views/system/appearance/index.vue' import Permission from '@/views/system/permission/index.vue' import User from '@/views/system/user/User.vue' import Workspace from '@/views/system/workspace/index.vue' +import Page401 from '@/views/error/index.vue' import { i18n } from '@/i18n' import { watchRouter } from './watch' @@ -207,6 +208,13 @@ export const routes = [ name: 'assistantTest', component: assistantTest, }, + { + path: '/401', + name: '401', + hidden: true, + meta: {}, + component: Page401, + }, ] const router = createRouter({ history: createWebHashHistory(), diff --git a/frontend/src/router/watch.ts b/frontend/src/router/watch.ts index fe08edd4..ae0d6631 100644 --- a/frontend/src/router/watch.ts +++ b/frontend/src/router/watch.ts @@ -8,7 +8,7 @@ const appearanceStore = useAppearanceStoreWithOut() const userStore = useUserStore() const { wsCache } = useCache() const whiteList = ['/login'] -const assistantWhiteList = ['/assistant', '/embeddedPage'] +const assistantWhiteList = ['/assistant', '/embeddedPage', '/401'] export const watchRouter = (router: any) => { router.beforeEach(async (to: any, from: any, next: any) => { await loadXpackStatic() diff --git a/frontend/src/utils/request.ts b/frontend/src/utils/request.ts index f222fae5..63b6ed70 100644 --- a/frontend/src/utils/request.ts +++ b/frontend/src/utils/request.ts @@ -11,10 +11,12 @@ import axios, { import { useCache } from '@/utils/useCache' import { getLocale } from './utils' import { useAssistantStore } from '@/stores/assistant' +import { useRouter } from 'vue-router' // import { i18n } from '@/i18n' // const t = i18n.global.t const assistantStore = useAssistantStore() const { wsCache } = useCache() +const router = useRouter() // Response data structure export interface ApiResponse { code: number @@ -193,6 +195,15 @@ class HttpService { ? error.response.data.toString() : 'Unauthorized, please login again' // Redirect to login page if needed + if (assistantStore.getAssistant) { + wsCache.delete('user.token') + if (router?.push) { + router.push(`/401?title=${encodeURIComponent(errorMessage)}`) + } else { + window.location.href = `/#/401?title=${encodeURIComponent(errorMessage)}` + } + return + } ElMessage({ message: errorMessage, type: 'error', diff --git a/frontend/src/views/error/index.vue b/frontend/src/views/error/index.vue new file mode 100644 index 00000000..ea9e7df1 --- /dev/null +++ b/frontend/src/views/error/index.vue @@ -0,0 +1,34 @@ + + + + {{ title || routerTitle || '' }} + + + + +