From 0c45fd9de183d4c063b86d19fe9b8a790a1d262d Mon Sep 17 00:00:00 2001 From: gyq <875626088@qq.com> Date: Mon, 31 Mar 2025 09:21:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AE=A2=E5=8D=95=E6=89=93?= =?UTF-8?q?=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development | 4 ++-- package.json | 2 +- src/store/goods.js | 2 ++ src/store/socket.js | 44 +++++++++++++++++++++------------- src/views/device/add.vue | 5 +++- src/views/device/add_label.vue | 5 +++- 6 files changed, 41 insertions(+), 21 deletions(-) diff --git a/.env.development b/.env.development index 6bd8ead..e98004a 100644 --- a/.env.development +++ b/.env.development @@ -20,10 +20,10 @@ VITE_API_PHP_URL = 'https://newblockwlx.sxczgkj.cn/index.php/api' VITE_API_KP_URL = 'https://invoice.sxczgkj.cn/api' # 本地调试连接 -VITE_API_URL = 'http://192.168.1.31/' +# VITE_API_URL = 'http://192.168.1.31/' # 线上测试 # VITE_API_URL = 'https://tapi.cashier.sxczgkj.cn' # 线上正式 -# VITE_API_URL = 'https://cashier.sxczgkj.com' \ No newline at end of file +VITE_API_URL = 'https://cashier.sxczgkj.com' \ No newline at end of file diff --git a/package.json b/package.json index daecab4..43a9b3f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "vite-electron", "private": true, - "version": "2.0.0", + "version": "2.0.3", "main": "dist-electron/main.js", "scripts": { "dev": "chcp 65001 && vite", diff --git a/src/store/goods.js b/src/store/goods.js index 53f776d..a71a4be 100644 --- a/src/store/goods.js +++ b/src/store/goods.js @@ -61,6 +61,8 @@ export const useGoods = defineStore("goods", { this.goodsListLoading = false; this.goodsList = []; this.originGoodsList = []; + + useStorage.del("printList"); }, // 清除会员信息 clearVipUserInfo() { diff --git a/src/store/socket.js b/src/store/socket.js index e6b2b9c..847eed6 100644 --- a/src/store/socket.js +++ b/src/store/socket.js @@ -16,6 +16,7 @@ export const useSocket = defineStore("socket", { orderList: [], orderListTimer: null, log: false, + isPrinting: false, }), actions: { // 关闭ws @@ -147,11 +148,15 @@ export const useSocket = defineStore("socket", { } } else if (data.data_type == "order") { // 收到订单消息,打印订单小票 - if (!this.orderList.some((el) => el == data.data)) { + let printList = useStorage.get("printList") || []; + if (!printList.some((el) => el == data.data)) { // 防止重复打印 this.orderList.push(data.data); this.startPrintInterval(); } + + printList.push(data.data); + useStorage.set("printList", _.uniq(printList)); } else if (data.data_type == "product_update") { // 商品更新 this.updateGoods(); @@ -189,28 +194,35 @@ export const useSocket = defineStore("socket", { }, // 打印队列开始执行 startPrintInterval() { + if (this.isPrinting) return; // 如果正在打印,直接返回 + this.isPrinting = true; // 标记为正在打印 + const printStore = usePrint(); - if (this.orderListTimer !== null) return; - this.orderListTimer = setInterval(async () => { + const printNextOrder = async () => { try { if (!this.orderList.length) { - clearInterval(this.orderListTimer); - this.orderListTimer = null; - } else { - const orderInfo = await getOrderByIdAjax(this.orderList[0]); - if (orderInfo.status == "done" && orderInfo.platformType != "PC") { - // 打印小票 - printStore.pushReceiptData(commOrderPrintData(orderInfo)); - // 打印标签小票 - printStore.labelPrint(commOrderPrintData(orderInfo)); - } - this.orderList.splice(0, 1); + this.isPrinting = false; // 订单处理完,标记为不在打印 + return; + } + const orderInfo = await getOrderByIdAjax(this.orderList[0]); + if (orderInfo.status == "done" && orderInfo.platformType != "PC") { + // 打印小票 + printStore.pushReceiptData(commOrderPrintData(orderInfo)); + // 打印标签小票 + printStore.labelPrint(commOrderPrintData(orderInfo)); } - } catch (error) { this.orderList.splice(0, 1); + // 递归调用打印下一个订单 + setTimeout(printNextOrder, 2000); + } catch (error) { console.log(error); + // 发生错误时继续尝试下一个订单 + this.orderList.splice(0, 1); + setTimeout(printNextOrder, 2000); } - }, 2000); + }; + // 开始打印第一个订单 + printNextOrder(); }, }, }); diff --git a/src/views/device/add.vue b/src/views/device/add.vue index 159cb56..b2505db 100644 --- a/src/views/device/add.vue +++ b/src/views/device/add.vue @@ -1,5 +1,5 @@