feat(ProductList): 支持通过URL参数shopId自动选择店铺
添加从URL参数中获取shopId的功能,当shopId存在且在店铺列表中时自动选中对应店铺
This commit is contained in:
parent
1224419c9e
commit
a2e30e7bed
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue