Compare commits
6 Commits
50e5f82dca
...
86c87b2cc4
| Author | SHA1 | Date | |
|---|---|---|---|
| 86c87b2cc4 | |||
| 8720c43570 | |||
| 96746df7c9 | |||
| dfaed6188b | |||
| 5841d92d5f | |||
| 4503e487f1 |
29
client-configs.json
Normal file
29
client-configs.json
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"zhinian": {
|
||||||
|
"clientId": "2",
|
||||||
|
"appId": "wx5e79df5996572539",
|
||||||
|
"name": "智念",
|
||||||
|
"placeholder": "快告诉智念您在想什么~",
|
||||||
|
"loginDesc": "您好,欢迎来到智念科技",
|
||||||
|
"logo": "@/pages/login/images/dh.png",
|
||||||
|
"subLogo": "@/pages/login/images/dhwq.png"
|
||||||
|
},
|
||||||
|
"duohua": {
|
||||||
|
"clientId": "2",
|
||||||
|
"appId": "wx23f86d809ae80259",
|
||||||
|
"name": "朵花",
|
||||||
|
"placeholder": "快告诉朵朵您在想什么~",
|
||||||
|
"loginDesc": "您好,欢迎来到朵花温泉",
|
||||||
|
"logo": "@/pages/login/images/dh.png",
|
||||||
|
"subLogo": "@/pages/login/images/dhwq.png"
|
||||||
|
},
|
||||||
|
"tianmu": {
|
||||||
|
"clientId": "4",
|
||||||
|
"appId": "wx0be424e1d22065a9",
|
||||||
|
"name": "天沐",
|
||||||
|
"placeholder": "快告诉沐沐您在想什么~",
|
||||||
|
"loginDesc": "您好,欢迎来到天沐温泉",
|
||||||
|
"logo": "@/pages/login/images/tm.png",
|
||||||
|
"subLogo": "@/pages/login/images/wsmm.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -37,7 +37,8 @@
|
|||||||
"build:mp-xhs": "uni build -p mp-xhs",
|
"build:mp-xhs": "uni build -p mp-xhs",
|
||||||
"build:quickapp-webview": "uni build -p quickapp-webview",
|
"build:quickapp-webview": "uni build -p quickapp-webview",
|
||||||
"build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei",
|
"build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei",
|
||||||
"build:quickapp-webview-union": "uni build -p quickapp-webview-union"
|
"build:quickapp-webview-union": "uni build -p quickapp-webview-union",
|
||||||
|
"switch-client": "node scripts/update-appid.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@dcloudio/uni-app": "3.0.0-4070620250821001",
|
"@dcloudio/uni-app": "3.0.0-4070620250821001",
|
||||||
|
|||||||
@ -1,31 +1,31 @@
|
|||||||
{
|
{
|
||||||
"appid": "wx0be424e1d22065a9",
|
"appid": "wx0be424e1d22065a9",
|
||||||
"compileType": "miniprogram",
|
"compileType": "miniprogram",
|
||||||
"libVersion": "3.8.10",
|
"libVersion": "3.8.10",
|
||||||
"packOptions": {
|
"packOptions": {
|
||||||
"ignore": [],
|
"ignore": [],
|
||||||
"include": []
|
"include": []
|
||||||
},
|
},
|
||||||
"setting": {
|
"setting": {
|
||||||
"coverView": true,
|
"coverView": true,
|
||||||
"es6": true,
|
"es6": true,
|
||||||
"postcss": true,
|
"postcss": true,
|
||||||
"minified": true,
|
"minified": true,
|
||||||
"enhance": true,
|
"enhance": true,
|
||||||
"showShadowRootInWxmlPanel": true,
|
"showShadowRootInWxmlPanel": true,
|
||||||
"packNpmRelationList": [],
|
"packNpmRelationList": [],
|
||||||
"ignoreDevUnusedFiles": false,
|
"ignoreDevUnusedFiles": false,
|
||||||
"ignoreUploadUnusedFiles": false,
|
"ignoreUploadUnusedFiles": false,
|
||||||
"babelSetting": {
|
"babelSetting": {
|
||||||
"ignore": [],
|
"ignore": [],
|
||||||
"disablePlugins": [],
|
"disablePlugins": [],
|
||||||
"outputPath": ""
|
"outputPath": ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"condition": {},
|
"condition": {},
|
||||||
"editorSetting": {
|
"editorSetting": {
|
||||||
"tabIndent": "insertSpaces",
|
"tabIndent": "insertSpaces",
|
||||||
"tabSize": 2
|
"tabSize": 2
|
||||||
},
|
},
|
||||||
"projectArchitecture": "miniProgram"
|
"projectArchitecture": "miniProgram"
|
||||||
}
|
}
|
||||||
173
scripts/README-update-appid.md
Normal file
173
scripts/README-update-appid.md
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
# 客户端配置切换脚本使用说明
|
||||||
|
|
||||||
|
这个脚本用于在不同客户端配置之间快速切换,支持智念、朵花、天沐等多个客户端。
|
||||||
|
|
||||||
|
## 主要功能
|
||||||
|
|
||||||
|
- 支持通过客户端名称切换配置
|
||||||
|
- 自动更新相关配置文件
|
||||||
|
- 统一的JSON配置文件管理
|
||||||
|
- 完整的错误处理和验证
|
||||||
|
|
||||||
|
## 配置文件结构
|
||||||
|
|
||||||
|
配置文件位于项目根目录的 `client-configs.json`,包含所有客户端的完整配置信息。配置会通过 `src/constant/base.js` 文件导入和使用:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"zhinian": {
|
||||||
|
"clientId": "2",
|
||||||
|
"appId": "wx5e79df5996572539",
|
||||||
|
"name": "智念",
|
||||||
|
"placeholder": "快告诉智念您在想什么~",
|
||||||
|
"loginDesc": "您好,欢迎来到智念科技",
|
||||||
|
"logo": "@/pages/login/images/dh.png",
|
||||||
|
"subLogo": "@/pages/login/images/dhwq.png"
|
||||||
|
},
|
||||||
|
"duohua": {
|
||||||
|
"clientId": "2",
|
||||||
|
"appId": "wx23f86d809ae80259",
|
||||||
|
"name": "朵花",
|
||||||
|
"placeholder": "快告诉朵朵您在想什么~",
|
||||||
|
"loginDesc": "您好,欢迎来到朵花温泉",
|
||||||
|
"logo": "@/pages/login/images/dh.png",
|
||||||
|
"subLogo": "@/pages/login/images/dhwq.png"
|
||||||
|
},
|
||||||
|
"tianmu": {
|
||||||
|
"clientId": "4",
|
||||||
|
"appId": "wx0be424e1d22065a9",
|
||||||
|
"name": "天沐",
|
||||||
|
"placeholder": "快告诉沐沐您在想什么~",
|
||||||
|
"loginDesc": "您好,欢迎来到天沐温泉",
|
||||||
|
"logo": "@/pages/login/images/tm.png",
|
||||||
|
"subLogo": "@/pages/login/images/wsmm.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 支持的客户端
|
||||||
|
|
||||||
|
| 客户端名称 | 显示名称 | AppID |
|
||||||
|
| ---------- | -------- | ------------------ |
|
||||||
|
| `zhinian` | 智念 | wx5e79df5996572539 |
|
||||||
|
| `duohua` | 朵花 | wx23f86d809ae80259 |
|
||||||
|
| `tianmu` | 天沐 | wx0be424e1d22065a9 |
|
||||||
|
|
||||||
|
## 使用方法
|
||||||
|
|
||||||
|
### 使用客户端名称切换
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 切换到智念客户端
|
||||||
|
npm run switch-client zhinian
|
||||||
|
|
||||||
|
# 切换到朵花客户端
|
||||||
|
npm run switch-client duohua
|
||||||
|
|
||||||
|
# 切换到天沐客户端
|
||||||
|
npm run switch-client tianmu
|
||||||
|
```
|
||||||
|
|
||||||
|
### 直接运行脚本
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 使用客户端名称
|
||||||
|
node scripts/update-appid.js tianmu
|
||||||
|
```
|
||||||
|
|
||||||
|
## AppID 信息
|
||||||
|
|
||||||
|
微信小程序的 AppID 通常格式为:
|
||||||
|
|
||||||
|
- 以 `wx` 开头
|
||||||
|
- 后跟 16 位字符(数字和字母)
|
||||||
|
- 总长度 18 位
|
||||||
|
|
||||||
|
示例:`wx1234567890abcdef`
|
||||||
|
|
||||||
|
## 更新的文件
|
||||||
|
|
||||||
|
1. **src/manifest.json**
|
||||||
|
|
||||||
|
- 更新 `mp-weixin.appid` 字段
|
||||||
|
- 保持文件中的注释不变
|
||||||
|
|
||||||
|
2. **project.config.json**
|
||||||
|
|
||||||
|
- 更新根级别的 `appid` 字段
|
||||||
|
- 保持 JSON 格式化
|
||||||
|
|
||||||
|
3. **src/constant/base.js**
|
||||||
|
- 更新 `getCurrentConfig()` 函数返回的客户端配置
|
||||||
|
|
||||||
|
4. **client-configs.json**
|
||||||
|
- 统一的配置文件,所有客户端配置的单一数据源
|
||||||
|
|
||||||
|
## 执行结果示例
|
||||||
|
|
||||||
|
### 使用客户端名称切换:
|
||||||
|
|
||||||
|
```
|
||||||
|
🚀 开始更新配置...
|
||||||
|
🎯 检测到客户端配置: 天沐 (tianmu)
|
||||||
|
目标客户端: 天沐 (tianmu)
|
||||||
|
目标appid: wx0be424e1d22065a9
|
||||||
|
|
||||||
|
📝 正在更新 base.js...
|
||||||
|
✅ base.js 更新成功,切换到 天沐 配置
|
||||||
|
📝 正在更新 manifest.json...
|
||||||
|
✅ manifest.json 更新成功
|
||||||
|
📝 正在更新 project.config.json...
|
||||||
|
✅ project.config.json 更新成功
|
||||||
|
旧appid: wx5e79df5996572539
|
||||||
|
新appid: wx0be424e1d22065a9
|
||||||
|
|
||||||
|
🎉 所有文件更新完成!
|
||||||
|
💡 已切换到 天沐 客户端配置
|
||||||
|
💡 提示: 请检查文件内容确认更新正确
|
||||||
|
```
|
||||||
|
|
||||||
|
## 错误处理
|
||||||
|
|
||||||
|
脚本包含以下验证和错误处理:
|
||||||
|
|
||||||
|
- 检查必需参数是否提供
|
||||||
|
- 验证客户端名称是否有效
|
||||||
|
- 检查目标文件是否存在
|
||||||
|
- 捕获文件读写错误
|
||||||
|
- 智能跳过不需要的更新
|
||||||
|
|
||||||
|
## 注意事项
|
||||||
|
|
||||||
|
1. **配置同步**: 确保 `client-configs.json` 与 `src/constant/base.js` 中的基础配置保持同步
|
||||||
|
2. **测试建议**: 切换配置后建议先进行测试,确认功能正常
|
||||||
|
3. **备份建议**: 重要更新前建议备份相关配置文件
|
||||||
|
|
||||||
|
## 常见问题
|
||||||
|
|
||||||
|
**Q: 脚本提示文件不存在怎么办?**
|
||||||
|
A: 请确保在项目根目录执行脚本,并检查文件路径是否正确。
|
||||||
|
|
||||||
|
**Q: 脚本提示不支持的客户端名称怎么办?**
|
||||||
|
A: 请检查输入的客户端名称是否正确,支持的客户端名称有:zhinian、duohua、tianmu。
|
||||||
|
|
||||||
|
**Q: 如何恢复到之前的配置?**
|
||||||
|
A: 可以使用版本控制系统恢复,或者再次运行脚本切换到其他客户端配置。
|
||||||
|
|
||||||
|
**Q: 如何添加新的客户端配置?**
|
||||||
|
A: 在 `client-configs.json` 中添加新的客户端配置:
|
||||||
|
```json
|
||||||
|
"new_client": {
|
||||||
|
"clientId": "客户端ID",
|
||||||
|
"appId": "微信小程序AppID",
|
||||||
|
"name": "客户端显示名称",
|
||||||
|
"placeholder": "输入框占位符文本",
|
||||||
|
"loginDesc": "登录页面描述文本",
|
||||||
|
"logo": "@/pages/login/images/logo.png",
|
||||||
|
"subLogo": "@/pages/login/images/sublogo.png"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
`src/constant/base.js` 会自动读取并处理新配置,无需手动修改。
|
||||||
|
|
||||||
|
**Q: 脚本提示"读取配置文件失败"怎么办?**
|
||||||
|
A: 检查 `client-configs.json` 文件是否存在且格式正确。
|
||||||
220
scripts/update-appid.js
Executable file
220
scripts/update-appid.js
Executable file
@ -0,0 +1,220 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
const fs = require("fs");
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户端配置切换脚本
|
||||||
|
* 支持通过客户端名称来切换配置
|
||||||
|
*
|
||||||
|
* 使用方法:
|
||||||
|
* 1. node scripts/update-appid.js <client-name>
|
||||||
|
* 2. npm run switch-client <client-name>
|
||||||
|
*/
|
||||||
|
|
||||||
|
// 读取客户端配置文件
|
||||||
|
const configPath = path.join(__dirname, "../client-configs.json");
|
||||||
|
let CLIENT_CONFIGS;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const configContent = fs.readFileSync(configPath, "utf8");
|
||||||
|
CLIENT_CONFIGS = JSON.parse(configContent);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("❌ 读取配置文件失败:", error.message);
|
||||||
|
console.error(" 配置文件路径:", configPath);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取命令行参数
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
const input = args[0];
|
||||||
|
|
||||||
|
// 验证参数
|
||||||
|
if (!input) {
|
||||||
|
console.error("❌ 错误: 请提供客户端名称");
|
||||||
|
console.log("使用方法:");
|
||||||
|
console.log(" node scripts/update-appid.js <client-name>");
|
||||||
|
console.log(" npm run switch-client <client-name>");
|
||||||
|
console.log("");
|
||||||
|
console.log("支持的客户端名称:");
|
||||||
|
Object.keys(CLIENT_CONFIGS).forEach((key) => {
|
||||||
|
console.log(` ${key} - ${CLIENT_CONFIGS[key].name}`);
|
||||||
|
});
|
||||||
|
console.log("");
|
||||||
|
console.log("示例:");
|
||||||
|
console.log(" node scripts/update-appid.js tianmu");
|
||||||
|
console.log(" npm run switch-client tianmu");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 文件路径
|
||||||
|
const manifestPath = path.join(__dirname, "../src/manifest.json");
|
||||||
|
const projectConfigPath = path.join(__dirname, "../project.config.json");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新base.js中的getCurrentConfig函数
|
||||||
|
*/
|
||||||
|
function updateBaseJs(clientName) {
|
||||||
|
const basePath = path.join(__dirname, "../src/constant/base.js");
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log("📝 正在更新 base.js...");
|
||||||
|
let content = fs.readFileSync(basePath, "utf8");
|
||||||
|
|
||||||
|
// 查找getCurrentConfig函数并替换其中的CLIENT_CONFIGS引用
|
||||||
|
const regex =
|
||||||
|
/export const getCurrentConfig = \(\) => CLIENT_CONFIGS\.\w+;/;
|
||||||
|
const newExport = `export const getCurrentConfig = () => CLIENT_CONFIGS.${clientName};`;
|
||||||
|
|
||||||
|
if (regex.test(content)) {
|
||||||
|
content = content.replace(regex, newExport);
|
||||||
|
fs.writeFileSync(basePath, content, "utf8");
|
||||||
|
console.log(
|
||||||
|
`✅ base.js 更新成功,切换到 ${CLIENT_CONFIGS[clientName].name} 配置`
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
console.log("⚠️ base.js 中未找到getCurrentConfig函数,跳过更新");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("❌ 更新base.js失败:", error.message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新manifest.json中的appid
|
||||||
|
*/
|
||||||
|
function updateManifestJson(newAppId) {
|
||||||
|
try {
|
||||||
|
console.log("📝 正在更新 manifest.json...");
|
||||||
|
let content = fs.readFileSync(manifestPath, "utf8");
|
||||||
|
|
||||||
|
// 由于manifest.json包含注释,需要特殊处理
|
||||||
|
// 使用正则表达式替换mp-weixin中的appid
|
||||||
|
const regex = /"mp-weixin":\s*{[^}]*"appid":\s*"[^"]*"/;
|
||||||
|
|
||||||
|
if (regex.test(content)) {
|
||||||
|
content = content.replace(regex, (match) => {
|
||||||
|
return match.replace(/"appid":\s*"[^"]*"/, `"appid": "${newAppId}"`);
|
||||||
|
});
|
||||||
|
fs.writeFileSync(manifestPath, content, "utf8");
|
||||||
|
console.log("✅ manifest.json 更新成功");
|
||||||
|
} else {
|
||||||
|
console.log("ℹ️ manifest.json 中未找到mp-weixin配置,跳过更新");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("❌ 更新manifest.json失败:", error.message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新project.config.json中的appid
|
||||||
|
*/
|
||||||
|
function updateProjectConfigJson(newAppId) {
|
||||||
|
try {
|
||||||
|
console.log("📝 正在更新 project.config.json...");
|
||||||
|
const content = fs.readFileSync(projectConfigPath, "utf8");
|
||||||
|
const config = JSON.parse(content);
|
||||||
|
|
||||||
|
const oldAppId = config.appid;
|
||||||
|
if (config.appid !== newAppId) {
|
||||||
|
config.appid = newAppId;
|
||||||
|
fs.writeFileSync(
|
||||||
|
projectConfigPath,
|
||||||
|
JSON.stringify(config, null, 2),
|
||||||
|
"utf8"
|
||||||
|
);
|
||||||
|
console.log("✅ project.config.json 更新成功");
|
||||||
|
console.log(` 旧appid: ${oldAppId}`);
|
||||||
|
console.log(` 新appid: ${newAppId}`);
|
||||||
|
} else {
|
||||||
|
console.log("ℹ️ project.config.json 无需更新");
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("❌ 更新project.config.json失败:", error.message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证必要文件是否存在
|
||||||
|
*/
|
||||||
|
function validateFiles() {
|
||||||
|
const basePath = path.join(__dirname, "../src/constant/base.js");
|
||||||
|
const files = [
|
||||||
|
{ path: basePath, name: "base.js" },
|
||||||
|
{ path: manifestPath, name: "manifest.json" },
|
||||||
|
{ path: projectConfigPath, name: "project.config.json" },
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
if (!fs.existsSync(file.path)) {
|
||||||
|
console.error(`❌ 文件不存在: ${file.name}`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 主函数
|
||||||
|
*/
|
||||||
|
function main() {
|
||||||
|
console.log("🚀 开始更新配置...");
|
||||||
|
|
||||||
|
// 解析输入参数
|
||||||
|
let newAppId;
|
||||||
|
let clientName;
|
||||||
|
|
||||||
|
// 检查是否为有效的客户端名称
|
||||||
|
if (CLIENT_CONFIGS[input]) {
|
||||||
|
// 使用客户端名称
|
||||||
|
clientName = input;
|
||||||
|
newAppId = CLIENT_CONFIGS[input].appId;
|
||||||
|
console.log(
|
||||||
|
`🎯 检测到客户端配置: ${CLIENT_CONFIGS[input].name} (${clientName})`
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(
|
||||||
|
`目标客户端: ${CLIENT_CONFIGS[clientName].name} (${clientName})`
|
||||||
|
);
|
||||||
|
console.log(`目标appid: ${newAppId}\n`);
|
||||||
|
|
||||||
|
// 验证文件存在
|
||||||
|
if (!validateFiles()) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 更新文件
|
||||||
|
const baseSuccess = updateBaseJs(clientName);
|
||||||
|
const manifestSuccess = updateManifestJson(newAppId);
|
||||||
|
const projectConfigSuccess = updateProjectConfigJson(newAppId);
|
||||||
|
|
||||||
|
if (baseSuccess && manifestSuccess && projectConfigSuccess) {
|
||||||
|
console.log("\n🎉 所有文件更新完成!");
|
||||||
|
console.log(`💡 已切换到 ${CLIENT_CONFIGS[clientName].name} 客户端配置`);
|
||||||
|
console.log("💡 提示: 请检查文件内容确认更新正确");
|
||||||
|
} else {
|
||||||
|
console.log("\n❌ 部分文件更新失败,请检查错误信息");
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 不支持的客户端名称
|
||||||
|
console.error(`❌ 错误: 不支持的客户端名称 "${input}"`);
|
||||||
|
console.log("");
|
||||||
|
console.log("支持的客户端名称:");
|
||||||
|
Object.keys(CLIENT_CONFIGS).forEach((key) => {
|
||||||
|
console.log(` ${key} - ${CLIENT_CONFIGS[key].name}`);
|
||||||
|
});
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行主函数
|
||||||
|
main();
|
||||||
@ -3,39 +3,45 @@ import DHWQ from "@/pages/login/images/dhwq.png";
|
|||||||
import TM from "@/pages/login/images/tm.png";
|
import TM from "@/pages/login/images/tm.png";
|
||||||
import WSMM from "@/pages/login/images/wsmm.png";
|
import WSMM from "@/pages/login/images/wsmm.png";
|
||||||
|
|
||||||
// 小程序特有相关: 同时更改manifest.json和 project.config.json文件中的appid;
|
/**
|
||||||
// 所有用户端的配置
|
* 客户端配置管理模块
|
||||||
export const CLIENT_CONFIGS = {
|
*
|
||||||
// 智念用户端
|
* 功能说明:
|
||||||
zhinian: {
|
* 所有配置从根目录的 client-configs.json 文件中读取
|
||||||
clientId: "2",
|
* 图片通过映射函数将路径转换为实际导入的模块
|
||||||
appId: "wx5e79df5996572539",
|
*/
|
||||||
placeholder: "快告诉智念您在想什么~",
|
|
||||||
loginDesc: "您好,欢迎来到智念科技",
|
// 直接导入配置文件
|
||||||
logo: DH,
|
import rawConfigs from '../../client-configs.json' with { type: 'json' };
|
||||||
subLogo: DHWQ,
|
|
||||||
},
|
// 图片路径映射表
|
||||||
// 朵花用户端
|
const imageMap = {
|
||||||
duohua: {
|
'@/pages/login/images/dh.png': DH,
|
||||||
clientId: "2",
|
'@/pages/login/images/dhwq.png': DHWQ,
|
||||||
appId: "wx23f86d809ae80259",
|
'@/pages/login/images/tm.png': TM,
|
||||||
placeholder: "快告诉朵朵您在想什么~",
|
'@/pages/login/images/wsmm.png': WSMM,
|
||||||
loginDesc: "您好,欢迎来到朵花温泉",
|
|
||||||
logo: DH,
|
|
||||||
subLogo: DHWQ,
|
|
||||||
},
|
|
||||||
// 天沐用户端
|
|
||||||
tianmu: {
|
|
||||||
clientId: "4",
|
|
||||||
appId: "wx0be424e1d22065a9",
|
|
||||||
placeholder: "快告诉沐沐您在想什么~",
|
|
||||||
loginDesc: "您好,欢迎来到天沐温泉",
|
|
||||||
logo: TM,
|
|
||||||
subLogo: WSMM,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 处理配置中的图片路径
|
||||||
|
const processConfigs = (configs) => {
|
||||||
|
const processed = {};
|
||||||
|
for (const [key, config] of Object.entries(configs)) {
|
||||||
|
processed[key] = {
|
||||||
|
...config,
|
||||||
|
logo: imageMap[config.logo] || config.logo,
|
||||||
|
subLogo: imageMap[config.subLogo] || config.subLogo,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return processed;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 所有用户端的配置 - 处理后的配置
|
||||||
|
export const CLIENT_CONFIGS = processConfigs(rawConfigs);
|
||||||
|
|
||||||
// 获取当前用户端配置
|
// 获取当前用户端配置
|
||||||
export const getCurrentConfig = () => CLIENT_CONFIGS.tianmu;
|
export const getCurrentConfig = () => CLIENT_CONFIGS.tianmu;
|
||||||
export const clientId = getCurrentConfig().clientId;
|
export const clientId = getCurrentConfig().clientId;
|
||||||
export const appId = getCurrentConfig().appId;
|
export const appId = getCurrentConfig().appId;
|
||||||
|
|
||||||
|
// 环境配置 - 智念客户端使用测试环境,其他客户端使用生产环境
|
||||||
|
export const isProd = getCurrentConfig().name !== '智念';
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
// 登录成功
|
||||||
|
export const NOTICE_EVENT_LOGIN_SUCCESS = "NOTICE_EVENT_LOGIN_SUCCESS";
|
||||||
// 退出登录
|
// 退出登录
|
||||||
export const NOTICE_EVENT_LOGOUT = "NOTICE_EVENT_LOGOUT";
|
export const NOTICE_EVENT_LOGOUT = "NOTICE_EVENT_LOGOUT";
|
||||||
|
|
||||||
|
|||||||
@ -6,8 +6,13 @@ import {
|
|||||||
import { getWeChatAuthCode } from "./AuthManager";
|
import { getWeChatAuthCode } from "./AuthManager";
|
||||||
import { useAppStore } from "@/store";
|
import { useAppStore } from "@/store";
|
||||||
import { clientId } from "@/constant/base";
|
import { clientId } from "@/constant/base";
|
||||||
|
import { NOTICE_EVENT_LOGIN_SUCCESS } from "@/constant/constant";
|
||||||
|
|
||||||
const loginAuth = () => {
|
const loginAuth = () => {
|
||||||
|
uni.setStorageSync("token", "");
|
||||||
|
const appStore = useAppStore();
|
||||||
|
appStore.setHasToken(false);
|
||||||
|
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const openIdCode = await getWeChatAuthCode();
|
const openIdCode = await getWeChatAuthCode();
|
||||||
console.log("获取到的微信授权code:", openIdCode);
|
console.log("获取到的微信授权code:", openIdCode);
|
||||||
@ -25,6 +30,8 @@ const loginAuth = () => {
|
|||||||
uni.setStorageSync("token", response.access_token);
|
uni.setStorageSync("token", response.access_token);
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
appStore.setHasToken(true);
|
appStore.setHasToken(true);
|
||||||
|
// 登录成功后,触发登录成功事件
|
||||||
|
uni.$emit(NOTICE_EVENT_LOGIN_SUCCESS);
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
reject(response.message || "登录失败");
|
reject(response.message || "登录失败");
|
||||||
|
|||||||
@ -152,6 +152,7 @@ import {
|
|||||||
RECOMMEND_POSTS_TITLE,
|
RECOMMEND_POSTS_TITLE,
|
||||||
SEND_COMMAND_TEXT,
|
SEND_COMMAND_TEXT,
|
||||||
NOTICE_EVENT_LOGOUT,
|
NOTICE_EVENT_LOGOUT,
|
||||||
|
NOTICE_EVENT_LOGIN_SUCCESS,
|
||||||
} from "@/constant/constant";
|
} from "@/constant/constant";
|
||||||
import { WSS_URL } from "@/request/base/baseUrl";
|
import { WSS_URL } from "@/request/base/baseUrl";
|
||||||
import { MessageRole, MessageType, CompName } from "@/model/ChatModel";
|
import { MessageRole, MessageType, CompName } from "@/model/ChatModel";
|
||||||
@ -336,6 +337,12 @@ const sendMessageAction = (inputText) => {
|
|||||||
|
|
||||||
/// 添加通知
|
/// 添加通知
|
||||||
const addNoticeListener = () => {
|
const addNoticeListener = () => {
|
||||||
|
uni.$on(NOTICE_EVENT_LOGIN_SUCCESS, () => {
|
||||||
|
if (!webSocketConnectStatus) {
|
||||||
|
initHandler();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
uni.$on(NOTICE_EVENT_LOGOUT, () => {
|
uni.$on(NOTICE_EVENT_LOGOUT, () => {
|
||||||
resetConfig();
|
resetConfig();
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@ -381,27 +388,14 @@ const initHandler = () => {
|
|||||||
if (!appStore.hasToken) return;
|
if (!appStore.hasToken) return;
|
||||||
loadRecentConversation();
|
loadRecentConversation();
|
||||||
///loadConversationMsgList();
|
///loadConversationMsgList();
|
||||||
|
initTypewriterManager();
|
||||||
initWebSocket();
|
initWebSocket();
|
||||||
};
|
};
|
||||||
|
|
||||||
// 绑定成功,监听token变化,初始化
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => appStore.hasToken,
|
|
||||||
(newValue) => {
|
|
||||||
if (newValue) {
|
|
||||||
console.log("token存在,初始化数据");
|
|
||||||
initHandler();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
try {
|
try {
|
||||||
getMainPageData();
|
getMainPageData();
|
||||||
addNoticeListener();
|
addNoticeListener();
|
||||||
initTypewriterManager();
|
|
||||||
|
|
||||||
// 有token时,加载最近会话、最近消息、初始化socket
|
// 有token时,加载最近会话、最近消息、初始化socket
|
||||||
initHandler();
|
initHandler();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -772,6 +766,7 @@ const stopRequest = () => {
|
|||||||
|
|
||||||
// 组件销毁时清理资源
|
// 组件销毁时清理资源
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
|
uni.$off(NOTICE_EVENT_LOGIN_SUCCESS);
|
||||||
uni.$off(SCROLL_TO_BOTTOM);
|
uni.$off(SCROLL_TO_BOTTOM);
|
||||||
uni.$off(RECOMMEND_POSTS_TITLE);
|
uni.$off(RECOMMEND_POSTS_TITLE);
|
||||||
uni.$off(SEND_COMMAND_TEXT);
|
uni.$off(SEND_COMMAND_TEXT);
|
||||||
@ -785,6 +780,7 @@ const resetConfig = () => {
|
|||||||
if (webSocketManager) {
|
if (webSocketManager) {
|
||||||
webSocketManager.destroy();
|
webSocketManager.destroy();
|
||||||
webSocketManager = null;
|
webSocketManager = null;
|
||||||
|
webSocketConnectStatus = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清理打字机管理器
|
// 清理打字机管理器
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
const isProd = true;
|
import { isProd } from '@/constant/base.js';
|
||||||
|
|
||||||
// 测试
|
// 测试
|
||||||
const VITE_BASE_URL_TEST = "https://onefeel.brother7.cn/ingress";
|
const VITE_BASE_URL_TEST = "https://onefeel.brother7.cn/ingress";
|
||||||
@ -8,7 +8,7 @@ const VITE_WSS_URL_TEST = "wss://onefeel.brother7.cn/ingress/agent/ws/chat";
|
|||||||
const VITE_BASE_URL_PRO = "https://biz.nianxx.cn";
|
const VITE_BASE_URL_PRO = "https://biz.nianxx.cn";
|
||||||
const VITE_WSS_URL_PRO = "wss://biz.nianxx.cn/agent/ws/chat";
|
const VITE_WSS_URL_PRO = "wss://biz.nianxx.cn/agent/ws/chat";
|
||||||
|
|
||||||
// 环境配置
|
// 环境配置 - 根据客户端配置动态决定环境
|
||||||
export const BASE_URL = isProd ? VITE_BASE_URL_PRO : VITE_BASE_URL_TEST;
|
export const BASE_URL = isProd ? VITE_BASE_URL_PRO : VITE_BASE_URL_TEST;
|
||||||
export const WSS_URL = isProd ? VITE_WSS_URL_PRO : VITE_WSS_URL_TEST;
|
export const WSS_URL = isProd ? VITE_WSS_URL_PRO : VITE_WSS_URL_TEST;
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import { goLogin } from "../../hooks/useGoLogin";
|
import { goLogin } from "../../hooks/useGoLogin";
|
||||||
import { BASE_URL } from "./baseUrl";
|
import { BASE_URL } from "./baseUrl";
|
||||||
import { getCurrentConfig } from "@/constant/base";
|
import { getCurrentConfig } from "@/constant/base";
|
||||||
|
import { useAppStore } from "@/store";
|
||||||
|
import { NOTICE_EVENT_LOGOUT } from "@/constant/constant";
|
||||||
|
|
||||||
const clientId = getCurrentConfig().clientId;
|
const clientId = getCurrentConfig().clientId;
|
||||||
const defaultConfig = {
|
const defaultConfig = {
|
||||||
@ -55,6 +57,10 @@ function request(url, args = {}, method = "POST", customConfig = {}) {
|
|||||||
resolve(res.data);
|
resolve(res.data);
|
||||||
if (res.statusCode && res.statusCode === 424) {
|
if (res.statusCode && res.statusCode === 424) {
|
||||||
console.log("424错误,重新登录");
|
console.log("424错误,重新登录");
|
||||||
|
uni.setStorageSync("token", "");
|
||||||
|
const appStore = useAppStore();
|
||||||
|
appStore.setHasToken(false);
|
||||||
|
uni.$emit(NOTICE_EVENT_LOGOUT);
|
||||||
goLogin();
|
goLogin();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user