feat(ProductList): 支持通过URL参数shopId自动选择店铺

添加从URL参数中获取shopId的功能,当shopId存在且在店铺列表中时自动选中对应店铺
This commit is contained in:
dzq 2025-06-20 08:41:07 +08:00
parent 1224419c9e
commit a2e30e7bed
1 changed files with 6 additions and 0 deletions

View File

@ -137,10 +137,16 @@ const currentProducts = computed(() => {
// //
onMounted(() => { onMounted(() => {
const urlParams = new URLSearchParams(window.location.search);
const shopIdParam = urlParams.get('shopId') || undefined;
if (showShopList.value) { if (showShopList.value) {
getShopListApi(wxStore.corpid).then((res) => { getShopListApi(wxStore.corpid).then((res) => {
if (res?.code === 0 && res?.data?.length > 0) { if (res?.code === 0 && res?.data?.length > 0) {
shopList.value = res.data; shopList.value = res.data;
if (shopIdParam && shopList.value.some(shop => shop.shopId.toString() == shopIdParam)) {
handleShopSelect(parseInt(shopIdParam));
}
} }
}); });
} else { } else {