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 小程序跳转方法二次封装