chore(config): 支持从本地文件中获取.loacl.config.js 获取

This commit is contained in:
2025-12-25 09:56:29 +08:00
parent 7d00f9d0f8
commit 01b620fcb3
2 changed files with 43 additions and 19 deletions

23
.local.config.js.example Normal file
View File

@@ -0,0 +1,23 @@
// 本地调试配置示例文件
// 复制此文件并重命名为 local.config.js 以使用自定义本地配置
const localDevConfig = ({
'460': { // 制氧设备平台
uniacid: 460,
domain: 'https://xcx30.5g-quickapp.com/',
},
'2285': { // 数码喷墨墨水
uniacid: 2285,
domain: 'https://xcx.aigc-quickapp.com/',
},
'1': { // 开发平台
uniacid: 1,
domain: 'https://dev.aigc-quickapp.com',
},
'1-test': { // 测试平台
uniacid: 1,
domain: 'https://test.aigc-quickapp.com',
},
})['2285']; // 选择要使用的环境配置
export default localDevConfig;

View File

@@ -17,28 +17,29 @@ try {
// #endif // #endif
// 线上版本部署域名, 注意: 必须以 '/' 结尾,适用于小程序/H5/快应用等场景 // 线上版本部署域名, 注意: 必须以 '/' 结尾,适用于小程序/H5/快应用等场景
let defaultDomain = 'https://5g.aigc-quickapp.com/'; // 部署H5站点时需要配置为当前站点域名 // const defaultDomain = 'https://5g.aigc-quickapp.com/'; // 部署H5站点时需要配置为当前站点域名
// #ifdef H5 const defaultDomain = 'https://xcx.aigc-quickapp.com/'; // 部署H5站点时需要配置为当前站点域名
defaultDomain = window.location.origin + '/';
// #endif
// 本地调试配置, 不同环境的配置 let localDevConfig = { uniacid: 0, domain: defaultDomain };
const localDevConfig = ({
'460': { // 制氧设备平台 // 尝试动态加载本地配置文件
uniacid: 460, // 注意:在发行模式下,.local.config.js 不会被打包,因此会自动使用默认配置
domain: 'https://xcx30.5g-quickapp.com/', try {
}, // 尝试从项目根目录加载本地配置文件
'2285': { // 数码喷墨墨水 // 使用相对路径的方式,确保在不同平台下都能正确解析
uniacid: 2285, let customConfig = require('@/.local.config.js').default;
domain: 'https://xcx.aigc-quickapp.com/', if (customConfig) {
}, localDevConfig = customConfig;
'1': { // 测试平台
uniacid: 1,
domain: 'https://dev.aigc-quickapp.com',
} }
})['2285']; } catch (e) {
// 如果本地配置文件不存在或加载失败,保持使用默认配置
// 只在开发模式下输出提示信息
// #ifndef APP-PLUS || MP-WEIXIN || MP-ALIPAY || MP-BAIDU || MP-QQ || MP-TOUTIAO
console.log('本地配置文件 .local.config.js 不存在,使用默认配置');
// #endif
}
const { uniacid, domain } = localDevConfig ?? { uniacid: 0, domain: defaultDomain } const { uniacid = 0, domain = defaultDomain } = localDevConfig ?? { uniacid: 0, domain: defaultDomain }
// 调试版本,配置说明 // 调试版本,配置说明
const devCfg = { const devCfg = {