This commit is contained in:
gyq
2024-07-12 16:36:28 +08:00
parent bb554a28d2
commit 8c1e1d3fbc
12 changed files with 304 additions and 342 deletions

View File

@@ -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("接收心跳");
}
});