From 94edda9710c411a607221bf3d936f7298e788cc6 Mon Sep 17 00:00:00 2001 From: yml Date: Fri, 22 May 2026 23:52:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=8D=E6=AC=A1=E4=BC=98=E5=8C=96=E4=BA=86?= =?UTF-8?q?=E7=99=BB=E9=99=86=E6=B3=A8=E5=86=8C=E7=95=8C=E9=9D=A2=E4=B8=8E?= =?UTF-8?q?=E8=B7=B3=E8=BD=AC=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/components.d.ts | 7 - frontend/src/api/client.ts | 34 ++ frontend/src/router/index.ts | 14 +- frontend/src/views/mobile/MobileLoginView.vue | 450 ++++++++--------- .../src/views/mobile/MobileProfileView.vue | 96 +--- .../src/views/mobile/MobileRegisterView.vue | 465 ++++++++---------- 6 files changed, 473 insertions(+), 593 deletions(-) diff --git a/frontend/components.d.ts b/frontend/components.d.ts index 70802f1..3785345 100644 --- a/frontend/components.d.ts +++ b/frontend/components.d.ts @@ -17,21 +17,14 @@ declare module 'vue' { VanCell: typeof import('vant/es')['Cell'] VanCellGroup: typeof import('vant/es')['CellGroup'] VanCheckbox: typeof import('vant/es')['Checkbox'] - VanDropdownItem: typeof import('vant/es')['DropdownItem'] - VanDropdownMenu: typeof import('vant/es')['DropdownMenu'] VanEmpty: typeof import('vant/es')['Empty'] VanField: typeof import('vant/es')['Field'] - VanGrid: typeof import('vant/es')['Grid'] - VanGridItem: typeof import('vant/es')['GridItem'] VanIcon: typeof import('vant/es')['Icon'] - VanImage: typeof import('vant/es')['Image'] VanLoading: typeof import('vant/es')['Loading'] VanNoticeBar: typeof import('vant/es')['NoticeBar'] VanPopup: typeof import('vant/es')['Popup'] VanPullRefresh: typeof import('vant/es')['PullRefresh'] VanSearch: typeof import('vant/es')['Search'] - VanTabbar: typeof import('vant/es')['Tabbar'] - VanTabbarItem: typeof import('vant/es')['TabbarItem'] VanTag: typeof import('vant/es')['Tag'] } } diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts index dc6fbe5..9148212 100644 --- a/frontend/src/api/client.ts +++ b/frontend/src/api/client.ts @@ -14,3 +14,37 @@ apiClient.interceptors.request.use((config) => { } return config }) + +apiClient.interceptors.response.use( + (response) => response, + (error) => { + if (error?.response?.status !== 401) { + return Promise.reject(error) + } + + const requestUrl = error.config?.url || '' + const isAdminRequest = requestUrl.startsWith('/admin') + const currentPath = window.location.pathname + window.location.search + + if (isAdminRequest) { + localStorage.removeItem('admin_access_token') + localStorage.removeItem('admin_refresh_token') + if (!window.location.pathname.startsWith('/admin/login')) { + window.location.assign('/admin/login') + } + return Promise.reject(error) + } + + localStorage.removeItem('access_token') + localStorage.removeItem('refresh_token') + localStorage.removeItem('user_id') + + if (!window.location.pathname.startsWith('/m/login') && !window.location.pathname.startsWith('/m/register')) { + const redirect = encodeURIComponent(currentPath) + const loginPath = window.location.pathname.startsWith('/m') ? '/m/login' : '/login' + window.location.assign(`${loginPath}?redirect=${redirect}`) + } + + return Promise.reject(error) + }, +) diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 8123e82..b746c69 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -40,32 +40,32 @@ const router = createRouter({ path: "/m/messages", name: "mobile-messages", component: () => import("@/views/mobile/MobileMessagesView.vue"), - meta: { layout: "blank" }, + meta: { layout: "blank", requiresAuth: true }, }, { path: "/m/realname", name: "mobile-realname", component: () => import("@/views/mobile/MobileRealnameView.vue"), - meta: { layout: "blank" }, + meta: { layout: "blank", requiresAuth: true }, }, { path: "/m/profile", name: "mobile-profile", component: () => import("@/views/mobile/MobileProfileView.vue"), - meta: { layout: "blank" }, + meta: { layout: "blank", requiresAuth: true }, }, { path: "/m/orders", name: "mobile-orders", component: () => import("@/views/mobile/MobileOrdersView.vue"), - meta: { layout: "blank" }, + meta: { layout: "blank", requiresAuth: true }, }, { path: "/m/seller/listings/create", name: "mobile-seller-listing-create", component: () => import("@/views/mobile/MobileSellerListingCreateView.vue"), - meta: { layout: "blank" }, + meta: { layout: "blank", requiresAuth: true }, }, { path: "/", @@ -217,6 +217,10 @@ router.beforeEach((to) => { return { path: toMobilePath(to.path), query: to.query, hash: to.hash }; } + if (to.meta.requiresAuth && !localStorage.getItem("access_token")) { + return { path: "/m/login", query: { redirect: to.fullPath } }; + } + if ( to.path === "/admin/login" && localStorage.getItem("admin_access_token") diff --git a/frontend/src/views/mobile/MobileLoginView.vue b/frontend/src/views/mobile/MobileLoginView.vue index 7a42c55..bef6ae9 100644 --- a/frontend/src/views/mobile/MobileLoginView.vue +++ b/frontend/src/views/mobile/MobileLoginView.vue @@ -1,12 +1,13 @@