无感刷新通知消息内容

main
HUOJIN\92525 2024-09-14 16:05:34 +08:00
parent 96754b1500
commit f998cbdaa2
1 changed files with 48 additions and 8 deletions

View File

@ -36,6 +36,8 @@ export default {
},
data() {
return {
notificationInstance: null, //
showNotification: false, //
lineChartData: lineChartData.newVisitis
}
},
@ -52,6 +54,10 @@ export default {
this.websock = new WebSocket(wsUri)
this.websock.onerror = this.webSocketOnError
this.websock.onmessage = this.webSocketOnMessage
//5
this.pollingTimer = setInterval(() => {
stockUrl.stockMsg()
}, 5000);
},
webSocketOnError(e) {
this.$notify({
@ -61,15 +67,8 @@ export default {
})
}, webSocketOnMessage(e) {
const data = JSON.parse(e.data)
console.log(data)
if (data.msgType === 'INFO') {
this.$notify({
title: '点击关注公众号',
message: data.msg,
type: 'success',
offset: 100,
duration: 0
});
this.createOrUpdateNotification(data);
} else if (data.msgType === 'ERROR') {
this.$notify({
title: '',
@ -83,7 +82,48 @@ export default {
webSocketSend(agentData) {
this.websock.send(agentData)
},
createOrUpdateNotification(data) {
//
if (this.showNotification && this.notificationInstance) {
this.updateNotification(data);
} else {
this.createNotification(data);
}
this.showNotification = true;
},
updateNotification(data) {
//
try {
this.notificationInstance.title = '点击关注公众号';
this.notificationInstance.message = data.msg;
} catch (error) {
//
this.createNotification(data);
}
},
createNotification(data) {
//
this.notificationInstance = this.$notify({
title: '点击关注公众号',
message: data.msg,
type: 'success',
offset: 100,
duration: 0
});
}
},
beforeDestroy() {
if (this.pollingTimer) {
clearInterval(this.pollingTimer);
}
if (this.websock && this.websock.readyState === WebSocket.OPEN) {
this.websock.close();
}
if (this.notificationInstance) {
this.notificationInstance.close(); //
}
}
}
</script>