From 0aa509e4306b8984b551cfa19aff9e407a9a9d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=98937886381=E2=80=99?= <‘937886381@qq.com’> Date: Wed, 27 Mar 2024 09:30:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/OperationalOverview/websocket.js | 51 ++++++++++++++----- src/views/report/glass/day.vue | 6 +-- src/views/report/glass/inputTable.vue | 6 +-- src/views/report/glass/month.vue | 2 +- src/views/report/glass/weekly.vue | 2 +- src/views/report/glass/year.vue | 2 +- .../report/productionDayReport/index.vue | 4 +- 7 files changed, 48 insertions(+), 25 deletions(-) diff --git a/src/views/OperationalOverview/websocket.js b/src/views/OperationalOverview/websocket.js index 82a96847..f3b5eedd 100644 --- a/src/views/OperationalOverview/websocket.js +++ b/src/views/OperationalOverview/websocket.js @@ -1,10 +1,3 @@ -/* - * @Author: zhp - * @Date: 2024-01-29 17:05:25 - * @LastEditTime: 2024-01-29 17:05:25 - * @LastEditors: zhp - * @Description: - */ /** * 发起websocket请求函数 * @param {string} url ws连接地址 @@ -49,7 +42,7 @@ export function WsConnect(url, agentData, successCallback, errCallback) { this.lockReconnect = true; this.wsCreateHandler && clearTimeout(this.wsCreateHandler); // 关闭心跳检查 - // heartCheck.stop(); + heartCheck.stop(); } }; const initWsEventHandle = () => { @@ -57,13 +50,13 @@ export function WsConnect(url, agentData, successCallback, errCallback) { // 连接成功 this.wsObj.onopen = (event) => { onWsOpen(event); - // heartCheck.start(); + heartCheck.start(); }; // 监听服务器端返回的信息 this.wsObj.onmessage = (event) => { onWsMessage(event); - // heartCheck.start(); + heartCheck.start(); }; this.wsObj.onclose = (event) => { @@ -130,7 +123,7 @@ export function WsConnect(url, agentData, successCallback, errCallback) { if (this.lockReconnect) { return; } - writeToScreen("3秒后重连"); + writeToScreen("5秒后重连"); this.lockReconnect = true; // 没连接上会一直重连,设置延迟避免请求过多 this.wsCreateHandler && clearTimeout(this.wsCreateHandler); @@ -139,10 +132,40 @@ export function WsConnect(url, agentData, successCallback, errCallback) { this.createWebSoket(); this.lockReconnect = false; writeToScreen("重连完成"); - }, 3000); + }, 5000); + }; + + // 心跳检查(看看websocket是否还在正常连接中,不需要服务端返回,单向的) + let _this = this + let heartCheck = { + timeout: 55000, + timeoutObj: null, + // 重启 + reset() { + clearTimeout(this.timeoutObj); + this.start(); + }, + // 停止 + stop() { + clearTimeout(this.timeoutObj); + }, + // 开启定时器 + start() { + this.timeoutObj && clearTimeout(this.timeoutObj); + this.timeoutObj = setTimeout(() => { + writeToScreen("心跳检查,发送ping到后台"); + try { + const datas = { ping: true }; + _this.wsObj.send(JSON.stringify(datas)); + } catch (err) { + writeToScreen("发送ping异常"); + } + }, this.timeout); + }, }; - // 心跳检查(看看websocket是否还在正常连接中) + + // 心跳检查(看看websocket是否还在正常连接中,和服务端通信,双向的) // let heartCheck = { // timeout: 15000, // timeoutObj: null, @@ -167,7 +190,7 @@ export function WsConnect(url, agentData, successCallback, errCallback) { // writeToScreen("心跳检查,发送ping到后台"); // try { // const datas = { ping: true }; - // this.wsObj.send(JSON.stringify(datas)); + // _this.wsObj.send(JSON.stringify(datas)); // } catch (err) { // writeToScreen("发送ping异常"); // } diff --git a/src/views/report/glass/day.vue b/src/views/report/glass/day.vue index b6c68cc1..6d408a77 100644 --- a/src/views/report/glass/day.vue +++ b/src/views/report/glass/day.vue @@ -1,7 +1,7 @@ @@ -16,9 +16,9 @@ - 查询 - 导出 diff --git a/src/views/report/glass/inputTable.vue b/src/views/report/glass/inputTable.vue index e112eb3f..4b33c779 100644 --- a/src/views/report/glass/inputTable.vue +++ b/src/views/report/glass/inputTable.vue @@ -1,7 +1,7 @@ @@ -206,12 +206,10 @@ const cols = [ }, methods: { handleReturn() { - // this.disabled = true this.edit = false + console.log(this.$parent.getDataList()); }, handleChange(e) { - // console.log(q) - console.log(e); }, updateData() { let obj = {} diff --git a/src/views/report/glass/month.vue b/src/views/report/glass/month.vue index ddbb382d..e958185d 100644 --- a/src/views/report/glass/month.vue +++ b/src/views/report/glass/month.vue @@ -7,7 +7,7 @@ - 查询 导出 diff --git a/src/views/report/glass/weekly.vue b/src/views/report/glass/weekly.vue index 2b167a9a..5c1cdd66 100644 --- a/src/views/report/glass/weekly.vue +++ b/src/views/report/glass/weekly.vue @@ -14,7 +14,7 @@ - 查询 导出 diff --git a/src/views/report/glass/year.vue b/src/views/report/glass/year.vue index 1d76ed21..31547716 100644 --- a/src/views/report/glass/year.vue +++ b/src/views/report/glass/year.vue @@ -9,7 +9,7 @@ - 查询 导出 diff --git a/src/views/report/productionDayReport/index.vue b/src/views/report/productionDayReport/index.vue index 23563c5c..f16e7da3 100644 --- a/src/views/report/productionDayReport/index.vue +++ b/src/views/report/productionDayReport/index.vue @@ -1,7 +1,7 @@ @@ -456,6 +456,8 @@ export default { handleReturn() { this.disabled = true this.isSave = false + this.getDataList() + }, format(shijianchuo) { //shijianchuo是整数,否则要parseInt转换 -- 2.24.3