From f01c764589f48311b48fb1a262e449e7dd3523ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BB=96=E5=BD=A6=E6=A3=8B?= Date: Thu, 14 Mar 2024 17:19:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20=E6=97=A0=E6=9D=83=E9=99=90?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- new-ui/projects/admin/env.d.ts | 10 +--------- new-ui/projects/admin/src/http/config.ts | 15 +++++++++++---- new-ui/projects/admin/src/router/type.d.ts | 8 ++++++++ 3 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 new-ui/projects/admin/src/router/type.d.ts diff --git a/new-ui/projects/admin/env.d.ts b/new-ui/projects/admin/env.d.ts index 0f8e5fd5..941fc709 100644 --- a/new-ui/projects/admin/env.d.ts +++ b/new-ui/projects/admin/env.d.ts @@ -5,13 +5,5 @@ declare module "*.vue" { const component: DefineComponent<{}, {}, any>; export default component; } -import 'vue-router' -declare module 'vue-router' { - interface RouteMeta { - title?: string - icon?: any - permission?: boolean | string | string[] - } -} -declare const __AUTH_KEY: string; \ No newline at end of file +declare const __AUTH_KEY: string; diff --git a/new-ui/projects/admin/src/http/config.ts b/new-ui/projects/admin/src/http/config.ts index 14ddc588..2437420d 100644 --- a/new-ui/projects/admin/src/http/config.ts +++ b/new-ui/projects/admin/src/http/config.ts @@ -17,10 +17,17 @@ instance.interceptors.request.use((config) => { instance.interceptors.response.use( (response) => { const { data }: { data: BaseResponse } = response - if (data && typeof data === "object" && data.code !== 0) { - if (data.code === 400) { - localStorage.removeItem(__AUTH_KEY); - router.push({ name: "Login" }) + if (data && typeof data === "object" && data.code > 0) { + switch (data.code) { + case 400: { + localStorage.removeItem(__AUTH_KEY); + router.push({ name: "Login" }) + break; + } + case 403: { + router.replace({ name: "403" }) + break; + } } Notification.error(data.message ?? '未知错误') } diff --git a/new-ui/projects/admin/src/router/type.d.ts b/new-ui/projects/admin/src/router/type.d.ts new file mode 100644 index 00000000..e1bf1fc7 --- /dev/null +++ b/new-ui/projects/admin/src/router/type.d.ts @@ -0,0 +1,8 @@ +import 'vue-router' +declare module 'vue-router' { + interface RouteMeta { + title?: string + icon?: any + permission?: boolean | string | string[] + } +} \ No newline at end of file