Jelajahi Sumber

Merge branch base

Burt 1 tahun lalu
induk
melakukan
c4736a8e67
7 mengubah file dengan 394 tambahan dan 438 penghapusan
  1. 2 0
      README.md
  2. 3 2
      package.json
  3. 317 432
      pnpm-lock.yaml
  4. 3 1
      src/hooks/useUpload.ts
  5. 2 1
      src/interceptors/request.ts
  6. 60 0
      src/utils/index.ts
  7. 7 2
      tsconfig.json

+ 2 - 0
README.md

@@ -41,6 +41,8 @@
 
 - node>=18
 - pnpm>=7.30
+- Vue Official<=2.1.6
+- TypeScript<=5.5.4
 
 ## &#x1F4C2; 快速开始
 

+ 3 - 2
package.json

@@ -93,7 +93,7 @@
     "pinia-plugin-persistedstate": "3.2.1",
     "qs": "6.5.3",
     "vue": "3.4.21",
-    "wot-design-uni": "^1.3.9",
+    "wot-design-uni": "^1.3.10",
     "z-paging": "^2.7.10"
   },
   "devDependencies": {
@@ -112,6 +112,7 @@
     "@types/wechat-miniprogram": "^3.4.7",
     "@typescript-eslint/eslint-plugin": "^6.21.0",
     "@typescript-eslint/parser": "^6.21.0",
+    "@uni-helper/uni-types": "1.0.0-alpha.3",
     "@uni-helper/vite-plugin-uni-layouts": "^0.1.10",
     "@uni-helper/vite-plugin-uni-manifest": "^0.2.6",
     "@uni-helper/vite-plugin-uni-pages": "0.2.20",
@@ -144,7 +145,7 @@
     "stylelint-config-recommended-vue": "^1.5.0",
     "stylelint-prettier": "^5.0.0",
     "terser": "^5.31.1",
-    "typescript": "^4.9.5",
+    "typescript": "^5.5.4",
     "unocss": "^0.58.9",
     "unocss-applet": "^0.7.8",
     "unplugin-auto-import": "^0.17.6",

File diff ditekan karena terlalu besar
+ 317 - 432
pnpm-lock.yaml


+ 3 - 1
src/hooks/useUpload.ts

@@ -1,5 +1,7 @@
 // TODO: 别忘加更改环境变量的 VITE_UPLOAD_BASEURL 地址。
-const VITE_UPLOAD_BASEURL = import.meta.env.VITE_UPLOAD_BASEURL
+import { getEvnBaseUploadUrl } from '@/utils'
+
+const VITE_UPLOAD_BASEURL = `${getEvnBaseUploadUrl()}`
 
 /**
  * useUpload 是一个定制化的请求钩子,用于处理上传图片。

+ 2 - 1
src/interceptors/request.ts

@@ -2,6 +2,7 @@
 import qs from 'qs'
 import { useUserStore } from '@/store'
 import { platform } from '@/utils/platform'
+import { getEvnBaseUrl } from '@/utils'
 
 export type CustomRequestOptions = UniApp.RequestOptions & {
   query?: Record<string, any>
@@ -10,7 +11,7 @@ export type CustomRequestOptions = UniApp.RequestOptions & {
 } & IUniUploadFileOptions // 添加uni.uploadFile参数类型
 
 // 请求基准地址
-const baseUrl = import.meta.env.VITE_SERVER_BASEURL
+const baseUrl = getEvnBaseUrl()
 
 // 拦截器配置
 const httpInterceptor = {

+ 60 - 0
src/utils/index.ts

@@ -1,4 +1,6 @@
 import { pages, subPackages, tabBar } from '@/pages.json'
+import { isMp } from './platform'
+
 const getLastPage = () => {
   // getCurrentPages() 至少有1个元素,所以不再额外判断
   // const lastPage = getCurrentPages().at(-1)
@@ -116,3 +118,61 @@ export const getNeedLoginPages = (): string[] => getAllPages('needLogin').map((p
  * 只得到 path 数组
  */
 export const needLoginPages: string[] = getAllPages('needLogin').map((page) => page.path)
+
+/**
+ * 根据微信小程序当前环境,判断应该获取的BaseUrl
+ */
+export const getEvnBaseUrl = () => {
+  // 请求基准地址
+  let baseUrl = import.meta.env.VITE_SERVER_BASEURL
+
+  // 小程序端环境区分
+  if (isMp) {
+    const {
+      miniProgram: { envVersion },
+    } = uni.getAccountInfoSync()
+
+    switch (envVersion) {
+      case 'develop':
+        baseUrl = 'https://ukw0y1.laf.run'
+        break
+      case 'trial':
+        baseUrl = 'https://ukw0y1.laf.run'
+        break
+      case 'release':
+        baseUrl = 'https://ukw0y1.laf.run'
+        break
+    }
+  }
+
+  return baseUrl
+}
+
+/**
+ * 根据微信小程序当前环境,判断应该获取的UPLOAD_BASEURL
+ */
+export const getEvnBaseUploadUrl = () => {
+  // 请求基准地址
+  let baseUploadUrl = import.meta.env.VITE_UPLOAD_BASEURL
+
+  // 小程序端环境区分
+  if (isMp) {
+    const {
+      miniProgram: { envVersion },
+    } = uni.getAccountInfoSync()
+
+    switch (envVersion) {
+      case 'develop':
+        baseUploadUrl = 'https://ukw0y1.laf.run/upload'
+        break
+      case 'trial':
+        baseUploadUrl = 'https://ukw0y1.laf.run/upload'
+        break
+      case 'release':
+        baseUploadUrl = 'https://ukw0y1.laf.run/upload'
+        break
+    }
+  }
+
+  return baseUploadUrl
+}

+ 7 - 2
tsconfig.json

@@ -15,11 +15,16 @@
     },
     "outDir": "dist",
     "lib": ["esnext", "dom"],
-    "types": ["@dcloudio/types", "@types/wechat-miniprogram", "wot-design-uni/global.d.ts"]
+    "types": [
+      "@dcloudio/types",
+      "@uni-helper/uni-types",
+      "@types/wechat-miniprogram",
+      "wot-design-uni/global.d.ts"
+    ]
   },
   "vueCompilerOptions": {
     "target": 3,
-    "nativeTags": ["block", "template", "component", "slot"]
+    "plugins": ["@uni-helper/uni-types/volar-plugin"]
   },
   "exclude": ["node_modules"],
   "include": [