提交
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import _ from "lodash";
|
||||
import { defineStore } from "pinia";
|
||||
import { useUser } from "@/store/user.js";
|
||||
import { usePrint } from "@/store/print.js";
|
||||
@@ -31,10 +32,19 @@ export const useSocket = defineStore({
|
||||
// 关闭ws
|
||||
close() {
|
||||
console.log("关闭ws");
|
||||
this.ws.close();
|
||||
this.ws = null;
|
||||
this.ws.close(1000);
|
||||
// this.ws = null;
|
||||
this.clearHeartBeat();
|
||||
},
|
||||
wsReconnect: _.throttle(
|
||||
function () {
|
||||
if (this.ws.readyState == ReconnectingWebSocket.OPEN) return;
|
||||
this.ws.reconnect();
|
||||
console.log("11111");
|
||||
},
|
||||
2000,
|
||||
{ leading: true, trailing: false }
|
||||
),
|
||||
// 初始化
|
||||
init(wsUrl = import.meta.env.VITE_API_WSS) {
|
||||
this.createUUID();
|
||||
@@ -45,7 +55,11 @@ export const useSocket = defineStore({
|
||||
printStore.init();
|
||||
|
||||
if (this.ws == null) {
|
||||
console.log("创建新的ws连接");
|
||||
this.ws = new ReconnectingWebSocket(wsUrl);
|
||||
} else {
|
||||
console.log("重新连接ws");
|
||||
this.wsReconnect();
|
||||
}
|
||||
|
||||
this.ws.addEventListener("open", (event) => {
|
||||
|
||||
Reference in New Issue
Block a user