From 17d29015847f379cb41044c36c43b8c552e4494b Mon Sep 17 00:00:00 2001 From: "HUOJIN\\92525" <925258474@qq.com> Date: Wed, 18 Sep 2024 09:46:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=85=A8=E5=B1=80=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 91 +++++++++++++++++++++++++++++++++++++++++++- src/api/stock.js | 8 ++-- src/views/home.vue | 94 ---------------------------------------------- 3 files changed, 93 insertions(+), 100 deletions(-) diff --git a/src/App.vue b/src/App.vue index bcf47c6..dd3f8c7 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,10 +1,97 @@ diff --git a/src/api/stock.js b/src/api/stock.js index 0370afb..2c3d6e2 100644 --- a/src/api/stock.js +++ b/src/api/stock.js @@ -44,7 +44,7 @@ export function updateStockStatus(stockList) { return request({ url: 'api/stock/updateStockStatus', method: 'put', - data:stockList + data: stockList }) } @@ -75,9 +75,9 @@ export function containerOut(data) { export function stockMsg(data) { return request({ url: 'api/stock/stockMsg', - method: 'post', - data + method: 'get', + params: {data} }) } -export default { add, edit, del,containerIn,containerOut,updateStockStatus,stockMsg} +export default {add, edit, del, containerIn, containerOut, updateStockStatus, stockMsg} diff --git a/src/views/home.vue b/src/views/home.vue index ccc1444..aa25b83 100644 --- a/src/views/home.vue +++ b/src/views/home.vue @@ -36,107 +36,13 @@ export default { }, data() { return { - notificationInstance: null, // 用于存储当前的通知实例 - showNotification: false, // 控制是否显示通知 lineChartData: lineChartData.newVisitis } }, - mounted() { - this.initWebSocket(); - }, methods: { handleSetLineChartData(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; - } } } From 767815e5a32c06adfc79a01ce30bf7e5bb0e5075 Mon Sep 17 00:00:00 2001 From: "HUOJIN\\92525" <925258474@qq.com> Date: Wed, 18 Sep 2024 09:59:04 +0800 Subject: [PATCH 2/2] no message --- src/App.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/src/App.vue b/src/App.vue index dd3f8c7..7f956be 100644 --- a/src/App.vue +++ b/src/App.vue @@ -20,7 +20,6 @@ export default { this.websock = new WebSocket(wsUri) this.websock.onerror = this.webSocketOnError this.websock.onmessage = this.webSocketOnMessage - this.pollMsg() }, webSocketOnError(e) { this.$notify({