fix: 问答页面bug处理

This commit is contained in:
yanghang
2025-07-21 15:39:13 +08:00
parent 2fe3ae7ee4
commit 3b41571b0c
3 changed files with 51 additions and 46 deletions
+3 -2
View File
@@ -140,7 +140,7 @@ export default class WebSocketUtil {
* @param {string|Object} message - 要发送的消息,可以是字符串或对象
* @returns {WebSocketUtil} - 返回当前实例,支持链式调用
*/
send(message) {
send(message, num = 1) {
if (this.socketTask && this.getStatus() === 1) {
// 发送消息,对象会自动转换为JSON字符串
this.socketTask.send({
@@ -156,8 +156,9 @@ export default class WebSocketUtil {
} else {
console.error('WebSocket连接未打开,无法发送消息');
this.triggerEvent('error', new Error('WebSocket连接未打开'));
if(num === 10) return
setTimeout(()=>{
this.send(message)
this.send(message, num + 1)
},500)
}
return this;
+6 -6
View File
@@ -281,12 +281,12 @@ import { onShow } from "@dcloudio/uni-app"
getCourseTypeListApi().then(res=>{
courseTypeList.value = res.body||[]
})
getPrdLineTypeListApi().then(res=>{
coursePrdlineList.value = res.body||[]
})
getTraTagListApi().then(res=>{
tagsTree.value = res.body||[]
})
// getPrdLineTypeListApi().then(res=>{
// coursePrdlineList.value = res.body||[]
// })
// getTraTagListApi().then(res=>{
// tagsTree.value = res.body||[]
// })
changeTab({name:'全部'})
})
onActivated(() => {
+42 -38
View File
@@ -157,6 +157,7 @@
const answerIsOver = ref(true)
const talkingList = ref([])
const showModelComfirm = ref(false)
const initsocketTask = () => {
socketStore.creatSocket('/traask/asksocket/open?summary=')
// unref(SocketObj).on('open', (res)=>{
@@ -171,19 +172,40 @@
// })
// }
// })
unref(SocketObj).on('error', () => {
if((watchFlag.value === 1) || showModelComfirm.value) return
showModelComfirm.value = true
common.show('提示信息', '网络环境不稳定,请重试!',false, '','确认').then((res) => {
common.redirectTo(`/pages/index/dialog`)
}).finally(() => {
showModelComfirm.value = false
})
})
unref(SocketObj).on('message', (res)=>{
const { rtnCode, body, commond } = JSON.parse(res.data)
let _id = new Date().getTime() + 'id'
if(rtnCode === '0000'){
if(commond === 'ASK-OPEN'){
// console.log('链接成功!')
sendMessage({
"commond" : 'ASK-START',
"body" : {
mascotId: mascotId.value,
deviceImei: ''
}
})
if(!answerIsOver.value){
// 问题没完成, 重新尝试回答
sendMessage({
"commond" : 'ASK-RE-START',
"body" : {
reqBatch: reqBatch.value,
seqNo: seqNo.value,
answerContent: answerText.value
}
})
}else{
// 新连接
sendMessage({
"commond" : 'ASK-START',
"body" : {
mascotId: mascotId.value,
deviceImei: ''
}
})
}
return
}
if(commond === 'ASK-START'){
@@ -254,7 +276,6 @@
if(commond === 'ASK-ERR'){
console.log('提问失败,系统异常!')
console.log('body')
return
}
}else{
@@ -421,38 +442,21 @@
initsocketTask()
})
onHide(()=>{
if(watchFlag.value === 1) return
// 停止获取
sendMessage({
"commond" : 'ASK-STOP',
"body" : {
reqBatch: reqBatch.value,
seqNo: seqNo.value,
}
})
socketStore?.closeSocket()
// if(watchFlag.value === 1) return
// // 停止获取
// sendMessage({
// "commond" : 'ASK-STOP',
// "body" : {
// reqBatch: reqBatch.value,
// seqNo: seqNo.value,
// }
// })
// socketStore?.closeSocket()
})
onShow(()=>{
if(watchFlag.value === 1) return
socketStore?.createSocket()
if(!answerIsOver.value){
sendMessage({
"commond" : 'ASK-RE-START',
"body" : {
reqBatch: reqBatch.value,
seqNo: seqNo.value,
answerContent: answerText.value
}
})
}else{
sendMessage({
"commond" : 'ASK-START',
"body" : {
mascotId: mascotId.value,
deviceImei: ''
}
})
}
// initsocketTask()
})
onUnload(()=>{
watchFlag.value = 1