From a6c417961198268decc3baae043a6066839d9ea1 Mon Sep 17 00:00:00 2001 From: zhangfengchen <1027307161@qq.com> Date: Mon, 25 May 2026 17:47:06 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E4=BD=93?= =?UTF-8?q?=E9=AA=8C=E7=89=88=E5=90=8E=E7=AB=AF=E6=8E=A5=E5=8F=A3=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 3 +++ sheep/config/index.js | 29 ++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.env b/.env index 03dd89b7..9a65d533 100644 --- a/.env +++ b/.env @@ -4,6 +4,9 @@ SHOPRO_VERSION=v2.4.1 # 后端接口 - 正式环境(通过 process.env.NODE_ENV 非 development) SHOPRO_BASE_URL=http://api-dashboard.yudao.iocoder.cn +# 后端接口 - 体验环境(通过 process.env.NODE_ENV 非 development) +SHOPRO_TRIAL_BASE_URL=https://suihuda.cn/tl + # 后端接口 - 测试环境(通过 process.env.NODE_ENV = development) SHOPRO_DEV_BASE_URL=http://127.0.0.1:48080 ### SHOPRO_DEV_BASE_URL=http://10.171.1.188:48080 diff --git a/sheep/config/index.js b/sheep/config/index.js index 803558c7..7767dac5 100644 --- a/sheep/config/index.js +++ b/sheep/config/index.js @@ -2,12 +2,39 @@ import packageInfo from '@/package.json'; const { version } = packageInfo; +// 获取微信小程序运行环境 +function getWxEnvVersion() { + // #ifdef MP-WEIXIN + try { + const accountInfo = wx.getAccountInfoSync(); + return accountInfo.miniProgram.envVersion; // develop: 开发版, trial: 体验版, release: 正式版 + } catch (e) { + console.log('获取微信小程序环境失败', e); + return 'release'; + } + // #endif +} + // 开发环境配置 export let baseUrl; if (process.env.NODE_ENV === 'development') { baseUrl = import.meta.env.SHOPRO_DEV_BASE_URL; } else { - baseUrl = import.meta.env.SHOPRO_BASE_URL; + // 生产环境下,判断是体验版还是正式版 + const wxEnvVersion = getWxEnvVersion(); + + if (wxEnvVersion === 'trial') { + // 体验版使用体验版服务器地址 + baseUrl = import.meta.env.SHOPRO_TRIAL_BASE_URL || import.meta.env.SHOPRO_BASE_URL; + console.log('当前运行环境:体验版'); + } else if (wxEnvVersion === 'release') { + // 正式版使用生产服务器地址 + baseUrl = import.meta.env.SHOPRO_BASE_URL; + console.log('当前运行环境:正式版'); + } else { + // 其他平台或获取失败,使用默认地址 + baseUrl = import.meta.env.SHOPRO_BASE_URL; + } } if (typeof baseUrl === 'undefined') { console.error('请检查.env配置文件是否存在'); From c6c240115d9fdcdbb9b63deb7919e5c236b2cd7c Mon Sep 17 00:00:00 2001 From: zhangfengchen <1027307161@qq.com> Date: Mon, 25 May 2026 17:50:49 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E4=BD=93?= =?UTF-8?q?=E9=AA=8C=E7=89=88=E5=90=8E=E7=AB=AF=E6=8E=A5=E5=8F=A3=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 5 ++++- sheep/config/index.js | 29 ++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/.env b/.env index 03dd89b7..b19e0dff 100644 --- a/.env +++ b/.env @@ -1,9 +1,12 @@ # 版本号 SHOPRO_VERSION=v2.4.1 -# 后端接口 - 正式环境(通过 process.env.NODE_ENV 非 development) +# 后端接口 - 正式环境(通过 process.env.NODE_ENV 非 development -生产环境-release) SHOPRO_BASE_URL=http://api-dashboard.yudao.iocoder.cn +# 后端接口 - 体验环境(通过 process.env.NODE_ENV 非 development -体验环境-trial) +SHOPRO_TRIAL_BASE_URL=http://api-dashboard.yudao.iocoder.cn/trial + # 后端接口 - 测试环境(通过 process.env.NODE_ENV = development) SHOPRO_DEV_BASE_URL=http://127.0.0.1:48080 ### SHOPRO_DEV_BASE_URL=http://10.171.1.188:48080 diff --git a/sheep/config/index.js b/sheep/config/index.js index 803558c7..7767dac5 100644 --- a/sheep/config/index.js +++ b/sheep/config/index.js @@ -2,12 +2,39 @@ import packageInfo from '@/package.json'; const { version } = packageInfo; +// 获取微信小程序运行环境 +function getWxEnvVersion() { + // #ifdef MP-WEIXIN + try { + const accountInfo = wx.getAccountInfoSync(); + return accountInfo.miniProgram.envVersion; // develop: 开发版, trial: 体验版, release: 正式版 + } catch (e) { + console.log('获取微信小程序环境失败', e); + return 'release'; + } + // #endif +} + // 开发环境配置 export let baseUrl; if (process.env.NODE_ENV === 'development') { baseUrl = import.meta.env.SHOPRO_DEV_BASE_URL; } else { - baseUrl = import.meta.env.SHOPRO_BASE_URL; + // 生产环境下,判断是体验版还是正式版 + const wxEnvVersion = getWxEnvVersion(); + + if (wxEnvVersion === 'trial') { + // 体验版使用体验版服务器地址 + baseUrl = import.meta.env.SHOPRO_TRIAL_BASE_URL || import.meta.env.SHOPRO_BASE_URL; + console.log('当前运行环境:体验版'); + } else if (wxEnvVersion === 'release') { + // 正式版使用生产服务器地址 + baseUrl = import.meta.env.SHOPRO_BASE_URL; + console.log('当前运行环境:正式版'); + } else { + // 其他平台或获取失败,使用默认地址 + baseUrl = import.meta.env.SHOPRO_BASE_URL; + } } if (typeof baseUrl === 'undefined') { console.error('请检查.env配置文件是否存在'); From be05df9d91af055e3c4d7bec94c17047e3b82301 Mon Sep 17 00:00:00 2001 From: zhangfengchen <1027307161@qq.com> Date: Tue, 26 May 2026 09:24:30 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E4=BD=93?= =?UTF-8?q?=E9=AA=8C=E7=89=88=E5=90=8E=E7=AB=AF=E6=8E=A5=E5=8F=A3=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E5=88=A4=E6=96=AD-=E6=96=B9=E6=B3=95=E6=8A=BD?= =?UTF-8?q?=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sheep/config/index.js | 13 +------------ sheep/helper/env.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 sheep/helper/env.js diff --git a/sheep/config/index.js b/sheep/config/index.js index 7767dac5..13a95db0 100644 --- a/sheep/config/index.js +++ b/sheep/config/index.js @@ -1,19 +1,8 @@ import packageInfo from '@/package.json'; +import { getWxEnvVersion } from '@/sheep/helper/env'; const { version } = packageInfo; -// 获取微信小程序运行环境 -function getWxEnvVersion() { - // #ifdef MP-WEIXIN - try { - const accountInfo = wx.getAccountInfoSync(); - return accountInfo.miniProgram.envVersion; // develop: 开发版, trial: 体验版, release: 正式版 - } catch (e) { - console.log('获取微信小程序环境失败', e); - return 'release'; - } - // #endif -} // 开发环境配置 export let baseUrl; diff --git a/sheep/helper/env.js b/sheep/helper/env.js new file mode 100644 index 00000000..6e53918a --- /dev/null +++ b/sheep/helper/env.js @@ -0,0 +1,21 @@ +/** + * 微信小程序运行环境:develop / trial / release + * 其它平台默认 release,整个 App 生命周期内不会变,缓存一次 + */ +let cachedEnvVersion; + +export function getWxEnvVersion() { + if (cachedEnvVersion) return cachedEnvVersion; + // #ifdef MP-WEIXIN + try { + cachedEnvVersion = wx.getAccountInfoSync().miniProgram.envVersion; + } catch (e) { + console.log('获取微信小程序环境失败', e); + cachedEnvVersion = 'release'; + } + // #endif + // #ifndef MP-WEIXIN + cachedEnvVersion = 'release'; + // #endif + return cachedEnvVersion; +} From 5ccddfa082faf4b261cd73b2a537850b9f1535c4 Mon Sep 17 00:00:00 2001 From: zhangfengchen <1027307161@qq.com> Date: Tue, 26 May 2026 09:43:57 +0800 Subject: [PATCH 4/4] =?UTF-8?q?docs:=20=E5=A2=9E=E5=8A=A0=E4=BD=93?= =?UTF-8?q?=E9=AA=8C=E7=89=88=E5=90=8E=E7=AB=AF=E6=8E=A5=E5=8F=A3=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sheep/config/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sheep/config/index.js b/sheep/config/index.js index 13a95db0..b00e4635 100644 --- a/sheep/config/index.js +++ b/sheep/config/index.js @@ -3,13 +3,12 @@ import { getWxEnvVersion } from '@/sheep/helper/env'; const { version } = packageInfo; - // 开发环境配置 export let baseUrl; if (process.env.NODE_ENV === 'development') { baseUrl = import.meta.env.SHOPRO_DEV_BASE_URL; } else { - // 生产环境下,判断是体验版还是正式版 + // 非本地 dev 模式开发环境,判断是体验版还是正式版 const wxEnvVersion = getWxEnvVersion(); if (wxEnvVersion === 'trial') {