优化店铺信息配置改变后取餐模式不生效的问题
This commit is contained in:
@@ -601,6 +601,24 @@ function dinerDisabled(item, index) {
|
|||||||
return !shopUser.userInfo.eatModel.includes("take-out");
|
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({
|
const category = reactive({
|
||||||
list: [],
|
list: [],
|
||||||
@@ -795,6 +813,34 @@ onMounted(async () => {
|
|||||||
}
|
}
|
||||||
console.log(table.value);
|
console.log(table.value);
|
||||||
init();
|
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() {
|
function resetOldOrder() {
|
||||||
|
|||||||
Reference in New Issue
Block a user