diff --git a/.local.config.js b/.local.config.js index 1902e69..4d86284 100644 --- a/.local.config.js +++ b/.local.config.js @@ -62,5 +62,5 @@ const localDevConfig = ({ uniacid: 2075, domain: 'https://xcx.aigc-quickapp.com/', }, -})['2811']; // 选择要使用的环境配置 +})['1']; // 选择要使用的环境配置 export default localDevConfig; \ No newline at end of file diff --git a/common/js/ai-service.js b/common/js/ai-service.js index 9bda135..14923fe 100644 --- a/common/js/ai-service.js +++ b/common/js/ai-service.js @@ -68,7 +68,7 @@ export default { } return result; } catch (error) { - console.error('[AI Service] Dify API请求失败,详细错误:', error); + console.error('[AI Service] AiChat API请求失败,详细错误:', error); console.error('[AI Service] 错误堆栈:', error.stack); // 打印更多信息帮助调试 console.error('[AI Service] store 状态:', { @@ -88,6 +88,16 @@ export default { return new Promise((resolve, reject) => { const match = Config.baseUrl.match(/^(?:https?:\/\/|wss?:\/\/)([^\/\s:]+)/); const domain = match ? match[1] : ''; + + // 修复 5:Domain 提取失败时提前拒绝 + if (!domain) { + const errorMsg = 'WebSocket 域名配置无效'; + console.error(errorMsg); + reject(new Error(errorMsg)); + if (onComplete) onComplete({ error: errorMsg }); + return; + } + const wssUrl = `wss://${domain}/ws/aikefu`; const socketTask = wx.connectSocket({ url: wssUrl, @@ -97,6 +107,29 @@ export default { let content = ''; let conversationId = ''; let isAuthenticated = false; + let closedNormally = false; + let settled = false; + + // 安全地拒绝(防止重复调用) + function safeReject(error) { + if (settled) return; + settled = true; + clearTimeout(timeout); + reject(error); + } + + // 安全地完成 + function safeResolve(result) { + if (settled) return; + settled = true; + clearTimeout(timeout); + resolve(result); + } + + // 安全地触发 onComplete + function safeComplete(result) { + if (onComplete) onComplete(result); + } socketTask.onOpen(() => { socketTask.send({ @@ -128,8 +161,8 @@ export default { } else if (data.type === 'auth_failed') { const errorMsg = '认证失败,请重新登录'; console.error(errorMsg, data); - reject(new Error(errorMsg)); - if (onComplete) onComplete({ error: errorMsg }); + safeComplete({ error: errorMsg }); + safeReject(new Error(errorMsg)); socketTask.close(); } @@ -146,10 +179,9 @@ export default { if (conversationId) { this.setConversationId(conversationId); } - if (onComplete) { - onComplete({ content, conversation_id: conversationId }); - } - resolve({ content, conversation_id: conversationId }); + closedNormally = true; + safeComplete({ content, conversation_id: conversationId }); + safeResolve({ content, conversation_id: conversationId }); socketTask.close(); } @@ -165,21 +197,19 @@ export default { socketTask.onError((err) => { const errorMsg = 'WebSocket 连接失败'; console.error(errorMsg, err); - reject(new Error(errorMsg)); - if (onComplete) onComplete({ error: errorMsg }); + safeComplete({ error: errorMsg }); + safeReject(new Error(errorMsg)); }); socketTask.onClose(() => { + if (!closedNormally && !settled) { + const errorMsg = 'WebSocket 连接意外关闭'; + console.error(errorMsg); + safeComplete({ error: errorMsg }); + safeReject(new Error(errorMsg)); + } }); - const timeout = setTimeout(() => { - if (!isAuthenticated || content === '') { - console.warn('WebSocket 超时,强制关闭'); - socketTask.close(); - reject(new Error('AI服务响应超时')); - if (onComplete) onComplete({ error: 'AI服务响应超时' }); - } - }, 10000); }); // #endif }, diff --git a/common/js/config.js b/common/js/config.js index 2c7e3e1..89ec42c 100644 --- a/common/js/config.js +++ b/common/js/config.js @@ -21,9 +21,9 @@ try { let defaultDomain = ''; // #ifdef H5 -// 域名由 package.json 中对应脚本的 env.UNI_APP_DOMAIN 传入 +// 域名由 vue.config.js 中 DefinePlugin 注入的 process.env.UNI_APP_DOMAIN 传入 try { - if (process?.env?.UNI_APP_DOMAIN) { + if (process.env.UNI_APP_DOMAIN) { defaultDomain = process.env.UNI_APP_DOMAIN; } } catch (e) {} diff --git a/common/js/customer-service.js b/common/js/customer-service.js index 288770f..5edbbd1 100644 --- a/common/js/customer-service.js +++ b/common/js/customer-service.js @@ -119,9 +119,9 @@ export class CustomerService { } /** - * 跳转到 AI 客服页面(Dify) + * 跳转到 AI智能客服页面(AiChat) */ - openDifyService() { + openAiChatService() { try { // 清除未读数(如果存在) if (typeof this.vm.setAiUnreadCount === 'function') { @@ -135,7 +135,7 @@ export class CustomerService { uni.navigateTo({ url: aiChatUrl, fail: (err) => { - console.error('跳转 AI 客服失败:', err); + console.error('跳转 AI智能客服失败:', err); // H5 兜底 // #ifdef H5 window.location.href = aiChatUrl; @@ -144,7 +144,7 @@ export class CustomerService { } }); } catch (e) { - console.error('跳转 AI 客服异常:', e); + console.error('跳转 AI智能客服异常:', e); uni.showToast({ title: '打开客服失败', icon: 'none' }); } } @@ -177,7 +177,7 @@ export class CustomerService { // 核心路由:根据 type 决定行为 switch (config.type) { case 'aikefu': - this.openDifyService(); + this.openAiChatService(); break; case 'wxwork': this.openWxworkService(false, config, options); @@ -364,7 +364,7 @@ export class CustomerService { openAliappService(config) { if (config.type === 'aikefu') { - this.openDifyService(); + this.openAiChatService(); } else if (config.type === 'third') { this.openThirdService(config); } else { @@ -565,7 +565,7 @@ export class CustomerService { uni.navigateTo({ url: aiChatUrl, fail: (err) => { - console.error('跳转 AI 客服失败:', err); + console.error('跳转 AI智能客服失败:', err); // #ifdef H5 window.location.href = aiChatUrl; // #endif @@ -573,7 +573,7 @@ export class CustomerService { } }); } catch (e) { - console.error('跳转 AI 客服异常:', e); + console.error('跳转 AI智能客服异常:', e); uni.showToast({ title: '打开客服失败', icon: 'none' }); } } diff --git a/components-diy/diy-fenxiao-goods-list.vue b/components-diy/diy-fenxiao-goods-list.vue index aab5fd8..08ecc1b 100644 --- a/components-diy/diy-fenxiao-goods-list.vue +++ b/components-diy/diy-fenxiao-goods-list.vue @@ -337,7 +337,7 @@ export default { width: calc(50% - 10rpx); &:nth-child(2n + 2) { - width: calc(50% - 11rpx); + width: calc(50% - 10rpx); margin-right: 0; } diff --git a/components-diy/diy-goods-list.vue b/components-diy/diy-goods-list.vue index 140a28c..61ea2d1 100644 --- a/components-diy/diy-goods-list.vue +++ b/components-diy/diy-goods-list.vue @@ -1018,10 +1018,6 @@ export default { width: calc(33.3333333% - 14rpx); box-sizing: border-box; - &:nth-child(3n + 3) { - width: calc(33.33% - 15rpx); - } - &:nth-of-type(1), &:nth-of-type(2), &:nth-of-type(3) { diff --git a/components-diy/diy-rubik-cube.vue b/components-diy/diy-rubik-cube.vue index 77646ac..923f8b6 100644 --- a/components-diy/diy-rubik-cube.vue +++ b/components-diy/diy-rubik-cube.vue @@ -19,7 +19,7 @@