From 2a47effa459619604cf30ef8fa8c851f41752357 Mon Sep 17 00:00:00 2001 From: YeMingfei666 <1619116647@qq.com> Date: Fri, 20 Mar 2026 10:45:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B8=85=E7=A9=BA=E5=8E=86?= =?UTF-8?q?=E5=8F=B2=E8=AE=A2=E5=8D=95=E6=97=B6=E6=B6=88=E5=A4=B1=E5=8F=88?= =?UTF-8?q?=E5=87=BA=E7=8E=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/store/modules/carts.ts | 18 +++- src/views/tool/Instead/index.vue | 174 +++++++++++++++++++++++-------- vite.config.ts | 6 +- 4 files changed, 153 insertions(+), 46 deletions(-) diff --git a/package.json b/package.json index 742fbab..a2a93f7 100644 --- a/package.json +++ b/package.json @@ -115,6 +115,7 @@ "vite-plugin-mock-dev-server": "^1.8.3", "vite-plugin-strip-code": "^1.1.0", "vite-plugin-svg-icons": "^2.0.1", + "vite-plugin-vue-devtools": "^8.1.0", "vue-eslint-parser": "^9.4.3", "vue-tsc": "^2.2.0" }, diff --git a/src/store/modules/carts.ts b/src/store/modules/carts.ts index 95278c0..b7ec6cc 100644 --- a/src/store/modules/carts.ts +++ b/src/store/modules/carts.ts @@ -850,6 +850,11 @@ export const useCartsStore = defineStore("carts", () => { let $initParams = {} as ApifoxModel; + + // 标志位,表示是否正在清空历史订单 + const isClearingOldOrder = ref(false); + + async function init(initParams: ApifoxModel | undefined, $oldOrder: any | undefined) { console.log('cart.init.initParams', initParams); console.log('cart.init.$oldOrder', $oldOrder); @@ -990,8 +995,15 @@ export const useCartsStore = defineStore("carts", () => { concocatSocket({ ...$initParams, table_code: table_code.value }); } + // WebSocket 监听 product_update 消息 if (msg.operate_type === "product_update") { - init($initParams, oldOrder.value,); + if (isClearingOldOrder.value) { + console.log("忽略 product_update 消息,因为正在清空历史订单"); + isClearingOldOrder.value = false; // 重置标志位 + return; + } + console.log("处理 product_update 消息"); + init($initParams, oldOrder.value); // 重新初始化 } if (msg.type === "bc") { @@ -1036,6 +1048,8 @@ export const useCartsStore = defineStore("carts", () => { newUserDiscount.value = {} } + + return { disconnect, dinnerType, @@ -1097,7 +1111,7 @@ export const useCartsStore = defineStore("carts", () => { getAllGoodsList, vipUser, changeTableInfo, - tableInfo, + tableInfo, isClearingOldOrder, clearHistory }; }); diff --git a/src/views/tool/Instead/index.vue b/src/views/tool/Instead/index.vue index 3d4c078..362e315 100644 --- a/src/views/tool/Instead/index.vue +++ b/src/views/tool/Instead/index.vue @@ -1,5 +1,9 @@