交易所前端蓝色ui 4.5 jiem
lxf
2025-05-14 31a83539c601c569288daaf375e9553422d2d2ec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
export function strFirstBit(val) {
  let arr = val.map((val, index, arr) => {
    return val.currency;
  });
  return arr;
}
export function filterArrayEmpty(val) {
  let isEmpty = val.every((val) => {
    return val != "";
  });
  return isEmpty;
}
export class WhrWebSocket {
  constructor(params) {
    //只有params这个参数必须卸载constructor方法里,其他的实例属性可以写在外面
    // 比如 socket = null
    this.socket = null;
    this.params = params;
    this.j = 0; //websocket重连次数
    this.i = 0; //发送信息次数
  }
 
  init(params) {
    if (this.params.path) {
      this.path = this.params.path;
    } else {
      throw new Error("参数socket服务器地址path必须存在");
    }
 
    this.socket = new WebSocket(this.path);
    this.socket.onopen = () => {
      // console.log("连接开启");
    };
    // this.socket.onclose = () => {
 
    //     console.log("连接关闭")
    //     this.reconnect()
    // }
    // this.socket.onerror = () => {
    //     console.log("连接错误")
    // }
    this.socket.onmessage = this.params.onmessage;
  }
 
  // getMessage(msg) {
  //     console.log("收到的消息", msg)
  //     return msg
  // }
 
  close() {
    clearTimeout(this.time);
    this.socket.close(1000, "手动关闭");
  }
}