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

@@ -20,20 +20,22 @@ try {
// 默认域名, 自定义发行时可以修改
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
// 确保域名以 '/' 结尾

View File

@@ -28,8 +28,6 @@
"UNI_PLATFORM": "h5"
},
"define": {
"H5_XCX_5G_QUICKAPP_COM": true,
"H5_PRODUCTION": true,
"PRODUCTION": true
}
},
@@ -39,8 +37,6 @@
"UNI_PLATFORM": "h5"
},
"define": {
"H5_XCX_AIGC_QUICKAPP_COM": true,
"H5_PRODUCTION": true,
"PRODUCTION": true
}
},
@@ -50,8 +46,6 @@
"UNI_PLATFORM": "h5"
},
"define": {
"H5_5G_AIGC_QUICKAPP_COM": true,
"H5_PRODUCTION": true,
"PRODUCTION": true
}
},
@@ -61,8 +55,6 @@
"UNI_PLATFORM": "h5"
},
"define": {
"H5_TEST_AIGC_QUICKAPP_COM": true,
"H5_PRODUCTION": true,
"PRODUCTION": true
}
}