From b46e6d2306515f94bf77c06e8d80ac76267e3ddb Mon Sep 17 00:00:00 2001
From: gaoshp <291585735@qq.com>
Date: 星期日, 02 六月 2024 21:44:23 +0800
Subject: [PATCH] 搜索

---
 src/utils/tool.js |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/src/utils/tool.js b/src/utils/tool.js
index 8c027db..5313762 100644
--- a/src/utils/tool.js
+++ b/src/utils/tool.js
@@ -114,6 +114,36 @@
 	}
 }
 
+/* socket */
+tool.socket = {
+	url:'ws://116.63.155.153:83/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);
@@ -218,4 +248,15 @@
 	}
 }
 
+tool.qsStringify = function(obj) {
+	return Object.keys(obj).map(key => {
+      if (Array.isArray(obj[key])) {
+        return obj[key]
+          .map(arrayValue => `${encodeURIComponent(key)}=${encodeURIComponent(arrayValue)}`)
+          .join('&');
+      }
+      return `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`;
+  	}).join('&');
+}
+
 export default tool

--
Gitblit v1.9.3