From def97c88edd3564e0fb358cf5cbabf0b58e58b33 Mon Sep 17 00:00:00 2001
From: gaoshp <291585735@qq.com>
Date: 星期三, 02 十月 2024 12:39:52 +0800
Subject: [PATCH] 机器编号
---
src/utils/tool.js | 44 ++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 42 insertions(+), 2 deletions(-)
diff --git a/src/utils/tool.js b/src/utils/tool.js
index 710f402..85cda09 100644
--- a/src/utils/tool.js
+++ b/src/utils/tool.js
@@ -1,8 +1,8 @@
/*
* @Descripttion: 宸ュ叿闆�
* @version: 1.2
- * @LastEditors: sakuya
- * @LastEditTime: 2022骞�5鏈�24鏃�00:28:56
+ * @LastEditors: lzhe lzhe@example.com
+ * @LastEditTime: 2024-06-17 18:21:44
*/
import CryptoJS from 'crypto-js';
@@ -10,6 +10,16 @@
const tool = {}
+var currentLocation = window.location.href; // 鑾峰彇瀹屾暣鐨刄RL
+var protocol = window.location.protocol; // 鑾峰彇鍗忚锛堝http:鎴杊ttps:锛�
+var hostname = window.location.hostname; // 鑾峰彇涓绘満鍚�
+var port = window.location.port; // 鑾峰彇绔彛鍙�
+var pathname = window.location.pathname; // 鑾峰彇璺緞鍚�
+if (process.env.NODE_ENV=='development') {
+ var path = "120.46.212.231:84";
+} else {
+ var path = hostname+":"+port;
+}
/* localStorage */
tool.data = {
set(key, data, datetime = 0) {
@@ -114,6 +124,36 @@
}
}
+/* socket */
+tool.socket = {
+ url:'ws://'+path+'/ws/info',
+ websocket: null,
+ connectToWebSocket(token) { //寤虹珛閾炬帴
+ this.websocket = new WebSocket(this.url + "?access_token=" + token);
+ },
+ sendDataToWebSocket(data) { //鍙戦��
+ if(!data) return; //娌℃湁鍏ュ弬涓嶅彂閫�
+ if (this.websocket.readyState === this.websocket.OPEN) {
+ this.websocket.send(JSON.stringify(data));
+ }
+ // this.websocket.onmessage = function(event) {
+ // // 褰撲粠鏈嶅姟鍣ㄦ敹鍒版秷鎭椂
+ // console.error("WebSocket Error: ", event.data);
+ // };
+
+ // this.websocket.onerror = function(error) {
+ // // 褰揥ebSocket杩炴帴鍙戠敓閿欒鏃�
+ // console.error("WebSocket Error: ", error);
+ // };
+
+ // this.websocket.onclose = function(event) {
+ // // 褰揥ebSocket杩炴帴鍏抽棴鏃�
+ // console.log("WebSocket is closed now.");
+ // // 鍙互鍦ㄨ繖閲岄噸璇曡繛鎺ユ垨鍏朵粬閫昏緫...
+ // };
+ return this;
+ }
+}
/* Fullscreen */
tool.screen = function (element) {
var isFull = !!(document.webkitIsFullScreen || document.mozFullScreen || document.msFullscreenElement || document.fullscreenElement);
--
Gitblit v1.9.3