From 60ea128a10f5fe8b4c9a60c153e9d9f4b7f0ce33 Mon Sep 17 00:00:00 2001 From: gyq <875626088@qq.com> Date: Thu, 29 Jan 2026 18:24:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=BA=97=E9=93=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E9=85=8D=E7=BD=AE=E6=94=B9=E5=8F=98=E5=90=8E=E5=8F=96?= =?UTF-8?q?=E9=A4=90=E6=A8=A1=E5=BC=8F=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/tool/Instead/index.vue | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/views/tool/Instead/index.vue b/src/views/tool/Instead/index.vue index ffcf629..3ae6b2e 100644 --- a/src/views/tool/Instead/index.vue +++ b/src/views/tool/Instead/index.vue @@ -601,6 +601,24 @@ function dinerDisabled(item, index) { return !shopUser.userInfo.eatModel.includes("take-out"); } } + +// 监听店铺就餐类型配置变化,自动同步 diners.sel,避免切换路由后需刷新才能生效 +watch( + () => shopUser.userInfo && shopUser.userInfo.eatModel, + (eatModel) => { + console.log("watch eatModel change:", eatModel); + if (!eatModel) return; + const sel = eatModel.includes("dine-in") ? 0 : 1; + if (diners.sel !== sel) { + console.log("update diners.sel:", diners.sel, "=>", sel); + diners.sel = sel; + // 同步 carts 的就餐类型 + changeCartsDinerType(); + } + }, + { immediate: true } +); + // 商品分类 const category = reactive({ list: [], @@ -795,6 +813,34 @@ onMounted(async () => { } console.log(table.value); init(); + // 尝试在挂载时主动刷新店铺配置,确保从设置页面返回时能生效 + await refreshShopUserInfo(); +}); + +// 主动刷新店铺信息并同步就餐类型(用于从设置页返回时生效) +async function refreshShopUserInfo() { + try { + const res = await shopUser.getUserInfo(); + if (res && res.eatModel) { + const sel = res.eatModel.includes("dine-in") ? 0 : 1; + if (diners.sel !== sel) { + diners.sel = sel; + changeCartsDinerType(); + } + } + } catch (error) { + console.error("refreshShopUserInfo error", error); + } +} + +// keep-alive 激活时刷新 +onActivated(() => { + refreshShopUserInfo(); +}); + +// 路由复用或更新时刷新 +onBeforeRouteUpdate((to, from) => { + refreshShopUserInfo(); }); function resetOldOrder() {