From 8d58c40af40493bd5f066cbfdb1ffd9f113c22fc Mon Sep 17 00:00:00 2001
From: 严智鑫 <test>
Date: 星期三, 03 九月 2025 16:37:21 +0800
Subject: [PATCH] 1.前端推数据使用了最新的webSokect客户现场总是掉线,修改为接口方式 2.设备交互整体增加异常处理以及PLC连接方式改为短连接
---
UI-Project/src/views/Lamination/lamination.vue | 110 +++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 79 insertions(+), 31 deletions(-)
diff --git a/UI-Project/src/views/Lamination/lamination.vue b/UI-Project/src/views/Lamination/lamination.vue
index 73f211d..77aa2e2 100644
--- a/UI-Project/src/views/Lamination/lamination.vue
+++ b/UI-Project/src/views/Lamination/lamination.vue
@@ -31,44 +31,92 @@
//const machineId = 21;//褰撳墠椤甸潰鐨勮澶嘔D
var errorScanId;
var errorOpen=false;
-//浣跨敤WebSocket鏂瑰紡灞曠ず鏁版嵁
-let socket = null;
-let socketDownLineTask = null;
-const socketUrl = `ws://${WebSocketHost}:${host}/api/deviceInteraction/api/talk/lamination`;
-const socketDownLineTaskUrl = `ws://${WebSocketHost}:${host}/api/deviceInteraction/api/talk/downLineTask`;
-// 瀹氫箟娑堟伅澶勭悊鍑芥暟锛屾洿鏂� receivedData 鍙橀噺
-const handleMessage = (data) => {
- // 鏇存柊 tableData 鐨勬暟鎹�
- let dataJson = data[""+machineId][0];
+// 鏂板锛氬畾鏃朵换鍔D锛堢敤浜庢竻闄ゅ畾鏃跺櫒锛�
+const timerId = ref(null);
+/**
+ * 鍗曟鎺ュ彛璇锋眰鍑芥暟
+ * 浣滅敤锛氳皟鐢ㄥ悗绔帴鍙o紝鑾峰彇鏁版嵁鍚庝氦缁� handleMessage 澶勭悊
+ */
+const fetchMachineData = async () => {
+ try {
+ // 浠诲姟鏁版嵁
+ request.post("/deviceInteraction/tasking/findMachineTask",{
+ "id": machineId
+ }).then((res) => { // 鏇挎崲涓轰綘鐨凙PI绔偣
+ if (res.code === 200) {
+ // 鍋囪鍚庣杩斿洖鐨勬暟鎹牸寮忎笌 handleMessage 棰勬湡涓�鑷�
+ const responseData = res.data || {};
+ loadData.value =responseData;
+ }
+ });
- loadData.value = dataJson.taskingList[0];
- findMachine.value = dataJson.machine[0];
- sendRecords.value = dataJson.sendRecords[0].reverse();
-
+ // 璁惧鏁版嵁
+ request.post("/deviceInteraction/machine/findMachine",{
+ "id": machineId
+ }).then((res) => { // 鏇挎崲涓轰綘鐨凙PI绔偣
+ if (res.code === 200) {
+ // 鍋囪鍚庣杩斿洖鐨勬暟鎹牸寮忎笌 handleMessage 棰勬湡涓�鑷�
+ const responseData = res.data || {};
+ findMachine.value =responseData;
+ if (Object.keys(findMachine.value).length === 0){
+ if(findMachine.value.remark.toString()!=errorScanId&&findMachine.value.remark.toString()!=""&&findMachine.value.remark.toString()!=undefined){
+ //鏈夋暟鎹氨寮圭獥
+ if(errorOpen){
+ ElMessageBox.close();
+ }
+ errorScanId=findMachine.value.remark.toString();
+ errorInfoFuntion(findMachine.value.remark.toString());
+ errorOpen=true;
+ }else if(findMachine.value.remark.toString()==""&&errorOpen){
+ ElMessageBox.close();
+ errorOpen=false;
+ }
+ }
+ }
+ });
+
+ // 绾夸笅鏁版嵁
+ } catch (err) {
+ console.error('瀹氭椂璇锋眰鍚庣鎺ュ彛澶辫触锛�', err);
+ }
};
-// 瀹氫箟娑堟伅澶勭悊鍑芥暟锛屾洿鏂� receivedData 鍙橀噺
-const handleMessage2 = (data) => {
- downLineTask.value = data.downLineTask[0];
- // console.log(data);
+
+/**
+ * 鍚姩瀹氭椂鍣�
+ * @param {number} interval - 瀹氭椂闂撮殧锛堟绉掞紝榛樿500ms锛屼笌鍚庣浠诲姟棰戠巼瀵归綈锛�
+ */
+const startTimer = (interval = 500) => {
+ // 鍏堟竻闄ゅ凡鏈夊畾鏃跺櫒锛堥伩鍏嶉噸澶嶅垱寤猴級
+ if (timerId.value) clearInterval(timerId.value);
+ // 绔嬪嵆鎵ц涓�娆★紙閬垮厤棣栨绛夊緟闂撮殧锛�
+ fetchMachineData();
+ // 鍒涘缓鏂板畾鏃跺櫒
+ timerId.value = setInterval(() => {
+ fetchMachineData();
+ }, interval);
};
+
+/**
+ * 娓呴櫎瀹氭椂鍣紙閬垮厤鍐呭瓨娉勬紡锛�
+ */
+const clearTimer = () => {
+ if (timerId.value) {
+ clearInterval(timerId.value);
+ timerId.value = null; // 閲嶇疆ID
+ }
+};
+
+// 缁勪欢鍗歌浇鏃舵竻闄ゅ畾鏃跺櫒锛堝叧閿細閬垮厤缁勪欢閿�姣佸悗瀹氭椂鍣ㄤ粛杩愯锛�
onUnmounted(() => {
- if (socket) {
- closeWebSocket(socket);
- }
- if (socketDownLineTask) {
- closeWebSocket(socketDownLineTask);
- }
-});
-onBeforeUnmount(() => {
- console.log("鍏抽棴浜�")
- closeWebSocket();
+ clearTimer();
});
onMounted(async () => {
- //浣跨敤WebSocket鏂瑰紡灞曠ず鏁版嵁
- socket = initializeWebSocket(socketUrl, handleMessage);// 鍒濆鍖� WebSocket锛屽苟浼犻�掓秷鎭鐞嗗嚱鏁�
- //浣跨敤WebSocket鏂瑰紡灞曠ず鏁版嵁
- socketDownLineTask = initializeWebSocket(socketDownLineTaskUrl, handleMessage2);// 鍒濆鍖� WebSocket锛屽苟浼犻�掓秷鎭鐞嗗嚱鏁�
+ startTimer(500); // 500ms 闂撮殧锛堝彲鏍规嵁涓氬姟璋冩暣锛屽1000ms锛�
+ // //浣跨敤WebSocket鏂瑰紡灞曠ず鏁版嵁
+ // socket = initializeWebSocket(socketUrl, handleMessage);// 鍒濆鍖� WebSocket锛屽苟浼犻�掓秷鎭鐞嗗嚱鏁�
+ // //浣跨敤WebSocket鏂瑰紡灞曠ず鏁版嵁
+ // socketDownLineTask = initializeWebSocket(socketDownLineTaskUrl, handleMessage2);// 鍒濆鍖� WebSocket锛屽苟浼犻�掓秷鎭鐞嗗嚱鏁�
});
//鎶ヨ鎻愮ず
const errorInfoFuntion = async (info) => {
--
Gitblit v1.8.0