From 494c6452b5c619da374ded3a25678e8a61e46b4c Mon Sep 17 00:00:00 2001 From: feige996 <1020102647@qq.com> Date: Fri, 22 Aug 2025 17:46:43 +0800 Subject: [PATCH] =?UTF-8?q?refactor(router):=20=E4=BD=BF=E7=94=A8=E5=B8=B8?= =?UTF-8?q?=E9=87=8F=E6=9B=BF=E6=8D=A2=E7=A1=AC=E7=BC=96=E7=A0=81=E7=9A=84?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E9=A1=B5=E9=9D=A2=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将多处硬编码的登录页面路径替换为统一的常量LOGIN_PAGE,提高代码可维护性 同时将注册页面路径也提取为常量REGISTER_PAGE --- src/http/alova.ts | 3 ++- src/http/http.ts | 5 +++-- src/pages/index/index.vue | 3 ++- src/pages/login/register.vue | 4 +++- src/pages/me/me.vue | 5 +++-- src/router/config.ts | 3 ++- src/store/token.ts | 1 - 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/http/alova.ts b/src/http/alova.ts index 52aaf61..696c795 100644 --- a/src/http/alova.ts +++ b/src/http/alova.ts @@ -4,6 +4,7 @@ import AdapterUniapp from '@alova/adapter-uniapp' import { createAlova } from 'alova' import { createServerTokenAuthentication } from 'alova/client' import VueHook from 'alova/vue' +import { LOGIN_PAGE } from '@/router/config' import { ContentTypeEnum, ResultEnum, ShowMessage } from './tools/enum' // 配置动态Tag @@ -29,7 +30,7 @@ const { onAuthRequired, onResponseRefreshToken } = createServerTokenAuthenticati } catch (error) { // 切换到登录页 - await uni.reLaunch({ url: '/pages/login/login' }) + await uni.reLaunch({ url: LOGIN_PAGE }) throw error } }, diff --git a/src/http/http.ts b/src/http/http.ts index e8b47ae..1d3ce2e 100644 --- a/src/http/http.ts +++ b/src/http/http.ts @@ -1,6 +1,7 @@ import type { IDoubleTokenRes } from '@/api/types/login' import type { CustomRequestOptions } from '@/http/types' import { nextTick } from 'vue' +import { LOGIN_PAGE } from '@/router/config' import { useTokenStore } from '@/store/token' import { isDoubleTokenMode } from '@/utils' @@ -30,7 +31,7 @@ export function http(options: CustomRequestOptions) { if (!isDoubleTokenMode) { // 未启用双token策略,清理用户信息,跳转到登录页 tokenStore.logout() - uni.navigateTo({ url: '/pages/login/login' }) + uni.navigateTo({ url: LOGIN_PAGE }) return reject(res) } /* -------- 无感刷新 token ----------- */ @@ -76,7 +77,7 @@ export function http(options: CustomRequestOptions) { await tokenStore.logout() // 跳转到登录页 setTimeout(() => { - uni.navigateTo({ url: '/pages/login/login' }) + uni.navigateTo({ url: LOGIN_PAGE }) }, 2000) } finally { diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 1be810f..c69423c 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -11,6 +11,7 @@ diff --git a/src/pages/me/me.vue b/src/pages/me/me.vue index d926110..8dbb5b6 100644 --- a/src/pages/me/me.vue +++ b/src/pages/me/me.vue @@ -12,6 +12,7 @@