From d2f1c1364068e4b89b8f88dce373975fbb8d0db4 Mon Sep 17 00:00:00 2001 From: lj7788 Date: Mon, 15 Dec 2025 15:32:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=88=87=E6=8D=A2=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yanzhu-ui-app/README.md | 17 +- yanzhu-ui-app/miniprogram/config.js | 10 +- yanzhu-ui-app/miniprogram/project.config.json | 2 +- yanzhu-ui-app/miniprogram/utils/config.wxs | 2 +- yanzhu-ui-app/package.json | 16 ++ yanzhu-ui-app/switchEnv.js | 180 ++++++++++++++++++ 6 files changed, 218 insertions(+), 9 deletions(-) create mode 100644 yanzhu-ui-app/package.json create mode 100644 yanzhu-ui-app/switchEnv.js diff --git a/yanzhu-ui-app/README.md b/yanzhu-ui-app/README.md index 27528247..83010a95 100644 --- a/yanzhu-ui-app/README.md +++ b/yanzhu-ui-app/README.md @@ -39,5 +39,18 @@ - [[智慧农业认养系统]](https://gitee.com/tony2y/smart-breed):基于Java + SpringBoot + Mybatis Plus + Redis + Vue + antdv,支持认养、商城、营销、会员、进销存、多租户等功能,包含小程序,系统管理后台。 - [[智慧景区管理系统]](https://gitee.com/tony2y/scenic-spot):基于Java + SpringBoot + Mybatis Plus + Redis + Vue + antdv,支持景区管理、售票、地块管理、认养、商城、农资管理、积分兑换等功能,包含小程序,系统管理后台。 -数字项管:wx46466c7828eede2b -筑安施工:wx007a8fd50dc185b2 +写一个切换环境的 js,根据不同的环境修改 config.js,config.wxs 和 project.config.json 文件中的配置项 + +数字项管(A): +appid:wx46466c7828eede2b +baseUrl:https://xiangguan.sxyanzhu.com/wechat +baseImgUrl:https://xiangguan.sxyanzhu.com + +筑安施工(B): +appid:wx007a8fd50dc185b2 +baseUrl:https://jaszpt.crfeb.com.cn/wechat +baseImgUrl:https://jaszpt.crfeb.com.cn + +注意修改图片路径要修改两个文件 +config.js +config.wxs diff --git a/yanzhu-ui-app/miniprogram/config.js b/yanzhu-ui-app/miniprogram/config.js index e3b3ac1e..5f302c9c 100644 --- a/yanzhu-ui-app/miniprogram/config.js +++ b/yanzhu-ui-app/miniprogram/config.js @@ -1,12 +1,12 @@ // 应用全局配置 module.exports = { timeout: 60000, - appId: "wx007a8fd50dc185b2", - //baseUrl: "https://xiangguan.sxyanzhu.com/wechat", - baseUrl: "https://jaszpt.crfeb.com.cn/wechat", + appId: "wx46466c7828eede2b", + baseUrl: "https://xiangguan.sxyanzhu.com/wechat", + ////baseUrl: "https://jaszpt.crfeb.com.cn/wechat", //baseUrl: "http://127.0.0.1:8080", - //baseImgUrl: "https://xiangguan.sxyanzhu.com", - baseImgUrl: "https://jaszpt.crfeb.com.cn", + baseImgUrl: "https://xiangguan.sxyanzhu.com", + ////baseImgUrl: "https://jaszpt.crfeb.com.cn", //baseImgUrl: 'http://127.0.0.1:9300', noSecuritys: [ "/code", diff --git a/yanzhu-ui-app/miniprogram/project.config.json b/yanzhu-ui-app/miniprogram/project.config.json index 8201a339..bed0f59f 100644 --- a/yanzhu-ui-app/miniprogram/project.config.json +++ b/yanzhu-ui-app/miniprogram/project.config.json @@ -1,5 +1,5 @@ { - "appid": "wx007a8fd50dc185b2", + "appid": "wx46466c7828eede2b", "compileType": "miniprogram", "libVersion": "3.8.9", "packOptions": { diff --git a/yanzhu-ui-app/miniprogram/utils/config.wxs b/yanzhu-ui-app/miniprogram/utils/config.wxs index 2174d135..1e63391b 100644 --- a/yanzhu-ui-app/miniprogram/utils/config.wxs +++ b/yanzhu-ui-app/miniprogram/utils/config.wxs @@ -1,7 +1,7 @@ // WXS 配置文件 var config = { // 与 config.js 中的 baseImgUrl 保持同步 - baseImgUrl: "https://jaszpt.crfeb.com.cn", + baseImgUrl: "https://xiangguan.sxyanzhu.com", }; module.exports = config; diff --git a/yanzhu-ui-app/package.json b/yanzhu-ui-app/package.json new file mode 100644 index 00000000..d36e08ec --- /dev/null +++ b/yanzhu-ui-app/package.json @@ -0,0 +1,16 @@ +{ + "name": "yanzhu-ui-app", + "version": "1.0.0", + "description": "研筑-临时工程项目管理App", + "scripts": { + "switch": "node switchEnv.js" + }, + "keywords": [ + "微信小程序", + "工程项目管理", + "Flowable", + "RuoYi" + ], + "author": "研筑团队", + "license": "MIT" +} \ No newline at end of file diff --git a/yanzhu-ui-app/switchEnv.js b/yanzhu-ui-app/switchEnv.js new file mode 100644 index 00000000..fee1903e --- /dev/null +++ b/yanzhu-ui-app/switchEnv.js @@ -0,0 +1,180 @@ +const fs = require("fs"); +const path = require("path"); + +// 环境配置 +const envConfigs = { + A: { + name: "数字项管", + displayName: "A (数字项管)", + appId: "wx46466c7828eede2b", + baseUrl: "https://xiangguan.sxyanzhu.com/wechat", + baseImgUrl: "https://xiangguan.sxyanzhu.com", + }, + B: { + name: "筑安施工", + displayName: "B (筑安施工)", + appId: "wx007a8fd50dc185b2", + baseUrl: "https://jaszpt.crfeb.com.cn/wechat", + baseImgUrl: "https://jaszpt.crfeb.com.cn", + }, +}; + +// 文件路径 +const configJsPath = path.join(__dirname, "miniprogram", "config.js"); +const configWxsPath = path.join( + __dirname, + "miniprogram", + "utils", + "config.wxs" +); +const projectConfigPath = path.join( + __dirname, + "miniprogram", + "project.config.json" +); + +// 更新 config.js +function updateConfigJs(env) { + let content = fs.readFileSync(configJsPath, "utf8"); + + // 更新 appId + content = content.replace(/appId:\s*"[^"]*"/, `appId: "${env.appId}"`); + + // 更新 baseUrl (取消注释目标环境,注释其他环境) + if (env.name === "数字项管") { + // 启用数字项管,注释其他 + content = content.replace( + /\/\/baseUrl:\s*"https:\/\/xiangguan\.sxyanzhu\.com\/wechat"/, + `baseUrl: "${env.baseUrl}"` + ); + content = content.replace( + /baseUrl:\s*"https:\/\/jaszpt\.crfeb\.com\.cn\/wechat"/, + `//baseUrl: "https://jaszpt.crfeb.com.cn/wechat"` + ); + content = content.replace( + /\/\/baseUrl:\s*"http:\/\/127\.0\.0\.1:8080"/, + `//baseUrl: "http://127.0.0.1:8080"` + ); + } else { + // 启用筑安施工,注释其他 + content = content.replace( + /\/\/baseUrl:\s*"https:\/\/jaszpt\.crfeb\.com\.cn\/wechat"/, + `baseUrl: "${env.baseUrl}"` + ); + content = content.replace( + /baseUrl:\s*"https:\/\/xiangguan\.sxyanzhu\.com\/wechat"/, + `//baseUrl: "https://xiangguan.sxyanzhu.com/wechat"` + ); + content = content.replace( + /\/\/baseUrl:\s*"http:\/\/127\.0\.0\.1:8080"/, + `//baseUrl: "http://127.0.0.1:8080"` + ); + } + + // 更新 baseImgUrl (取消注释目标环境,注释其他) + if (env.name === "数字项管") { + // 启用数字项管,注释其他 + content = content.replace( + /\/\/baseImgUrl:\s*"https:\/\/xiangguan\.sxyanzhu\.com"/, + `baseImgUrl: "${env.baseImgUrl}"` + ); + content = content.replace( + /baseImgUrl:\s*"https:\/\/jaszpt\.crfeb\.com\.cn"/, + `//baseImgUrl: "https://jaszpt.crfeb.com.cn"` + ); + content = content.replace( + /\/\/baseImgUrl:\s*'http:\/\/127\.0\.0\.1:9300'/, + `//baseImgUrl: 'http://127.0.0.1:9300'` + ); + } else { + // 启用筑安施工,注释其他 + content = content.replace( + /\/\/baseImgUrl:\s*"https:\/\/jaszpt\.crfeb\.com\.cn"/, + `baseImgUrl: "${env.baseImgUrl}"` + ); + content = content.replace( + /baseImgUrl:\s*"https:\/\/xiangguan\.sxyanzhu\.com"/, + `//baseImgUrl: "https://xiangguan.sxyanzhu.com"` + ); + content = content.replace( + /\/\/baseImgUrl:\s*'http:\/\/127\.0\.0\.1:9300'/, + `//baseImgUrl: 'http://127.0.0.1:9300'` + ); + } + + fs.writeFileSync(configJsPath, content, "utf8"); + console.log(`✅ 已更新 config.js 为 ${env.name} 环境`); +} + +// 更新 config.wxs +function updateConfigWxs(env) { + let content = fs.readFileSync(configWxsPath, "utf8"); + + // 更新 baseImgUrl + content = content.replace( + /baseImgUrl:\s*"[^"]*"/, + `baseImgUrl: "${env.baseImgUrl}"` + ); + + fs.writeFileSync(configWxsPath, content, "utf8"); + console.log(`✅ 已更新 config.wxs 为 ${env.name} 环境`); +} + +// 更新 project.config.json +function updateProjectConfig(env) { + const content = fs.readFileSync(projectConfigPath, "utf8"); + const config = JSON.parse(content); + + // 更新 appId + config.appid = env.appId; + + fs.writeFileSync(projectConfigPath, JSON.stringify(config, null, 4), "utf8"); + console.log(`✅ 已更新 project.config.json 为 ${env.name} 环境`); +} + +// 主函数 +function main() { + const args = process.argv.slice(2); + let envName = args[0]; + + // 如果没有传参数,提示用户选择 + if (!envName) { + console.log("🔧 当前支持的环境:"); + console.log(" A - 数字项管"); + console.log(" B - 筑安施工"); + console.log("\n💡 使用方法: node switchEnv.js <环境标识>"); + console.log(" 例如: node switchEnv.js A"); + return; + } + + // 匹配环境 + let selectedEnv = null; + for (const [key, env] of Object.entries(envConfigs)) { + if (key.includes(envName) || env.name.includes(envName)) { + selectedEnv = env; + break; + } + } + + if (!selectedEnv) { + console.error(`❌ 未找到环境: ${envName}`); + console.log("🔧 支持的环境:"); + Object.entries(envConfigs).forEach(([key, env]) => { + console.log(` ${key} - ${env.name}`); + }); + return; + } + + console.log(`🔄 正在切换到 ${selectedEnv.displayName} 环境...`); + + try { + updateConfigJs(selectedEnv); + updateConfigWxs(selectedEnv); + updateProjectConfig(selectedEnv); + console.log(`\n🎉 环境切换成功!当前环境: ${selectedEnv.displayName}`); + } catch (error) { + console.error(`❌ 环境切换失败: ${error.message}`); + } +} + +main();