fix(ai-service): WebSocket长连接重构 + 环境隔离 + this上下文修复

- 改为长连接模式:首次建立WebSocket后保持不断开,后续复用
- 添加 #ifdef MP-WEIXIN / #ifdef H5 环境隔离
- 修复 ensureWebSocketConnected 中 .bind(this) 导致 this 为 undefined 的问题
- 组件 onUnload 中调用 disconnectWebSocket() 断开连接
This commit is contained in:
2026-05-14 17:04:28 +08:00
parent 6de74a3baf
commit fed3962965
2 changed files with 208 additions and 124 deletions

View File

@@ -596,6 +596,10 @@ export default {
this.scrollToBottom()
})
},
onUnload() {
// 页面销毁时断开 WebSocket 长连接
aiService.disconnectWebSocket();
},
watch: {
messages: {
handler(newVal, oldVal) {