From 3737e6496b407d73931013e6e82ff35eb120a300 Mon Sep 17 00:00:00 2001 From: ideal Date: Thu, 24 Apr 2025 19:13:42 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E5=9C=A8H5=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E7=8E=AF=E5=A2=83=E4=B8=8B=EF=BC=8C=E6=8B=BC?= =?UTF-8?q?=E6=8E=A5=E4=BB=A3=E7=90=86=E5=89=8D=E7=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interceptors/request.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/interceptors/request.ts b/src/interceptors/request.ts index 1f84b31..63ea3e0 100644 --- a/src/interceptors/request.ts +++ b/src/interceptors/request.ts @@ -31,7 +31,8 @@ const httpInterceptor = { // #ifdef H5 // console.log(__VITE_APP_PROXY__) if (JSON.parse(__VITE_APP_PROXY__)) { - // 啥都不需要做 + // 自动拼接代理前缀 + options.url = import.meta.env.VITE_APP_PROXY_PREFIX + options.url } else { options.url = baseUrl + options.url } From 32765a789a8ac4562ca97c5bccb33c7ede5b5867 Mon Sep 17 00:00:00 2001 From: ideal Date: Fri, 25 Apr 2025 17:07:12 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E8=B7=AF=E7=94=B1=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E5=99=A8=E5=9C=A8=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=84=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8B=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interceptors/route.ts | 15 ++++++++++++--- src/utils/index.ts | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/interceptors/route.ts b/src/interceptors/route.ts index ddd6c98..d550c97 100644 --- a/src/interceptors/route.ts +++ b/src/interceptors/route.ts @@ -5,7 +5,7 @@ * 我这里应为大部分都可以随便进入,所以使用黑名单 */ import { useUserStore } from '@/store' -import { needLoginPages as _needLoginPages, getNeedLoginPages } from '@/utils' +import { needLoginPages as _needLoginPages, getNeedLoginPages, getLastPage } from '@/utils' // TODO Check const loginRoute = '/pages/login/index' @@ -19,10 +19,19 @@ const isDev = import.meta.env.DEV // 黑名单登录拦截器 - (适用于大部分页面不需要登录,少部分页面需要登录) const navigateToInterceptor = { - // 注意,这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同 + // 注意,这里的url是 '/' 开头的(也有可能是相对路径),如 '/pages/index/index',跟 'pages.json' 里面的 path 不同 invoke({ url }: { url: string }) { // console.log(url) // /pages/route-interceptor/index?name=feige&age=30 - const path = url.split('?')[0] + let path = url.split('?')[0] + + // 处理相对路径 + if (!path.startsWith('/')) { + const currentPath = getLastPage().route + const normalizedCurrentPath = currentPath.startsWith('/') ? currentPath : `/${currentPath}` + const baseDir = normalizedCurrentPath.substring(0, normalizedCurrentPath.lastIndexOf('/')) + path = `${baseDir}/${path}` + } + let needLoginPages: string[] = [] // 为了防止开发时出现BUG,这里每次都获取一下。生产环境可以移到函数外,性能更好 if (isDev) { diff --git a/src/utils/index.ts b/src/utils/index.ts index a60e713..e358e1b 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,7 +1,7 @@ import { pages, subPackages, tabBar } from '@/pages.json' import { isMpWeixin } from './platform' -const getLastPage = () => { +export const getLastPage = () => { // getCurrentPages() 至少有1个元素,所以不再额外判断 // const lastPage = getCurrentPages().at(-1) // 上面那个在低版本安卓中打包会报错,所以改用下面这个【虽然我加了 src/interceptions/prototype.ts,但依然报错】 From 91f295fbb19f49ae4f530f4d9009ca5eb7e8d2df Mon Sep 17 00:00:00 2001 From: feige996 <1020102647@qq.com> Date: Mon, 28 Apr 2025 18:18:12 +0800 Subject: [PATCH 3/3] chore: ideal --- src/interceptors/route.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/interceptors/route.ts b/src/interceptors/route.ts index d550c97..6e71763 100644 --- a/src/interceptors/route.ts +++ b/src/interceptors/route.ts @@ -19,7 +19,8 @@ const isDev = import.meta.env.DEV // 黑名单登录拦截器 - (适用于大部分页面不需要登录,少部分页面需要登录) const navigateToInterceptor = { - // 注意,这里的url是 '/' 开头的(也有可能是相对路径),如 '/pages/index/index',跟 'pages.json' 里面的 path 不同 + // 注意,这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同 + // 增加对相对路径的处理,BY 网友 @ideal invoke({ url }: { url: string }) { // console.log(url) // /pages/route-interceptor/index?name=feige&age=30 let path = url.split('?')[0]