This commit is contained in:
lik
2026-10-07 15:51:42 +08:00
parent f0adf77a41
commit 136b3111cf
+13 -11
View File
@@ -195,21 +195,23 @@ Page({
const user = app.globalData.user const user = app.globalData.user
const socket = app.globalData.chatSocket const socket = app.globalData.chatSocket
// 先判空再判连接状态,避免 socket 不存在时读取 isConnected 报错
if (!socket) {
this.handleAIError('网络连接失败,请检查网络设置')
return
}
if (!socket.isConnected) { if (!socket.isConnected) {
socket.connect() socket.connect()
} }
if (socket) { socket.send({
socket.send({ type: type,
type: type, content: content,
content: content, // 身份以 token 为准,服务端不再接受凭 userId 明文接入
userId: user ? user._id : '', token: (user && user.security && user.security.token) || '',
appId: app.globalData.appId appId: app.globalData.appId
}) })
} else {
// 处理连接失败的情况
this.handleAIError('网络连接失败,请检查网络设置')
}
}, },
handleAIError(errorMessage) { handleAIError(errorMessage) {