im重复请求

master
2023-02-10 16:25:42 +08:00
parent 63ebf1a7c5
commit c9c0d2d171
1 changed files with 44 additions and 40 deletions

View File

@ -279,6 +279,13 @@ export default {
// this.ws.connect(); // this.ws.connect();
this.sokcet(); this.sokcet();
}, },
//
onHide () {
uni.closeSocket();
},
onUnload () {
uni.closeSocket();
},
onPullDownRefresh () { onPullDownRefresh () {
this.params.pageNumber = this.params.pageNumber + 1 this.params.pageNumber = this.params.pageNumber + 1
this.getTalkMessage() this.getTalkMessage()
@ -319,7 +326,7 @@ export default {
ws: new SocketService(), ws: new SocketService(),
resolve: {}, resolve: {},
goodListData: {}, goodListData: {},
count: 0 count: 0, //socket
} }
}, },
// watch: { // watch: {
@ -354,21 +361,22 @@ export default {
talk_id: this.params.talkId, talk_id: this.params.talkId,
} }
let data = JSON.stringify(msg); let data = JSON.stringify(msg);
try { uni.sendSocketMessage({
uni.sendSocketMessage({ data: data,
data: data success: () => {
}); this.msgList.push({
this.msgList.push({ "text": this.msg,
"text": this.msg, "my": true,
"my": true, "messageType": 'MESSAGE'
"messageType": 'MESSAGE' })
}) },
let type = 'down'; fail: () => {
this.msgGo(type) this.sokcet()
this.msg = "" }
} catch (e) { });
uni.closeSocket(); let type = 'down';
} this.msgGo(type)
this.msg = ""
}, },
sendGoodsMessage () { sendGoodsMessage () {
let msg = { let msg = {
@ -381,13 +389,18 @@ export default {
} }
let data = JSON.stringify(msg); let data = JSON.stringify(msg);
uni.sendSocketMessage({ uni.sendSocketMessage({
data: data data: data,
success: () => {
this.msgList.push({
"text": JSON.stringify(this.goodListData),
"my": true,
"messageType": 'GOODS'
})
},
fail: () => {
this.sokcet()
}
}); });
this.msgList.push({
"text": JSON.stringify(this.goodListData),
"my": true,
"messageType": 'GOODS'
})
this.showHide = false this.showHide = false
// #ifdef H5 // #ifdef H5
uni.setStorageSync("imGoodId", 1111111); uni.setStorageSync("imGoodId", 1111111);
@ -418,27 +431,20 @@ export default {
// //
uni.onSocketError(function (err) { uni.onSocketError(function (err) {
if (this.count < 3) { if (this.count < 3) {
if (err && err.code !== 1000) { if (err && err.code != 1000) {
_this.socketOpen = true; _this.socketOpen = true;
uni.connectSocket({ setTimeout(() => {
url: url, uni.connectSocket({
}); url: url,
});
}, 2000)
} }
} else {
uni.closeSocket();
} }
this.count++ this.count++
}); });
} }
//
uni.onSocketClose(function (err) {
if (err && err.code !== 1000) {
setTimeout(function () {
_this.socketOpen = true;
uni.connectSocket({
url: url,
});
}, 999999)
}
});
// //
uni.onSocketMessage(function (res) { uni.onSocketMessage(function (res) {
res.data = JSON.parse(res.data) res.data = JSON.parse(res.data)
@ -451,9 +457,8 @@ export default {
_this.msgGo() _this.msgGo()
}) })
} catch (e) { } catch (e) {
uni.closeSocket();
} }
}, },
beautifyTime, beautifyTime,
// //
@ -508,7 +513,6 @@ export default {
}, },
// //
msgGo (type) { msgGo (type) {
console.log(type, 'typetypetype');
const query = uni.createSelectorQuery() const query = uni.createSelectorQuery()
// 100ms // 100ms
setTimeout(() => { setTimeout(() => {