优化
This commit is contained in:
@@ -4,6 +4,7 @@ import { usePrint } from "@/store/print.js";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import useStorage from "@/utils/useStorage";
|
||||
import ReconnectingWebSocket from "reconnecting-websocket";
|
||||
import { ipcRenderer } from "electron";
|
||||
|
||||
export const useSocket = defineStore({
|
||||
id: "socket",
|
||||
@@ -17,8 +18,12 @@ export const useSocket = defineStore({
|
||||
// 创建uuid
|
||||
createUUID() {
|
||||
if (!useStorage.get("uuid")) {
|
||||
useStorage.set("uuid", uuidv4());
|
||||
this.uuid = useStorage.get("uuid");
|
||||
ipcRenderer.send("getOSmacSync");
|
||||
// useStorage.set("uuid", uuidv4());
|
||||
ipcRenderer.on("getOSmacRes", (event, arg) => {
|
||||
useStorage.set("uuid", arg);
|
||||
this.uuid = useStorage.get("uuid");
|
||||
});
|
||||
} else {
|
||||
this.uuid = useStorage.get("uuid");
|
||||
}
|
||||
@@ -46,11 +51,8 @@ export const useSocket = defineStore({
|
||||
this.ws.addEventListener("open", (event) => {
|
||||
console.log("wss连接成功");
|
||||
this.online = true;
|
||||
|
||||
// 清除心跳
|
||||
this.clearHeartBeat();
|
||||
this.startheartbeat();
|
||||
|
||||
this.ws.send(
|
||||
JSON.stringify({
|
||||
type: "connect",
|
||||
@@ -58,6 +60,7 @@ export const useSocket = defineStore({
|
||||
clientId: this.uuid,
|
||||
})
|
||||
);
|
||||
this.startheartbeat();
|
||||
});
|
||||
|
||||
this.ws.addEventListener("message", (e) => {
|
||||
@@ -72,9 +75,10 @@ export const useSocket = defineStore({
|
||||
);
|
||||
// 接收订单消息,打印小票
|
||||
// printBill(data)
|
||||
|
||||
// 打印标签小票
|
||||
printStore.labelPrint(data);
|
||||
} else if (data.type == "heartbeat") {
|
||||
console.log("接收心跳");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user