refactor: 用 UNI_SCRIPT + DOMAIN_MAP 替代 #ifdef 环境常量

This commit is contained in:
2026-05-11 10:27:33 +08:00
parent 79202c4542
commit 55c1e80ed7
2 changed files with 16 additions and 22 deletions

View File

@@ -18,22 +18,24 @@ try {
// 线上版本部署域名, 注意: 必须以 '/' 结尾,适用于小程序/H5/快应用等场景
// 默认域名, 自定义发行时可以修改
let defaultDomain = '';
let defaultDomain = '';
// #ifdef H5_XCX_5G_QUICKAPP_COM
defaultDomain = 'https://xcx20.5g-quickapp.com';
// #endif
// 各自定义发行脚本对应的域名映射
// 利用 UNI_SCRIPT 环境变量(由运行的自定义脚本名称自动设置)来查找
const DOMAIN_MAP = {
'h5-xcx20.5g-quickapp.com': 'https://xcx20.5g-quickapp.com/',
'h5-xcx.aigc-quickapp.com': 'https://xcx.aigc-quickapp.com/',
'h5-5g.aigc-quickapp.com': 'https://5g.aigc-quickapp.com/',
'h5-test.aigc-quickapp.com':'https://test.aigc-quickapp.com/',
};
// #ifdef H5_XCX_AIGC_QUICKAPP_COM
defaultDomain = 'https://xcx.aigc-quickapp.com/';
// #endif
// #ifdef H5_5G_AIGC_QUICKAPP_COM
defaultDomain = 'https://5g.aigc-quickapp.com/';
// #endif
// #ifdef H5_TEST_AIGC_QUICKAPP_COM
defaultDomain = 'https://test.aigc-quickapp.com/';
// #ifdef H5
try {
const scriptName = process?.env?.UNI_SCRIPT;
if (scriptName && DOMAIN_MAP[scriptName]) {
defaultDomain = DOMAIN_MAP[scriptName];
}
} catch (e) {}
// #endif
// 确保域名以 '/' 结尾