Initial commit

This commit is contained in:
2025-08-18 16:50:57 +08:00
commit 4fc95516d6
350 changed files with 175555 additions and 0 deletions

65
src/utils/webSocket.js Normal file
View File

@ -0,0 +1,65 @@
const url = "ws://47.108.232.77:7555/socket/"; //线上
class WebSoketClass {
constructor(props) { }
ws = null;
static getInstance() {
if (!this.ws) this.ws = new WebSoketClass();
return this.ws;
}
//关闭连接
static close() {
this.ws.ws.close();
}
// 创建连接
connect(fun) {
let uuid = this.getUUid()
this.ws = new WebSocket(url + uuid);
this.ws.onopen = (e) => { fun(true); };
}
// 心跳机制
heartCheck() {
const _that = this;
this.state = setInterval(() => {
if (this.ws.readyState === 1) {
this.ws.send("/heart");
} else {
this.closeHandle(); //重新连接
}
}, 6e3);
}
// 获取uuid
getUUid() {
var s = [];
var hexDigits = "0123456789abcdefghijklmnopqrstuvwxyz";
for (var i = 0; i < 32; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
s[14] = "4";
s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
s[8] = s[13] = s[18] = s[23];
let uuid = s.join("");
return uuid
}
closeHandle() {
if (this.state) {
clearInterval(this.state);
this.connect();
} else {
}
}
// 接收发送消息
getMessage() {
this.ws.onmessage = (e) => {
if (e.data) {
let newsDate = JSON.parse(e.data);
this.newVal = newsDate;
//接收的数据
}
};
}
}
export default WebSoketClass;