no message

main
HUOJIN\92525 2024-09-19 11:47:29 +08:00
parent 8ed2d30858
commit 733ba7b15c
1 changed files with 0 additions and 95 deletions

View File

@ -6,7 +6,6 @@
import PanelGroup from './dashboard/PanelGroup' import PanelGroup from './dashboard/PanelGroup'
import LineChart from './dashboard/LineChart' import LineChart from './dashboard/LineChart'
import crudOperation from "@crud/CRUD.operation.vue"; import crudOperation from "@crud/CRUD.operation.vue";
import stockUrl from "@/api/stock";
const lineChartData = { const lineChartData = {
newVisitis: { newVisitis: {
@ -36,106 +35,12 @@ export default {
}, },
data() { data() {
return { return {
notificationInstance: null, //
showNotification: false, //
lineChartData: lineChartData.newVisitis lineChartData: lineChartData.newVisitis
} }
}, },
mounted() {
this.initWebSocket();
},
methods: { methods: {
handleSetLineChartData(type) { handleSetLineChartData(type) {
this.lineChartData = lineChartData[type] this.lineChartData = lineChartData[type]
},
async pollMsg() {
//3
this.pollingTimer = setInterval(async () => {
const data = {msg: '友仓智慧物流,软件定义物流。', msgType: 'INFO'}
console.log(data)
//this.createOrUpdateNotification(data)
}, 3000);
},
initWebSocket() {
stockUrl.stockMsg();
const wsUri = (process.env.VUE_APP_WS_API === '/' ? '/' : (process.env.VUE_APP_WS_API + '/')) + 'webSocket/stock'
this.websock = new WebSocket(wsUri)
this.websock.onerror = this.webSocketOnError
this.websock.onmessage = this.webSocketOnMessage
this.pollMsg()
},
webSocketOnError(e) {
this.$notify({
title: 'WebSocket连接发生错误',
type: 'error',
duration: 0
})
}, webSocketOnMessage(e) {
const data = JSON.parse(e.data)
if (data.msgType === 'INFO') {
this.createOrUpdateNotification(data);
} else if (data.msgType === 'ERROR') {
this.$notify({
title: '',
message: data.msg,
dangerouslyUseHTMLString: true,
type: 'error',
duration: 0
})
}
},
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,
onClose: this.onNotificationClose //
});
},
onNotificationClose() {
this.showNotification = false;
this.notificationInstance = null;
}
},
beforeDestroy() {
if (this.pollingTimer) {
clearInterval(this.pollingTimer);
}
if (this.websock && this.websock.readyState === WebSocket.OPEN) {
this.websock.close();
}
if (this.notificationInstance) {
console.log(111)
this.notificationInstance.close(); //
this.showNotification = false;
this.notificationInstance = null;
} }
} }
} }