From 7dcc220b17294e6b8c390afa8951472d473d7bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=AF=85?= <1335909236@qq.com> Date: Thu, 18 Sep 2025 15:39:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=8E=AF=E5=A2=83=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E8=B0=83=E7=94=A8=E7=9A=84=E6=8E=A5=E5=8F=A3=E5=9C=B0?= =?UTF-8?q?=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/index.js | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/utils/index.js b/utils/index.js index af6afc01..62c381f0 100644 --- a/utils/index.js +++ b/utils/index.js @@ -1,6 +1,37 @@ -// const RequsetUrl = 'https://huishang.magicany.cc/api/v1'; // 请求地址前缀 -const RequsetUrl = 'https://test.hshuishang.com'; // 请求地址前缀 -export const picUrl = 'https://test.hshuishang.com'; // 图片地址前缀 +// 环境配置 +const environments = { + development: { + apiUrl: 'https://test.hshuishang.com', + picUrl: 'https://test.hshuishang.com' + }, + production: { + apiUrl: 'https://huishang.magicany.cc/api/v1', + picUrl: 'https://huishang.magicany.cc/api/v1' + } +}; + +// 判断当前环境 +const getCurrentEnvironment = () => { + // 优先通过NODE_ENV判断 + if (process && process.env && process.env.NODE_ENV) { + return process.env.NODE_ENV; + } + + // 通过全局配置判断(例如Vercel等平台的环境变量) + if (typeof global !== 'undefined' && global.env) { + return global.env; + } + + // 默认返回开发环境 + return 'development'; +}; + +// 获取当前环境配置 +const currentEnv = getCurrentEnvironment(); +const envConfig = environments[currentEnv] || environments.development; + +export const RequsetUrl = envConfig.apiUrl; // 请求地址前缀 +export const picUrl = envConfig.picUrl; // 图片地址前缀 /** * @description 小程序跳转方法二次封装