From 466724080e4360d6f86c20db84592bc3e92b129b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=8F=B2=E9=B8=BD?= <1020103647@qq.com>
Date: Mon, 6 Jan 2025 13:32:39 +0800
Subject: [PATCH 1/3] Merge pull request #42 from Rem-Blove/main
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
fix: 枚举失效问题 & 分离全局声明和模块化内容
---
src/pages/index/index.vue | 2 ++
src/typings.d.ts | 28 ++++++++++++++++++++++++++++
src/typings.ts | 31 ++++---------------------------
tsconfig.json | 3 ++-
4 files changed, 36 insertions(+), 28 deletions(-)
create mode 100644 src/typings.d.ts
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index 84d3606..59da0ab 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -31,6 +31,7 @@
diff --git a/src/typings.d.ts b/src/typings.d.ts
new file mode 100644
index 0000000..0ab0858
--- /dev/null
+++ b/src/typings.d.ts
@@ -0,0 +1,28 @@
+// 全局要用的类型放到这里
+
+declare global {
+ type IResData = {
+ code: number
+ msg: string
+ data: T
+ }
+
+ // uni.uploadFile文件上传参数
+ type IUniUploadFileOptions = {
+ file?: File
+ files?: UniApp.UploadFileOptionFiles[]
+ filePath?: string
+ name?: string
+ formData?: any
+ }
+
+ type IUserInfo = {
+ nickname?: string
+ avatar?: string
+ /** 微信的 openid,非微信没有这个字段 */
+ openid?: string
+ token?: string
+ }
+}
+
+export {} // 防止模块污染
diff --git a/src/typings.ts b/src/typings.ts
index 06354be..016e462 100644
--- a/src/typings.ts
+++ b/src/typings.ts
@@ -1,29 +1,6 @@
-// 全局要用的类型放到这里
+// 枚举定义
-type IResData = {
- code: number
- msg: string
- data: T
-}
-
-// uni.uploadFile文件上传参数
-type IUniUploadFileOptions = {
- file?: File
- files?: UniApp.UploadFileOptionFiles[]
- filePath?: string
- name?: string
- formData?: any
-}
-
-type IUserInfo = {
- nickname?: string
- avatar?: string
- /** 微信的 openid,非微信没有这个字段 */
- openid?: string
- token?: string
-}
-
-enum TestEnum {
- A = 'a',
- B = 'b',
+export enum TestEnum {
+ A = '1',
+ B = '2',
}
diff --git a/tsconfig.json b/tsconfig.json
index 8390fbe..495932e 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -20,7 +20,8 @@
"@uni-helper/uni-types",
"@types/wechat-miniprogram",
"wot-design-uni/global.d.ts",
- "z-paging/types"
+ "z-paging/types",
+ "./src/typings.d.ts"
]
},
"vueCompilerOptions": {
From 732f286ac1b8b0cf084317a2cd0d09d4fad767df Mon Sep 17 00:00:00 2001
From: Burt
Date: Mon, 6 Jan 2025 13:57:55 +0800
Subject: [PATCH 2/3] =?UTF-8?q?fix:=20miniProgram=20=E9=9C=80=E8=A6=81?=
=?UTF-8?q?=E5=8C=BA=E5=88=86=E4=B8=8D=E5=90=8C=E7=9A=84=E5=B0=8F=E7=A8=8B?=
=?UTF-8?q?=E5=BA=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.vscode/settings.json | 6 +++++-
env/.env | 10 ++++++++++
src/utils/index.ts | 22 +++++++++++-----------
src/utils/platform.ts | 7 +++++++
4 files changed, 33 insertions(+), 12 deletions(-)
diff --git a/.vscode/settings.json b/.vscode/settings.json
index fec1619..4990c35 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -36,6 +36,7 @@
"manifest.json": "jsonc" // manifest.json 可以写注释
},
"cSpell.words": [
+ "Aplipay",
"climblee",
"commitlint",
"dcloudio",
@@ -44,9 +45,12 @@
"refresherrefresh",
"scrolltolower",
"tabbar",
+ "Toutiao",
"unibest",
"uvui",
- "WechatMiniprogram"
+ "Wechat",
+ "WechatMiniprogram",
+ "Weixin"
],
"typescript.tsdk": "node_modules\\typescript\\lib",
// 控制相关文件嵌套展示
diff --git a/env/.env b/env/.env
index 03c7ecf..b842e46 100644
--- a/env/.env
+++ b/env/.env
@@ -10,6 +10,16 @@ VITE_APP_PUBLIC_BASE=/unibest/
VITE_SERVER_BASEURL = 'https://ukw0y1.laf.run'
VITE_UPLOAD_BASEURL = 'https://ukw0y1.laf.run/upload'
+# 有些同学可能需要在微信小程序里面根据 develop、trial、release 分别设置上传地址,参考代码如下。
+# 下面的变量如果没有设置,会默认使用 VITE_SERVER_BASEURL or VITE_UPLOAD_BASEURL
+VITE_SERVER_BASEURL__WEIXIN_DEVELOP = 'https://ukw0y1.laf.run'
+VITE_SERVER_BASEURL__WEIXIN_TRIAL = 'https://ukw0y1.laf.run'
+VITE_SERVER_BASEURL__WEIXIN_RELEASE = 'https://ukw0y1.laf.run'
+
+VITE_UPLOAD_BASEURL__WEIXIN_DEVELOP = 'https://ukw0y1.laf.run/upload'
+VITE_UPLOAD_BASEURL__WEIXIN_TRIAL = 'https://ukw0y1.laf.run/upload'
+VITE_UPLOAD_BASEURL__WEIXIN_RELEASE = 'https://ukw0y1.laf.run/upload'
+
# h5是否需要配置代理
VITE_APP_PROXY=false
VITE_APP_PROXY_PREFIX = '/api'
diff --git a/src/utils/index.ts b/src/utils/index.ts
index be21dd6..f729525 100644
--- a/src/utils/index.ts
+++ b/src/utils/index.ts
@@ -1,5 +1,5 @@
import { pages, subPackages, tabBar } from '@/pages.json'
-import { isMp } from './platform'
+import { isMpWeixin } from './platform'
const getLastPage = () => {
// getCurrentPages() 至少有1个元素,所以不再额外判断
@@ -126,21 +126,21 @@ export const getEnvBaseUrl = () => {
// 请求基准地址
let baseUrl = import.meta.env.VITE_SERVER_BASEURL
- // 小程序端环境区分
- if (isMp) {
+ // 微信小程序端环境区分
+ if (isMpWeixin) {
const {
miniProgram: { envVersion },
} = uni.getAccountInfoSync()
switch (envVersion) {
case 'develop':
- baseUrl = 'https://ukw0y1.laf.run'
+ baseUrl = import.meta.env.VITE_SERVER_BASEURL__WEIXIN_DEVELOP || baseUrl
break
case 'trial':
- baseUrl = 'https://ukw0y1.laf.run'
+ baseUrl = import.meta.env.VITE_SERVER_BASEURL__WEIXIN_TRIAL || baseUrl
break
case 'release':
- baseUrl = 'https://ukw0y1.laf.run'
+ baseUrl = import.meta.env.VITE_SERVER_BASEURL__WEIXIN_RELEASE || baseUrl
break
}
}
@@ -155,21 +155,21 @@ export const getEnvBaseUploadUrl = () => {
// 请求基准地址
let baseUploadUrl = import.meta.env.VITE_UPLOAD_BASEURL
- // 小程序端环境区分
- if (isMp) {
+ // 微信小程序端环境区分
+ if (isMpWeixin) {
const {
miniProgram: { envVersion },
} = uni.getAccountInfoSync()
switch (envVersion) {
case 'develop':
- baseUploadUrl = 'https://ukw0y1.laf.run/upload'
+ baseUploadUrl = import.meta.env.VITE_UPLOAD_BASEURL__WEIXIN_DEVELOP || baseUploadUrl
break
case 'trial':
- baseUploadUrl = 'https://ukw0y1.laf.run/upload'
+ baseUploadUrl = import.meta.env.VITE_UPLOAD_BASEURL__WEIXIN_TRIAL || baseUploadUrl
break
case 'release':
- baseUploadUrl = 'https://ukw0y1.laf.run/upload'
+ baseUploadUrl = import.meta.env.VITE_UPLOAD_BASEURL__WEIXIN_RELEASE || baseUploadUrl
break
}
}
diff --git a/src/utils/platform.ts b/src/utils/platform.ts
index a42200c..c714199 100644
--- a/src/utils/platform.ts
+++ b/src/utils/platform.ts
@@ -8,10 +8,17 @@ export const platform = __UNI_PLATFORM__
export const isH5 = __UNI_PLATFORM__ === 'h5'
export const isApp = __UNI_PLATFORM__ === 'app'
export const isMp = __UNI_PLATFORM__.startsWith('mp-')
+export const isMpWeixin = __UNI_PLATFORM__.startsWith('mp-weixin')
+export const isMpAplipay = __UNI_PLATFORM__.startsWith('mp-alipay')
+export const isMpToutiao = __UNI_PLATFORM__.startsWith('mp-toutiao')
+
const PLATFORM = {
platform,
isH5,
isApp,
isMp,
+ isMpWeixin,
+ isMpAplipay,
+ isMpToutiao,
}
export default PLATFORM
From 29ecfdf6174e4238f9847b058b03e0a0a92cdc41 Mon Sep 17 00:00:00 2001
From: Burt
Date: Mon, 6 Jan 2025 13:59:48 +0800
Subject: [PATCH 3/3] build: update version
---
package.json | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/package.json b/package.json
index 99d4c06..5bf7579 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "unibest",
"type": "commonjs",
- "version": "2.5.4",
+ "version": "2.5.5",
"description": "unibest - 最好的 uniapp 开发模板",
"author": {
"name": "feige996",