优化各项

This commit is contained in:
gyq
2024-07-15 09:46:40 +08:00
parent e00feb82ec
commit 38366601d4
7 changed files with 36 additions and 14 deletions

View File

@@ -8,7 +8,7 @@ import ReconnectingWebSocket from "reconnecting-websocket";
import { ipcRenderer } from "electron";
export const useSocket = defineStore({
id: "socket",
id: uuidv4(),
state: () => ({
online: false, // 在线状态
ws: null, // websocket实例
@@ -33,7 +33,7 @@ export const useSocket = defineStore({
close() {
console.log("关闭ws");
this.ws.close(1000);
// this.ws = null;
this.ws = null;
this.clearHeartBeat();
},
wsReconnect: _.throttle(
@@ -48,7 +48,6 @@ export const useSocket = defineStore({
// 初始化
init(wsUrl = import.meta.env.VITE_API_WSS) {
this.createUUID();
const store = useUser();
const printStore = usePrint();
@@ -67,6 +66,9 @@ export const useSocket = defineStore({
this.online = true;
// 清除心跳
this.clearHeartBeat();
console.log(this);
this.ws.send(
JSON.stringify({
type: "connect",