From a660db06773007b1be690e0674829c00a57aeb7b Mon Sep 17 00:00:00 2001
From: 廖井涛 <2265517004@qq.com>
Date: 星期三, 24 十二月 2025 16:21:23 +0800
Subject: [PATCH] 订单首页流程卡新增楼层编号显示
---
north-glass-erp/northglass-erp/src/utils/webSocket.js | 138 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 138 insertions(+), 0 deletions(-)
diff --git a/north-glass-erp/northglass-erp/src/utils/webSocket.js b/north-glass-erp/northglass-erp/src/utils/webSocket.js
new file mode 100644
index 0000000..582771a
--- /dev/null
+++ b/north-glass-erp/northglass-erp/src/utils/webSocket.js
@@ -0,0 +1,138 @@
+
+var websock = null;
+var global_callback = null;
+let isConnect = false; //杩炴帴鏍囪瘑 閬垮厤閲嶅杩炴帴
+let rec; //鏂嚎閲嶈繛鍚庯紝寤惰繜5绉掗噸鏂板垱寤篧ebSocket杩炴帴 rec鐢ㄦ潵瀛樺偍寤惰繜璇锋眰鐨勪唬鐮�
+let soketparams ='蹇冭烦鍖呮娴�'
+
+
+var serverPort = "/ws"; // webSocket杩炴帴绔彛
+var wsuri = `ws://${window.ipConfig.webSocketUrl}/ws`
+
+function createWebSocket(callback) {
+
+ if (websock == null || typeof websock !== WebSocket) {
+ initWebSocket(callback);
+ }
+}
+
+function global_callback1(msg) {
+ console.log("websocket鐨勫洖璋冨嚱鏁版敹鍒版湇鍔″櫒淇℃伅锛�" + JSON.stringify(msg));
+ // console.log("鏀跺埌鏈嶅姟鍣ㄤ俊鎭細" + msg);
+}
+
+function initWebSocket(callback) {
+ global_callback = callback;
+ // 鍒濆鍖杦ebsocket
+ websock = new WebSocket(wsuri);
+ websock.onmessage = function (e) {
+ websocketonmessage(e);
+ };
+ websock.onclose = function (e) {
+ websocketclose(e);
+ };
+ websock.onopen = function () {
+ websocketOpen();
+ };
+
+ // 杩炴帴鍙戠敓閿欒鐨勫洖璋冩柟娉�
+ websock.onerror = function () {
+ console.log("WebSocket杩炴帴鍙戠敓閿欒");
+ };
+}
+
+
+
+//蹇冭烦璁剧疆
+var heartCheck = {
+ timeout: 20000, //姣忔鏃堕棿鍙戦�佷竴娆″績璺冲寘 杩欓噷璁剧疆涓�20s
+ timeoutObj: null, //寤舵椂鍙戦�佹秷鎭璞★紙鍚姩蹇冭烦鏂板缓杩欎釜瀵硅薄锛屾敹鍒版秷鎭悗閲嶇疆瀵硅薄锛�
+
+ start: function () {
+ this.timeoutObj = setInterval(function () {
+ if (isConnect) websock.send(JSON.stringify(soketparams));
+ }, this.timeout);
+ },
+
+ reset: function () {
+ clearTimeout(this.timeoutObj);
+ this.start();
+ }
+};
+
+//瀹氫箟閲嶈繛鍑芥暟
+let reConnect = () => {
+ console.log("灏濊瘯閲嶆柊杩炴帴");
+ if (isConnect) return; //濡傛灉宸茬粡杩炰笂灏变笉鍦ㄩ噸杩炰簡
+ rec && clearTimeout(rec);
+ rec = setTimeout(function () { // 寤惰繜5绉掗噸杩� 閬垮厤杩囧娆¤繃棰戠箒璇锋眰閲嶈繛
+ initWebSocket();
+ }, 5000);
+};
+
+
+
+// 瀹為檯璋冪敤鐨勬柟娉�
+function sendSock(agentData ) {
+ if (websock.readyState === websock.OPEN) {
+ // 鑻ユ槸ws寮�鍚姸鎬�
+ websocketsend(agentData);
+ } else if (websock.readyState === websock.CONNECTING) {
+ // 鑻ユ槸 姝e湪寮�鍚姸鎬侊紝鍒欑瓑寰�1s鍚庨噸鏂拌皟鐢�
+ setTimeout(function () {
+ sendSock(agentData);
+ }, 1000);
+ } else {
+ // 鑻ユ湭寮�鍚� 锛屽垯绛夊緟1s鍚庨噸鏂拌皟鐢�
+ setTimeout(function () {
+ sendSock(agentData);
+ }, 1000);
+ }
+}
+
+function closeSock() {
+ console.log('鍏抽棴浜�')
+ websock.close();
+}
+
+// 鏁版嵁鎺ユ敹
+function websocketonmessage(msg) {
+ // console.log("鏀跺埌鏁版嵁锛�"+JSON.parse(e.data));
+ // console.log("鏀跺埌鏁版嵁锛�"+msg);
+
+ // global_callback(JSON.parse(msg.data));
+ // 鏀跺埌淇℃伅涓築lob绫诲瀷鏃�
+ let result = null;
+ if (msg.data instanceof Blob) {
+ const reader = new FileReader();
+ reader.readAsText(msg.data, "UTF-8");
+ reader.onload = (e) => {
+ result = JSON.parse(reader.result);
+ //console.log("websocket鏀跺埌", result);
+ global_callback(result);
+ };
+ } else {
+ result = JSON.parse(msg.data);
+ //console.log("websocket鏀跺埌", result);
+ global_callback(result);
+ }
+}
+
+// 鏁版嵁鍙戦��
+function websocketsend(agentData) {
+ // console.log("鍙戦�佹暟鎹細" + agentData);
+ websock.send(agentData);
+}
+
+// 鍏抽棴
+function websocketclose(e) {
+ console.log("connection closed (" + e.code + ")");
+}
+
+function websocketOpen(e) {
+ console.log("杩炴帴鎵撳紑");
+ isConnect = true
+ //heartCheck.start(); //鍙戦�佸績璺� 鐪嬩釜浜洪」鐩渶姹�
+}
+
+export { sendSock, createWebSocket, closeSock ,global_callback1};
\ No newline at end of file
--
Gitblit v1.8.0