Просмотр исходного кода

Merge branch 'base' into tabbar

feige996 11 месяцев назад
Родитель
Сommit
2959974f86
5 измененных файлов с 17 добавлено и 6 удалено
  1. 1 1
      .eslintrc.cjs
  2. 1 1
      package.json
  3. 2 1
      src/interceptors/request.ts
  4. 12 2
      src/interceptors/route.ts
  5. 1 1
      src/utils/index.ts

+ 1 - 1
.eslintrc.cjs

@@ -63,13 +63,13 @@ module.exports = {
     'no-shadow': 'off',
     'no-shadow': 'off',
     'vue/multi-word-component-names': 'off',
     'vue/multi-word-component-names': 'off',
     'vue/no-unused-vars': 'off',
     'vue/no-unused-vars': 'off',
+    '@typescript-eslint/no-unused-vars': 'off',
     '@typescript-eslint/no-explicit-any': 'off',
     '@typescript-eslint/no-explicit-any': 'off',
     'no-underscore-dangle': 'off',
     'no-underscore-dangle': 'off',
     'no-use-before-define': 'off',
     'no-use-before-define': 'off',
     'no-undef': 'off',
     'no-undef': 'off',
     'no-unused-vars': 'off',
     'no-unused-vars': 'off',
     'no-param-reassign': 'off',
     'no-param-reassign': 'off',
-    '@typescript-eslint/no-unused-vars': 'off',
     // 避免 `eslint` 对于 `typescript` 函数重载的误报
     // 避免 `eslint` 对于 `typescript` 函数重载的误报
     'no-redeclare': 'off',
     'no-redeclare': 'off',
     '@typescript-eslint/no-redeclare': 'error',
     '@typescript-eslint/no-redeclare': 'error',

+ 1 - 1
package.json

@@ -1,7 +1,7 @@
 {
 {
   "name": "unibest",
   "name": "unibest",
   "type": "commonjs",
   "type": "commonjs",
-  "version": "2.6.3",
+  "version": "2.6.4",
   "description": "unibest - 最好的 uniapp 开发模板",
   "description": "unibest - 最好的 uniapp 开发模板",
   "author": {
   "author": {
     "name": "feige996",
     "name": "feige996",

+ 2 - 1
src/interceptors/request.ts

@@ -31,7 +31,8 @@ const httpInterceptor = {
       // #ifdef H5
       // #ifdef H5
       // console.log(__VITE_APP_PROXY__)
       // console.log(__VITE_APP_PROXY__)
       if (JSON.parse(__VITE_APP_PROXY__)) {
       if (JSON.parse(__VITE_APP_PROXY__)) {
-        // 啥都不需要做
+        // 自动拼接代理前缀
+        options.url = import.meta.env.VITE_APP_PROXY_PREFIX + options.url
       } else {
       } else {
         options.url = baseUrl + options.url
         options.url = baseUrl + options.url
       }
       }

+ 12 - 2
src/interceptors/route.ts

@@ -5,7 +5,7 @@
  * 我这里应为大部分都可以随便进入,所以使用黑名单
  * 我这里应为大部分都可以随便进入,所以使用黑名单
  */
  */
 import { useUserStore } from '@/store'
 import { useUserStore } from '@/store'
-import { needLoginPages as _needLoginPages, getNeedLoginPages } from '@/utils'
+import { needLoginPages as _needLoginPages, getNeedLoginPages, getLastPage } from '@/utils'
 
 
 // TODO Check
 // TODO Check
 const loginRoute = '/pages/login/index'
 const loginRoute = '/pages/login/index'
@@ -20,9 +20,19 @@ const isDev = import.meta.env.DEV
 // 黑名单登录拦截器 - (适用于大部分页面不需要登录,少部分页面需要登录)
 // 黑名单登录拦截器 - (适用于大部分页面不需要登录,少部分页面需要登录)
 const navigateToInterceptor = {
 const navigateToInterceptor = {
   // 注意,这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同
   // 注意,这里的url是 '/' 开头的,如 '/pages/index/index',跟 'pages.json' 里面的 path 不同
+  // 增加对相对路径的处理,BY 网友 @ideal
   invoke({ url }: { url: string }) {
   invoke({ url }: { url: string }) {
     // console.log(url) // /pages/route-interceptor/index?name=feige&age=30
     // 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[] = []
     let needLoginPages: string[] = []
     // 为了防止开发时出现BUG,这里每次都获取一下。生产环境可以移到函数外,性能更好
     // 为了防止开发时出现BUG,这里每次都获取一下。生产环境可以移到函数外,性能更好
     if (isDev) {
     if (isDev) {

+ 1 - 1
src/utils/index.ts

@@ -1,7 +1,7 @@
 import { pages, subPackages, tabBar } from '@/pages.json'
 import { pages, subPackages, tabBar } from '@/pages.json'
 import { isMpWeixin } from './platform'
 import { isMpWeixin } from './platform'
 
 
-const getLastPage = () => {
+export const getLastPage = () => {
   // getCurrentPages() 至少有1个元素,所以不再额外判断
   // getCurrentPages() 至少有1个元素,所以不再额外判断
   // const lastPage = getCurrentPages().at(-1)
   // const lastPage = getCurrentPages().at(-1)
   // 上面那个在低版本安卓中打包会报错,所以改用下面这个【虽然我加了 src/interceptions/prototype.ts,但依然报错】
   // 上面那个在低版本安卓中打包会报错,所以改用下面这个【虽然我加了 src/interceptions/prototype.ts,但依然报错】