From 638300113bebf7d4549c5e163c2c5e634ac68211 Mon Sep 17 00:00:00 2001 From: dzq Date: Fri, 9 May 2025 15:25:17 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=95=86=E5=93=81):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=BA=97=E9=93=BAID=E5=8F=82=E6=95=B0=E4=BB=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=8C=89=E5=BA=97=E9=93=BA=E8=8E=B7=E5=8F=96=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 `getShopGoodsApi` 中添加 `shopId` 参数,允许根据店铺ID过滤商品列表。同时,在 `useProductStore` 中新增 `shopId` 状态和 `setShopId` 方法,用于动态设置店铺ID并触发商品数据更新。这些改动支持了按店铺筛选商品的功能。 --- src/App.vue | 10 ++++++---- src/common/apis/shop/index.ts | 7 +++++-- src/pinia/stores/product.ts | 21 ++++++++++++++++----- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/App.vue b/src/App.vue index 2695f34..8d548ca 100644 --- a/src/App.vue +++ b/src/App.vue @@ -5,12 +5,14 @@ import { useDark } from "@@/composables/useDark" import { useWxStore } from "@/pinia/stores/wx" import { tokenLogin } from '@/common/apis/ab98' import { useAb98UserStore } from '@/pinia/stores/ab98-user' +import { useProductStore } from "./pinia/stores/product" // const userStore = useUserStore() -const wxStore = useWxStore() -const route = useRoute() -const router = useRouter() -const ab98UserStore = useAb98UserStore() +const wxStore = useWxStore(); +const route = useRoute(); +const router = useRouter(); +const ab98UserStore = useAb98UserStore(); +const productStore = useProductStore(); const { isDark, initDark } = useDark() diff --git a/src/common/apis/shop/index.ts b/src/common/apis/shop/index.ts index e106b27..6f19f75 100644 --- a/src/common/apis/shop/index.ts +++ b/src/common/apis/shop/index.ts @@ -5,10 +5,13 @@ import { GetOpenIdRequestParams } from './type' /** 获取商品列表 */ -export function getShopGoodsApi() { +export function getShopGoodsApi(shopId: number|null) { return request({ url: "shop/goods", - method: "get" + method: "get", + params: { + shopId: shopId ? shopId : undefined + } }) } diff --git a/src/pinia/stores/product.ts b/src/pinia/stores/product.ts index 0310069..92e9864 100644 --- a/src/pinia/stores/product.ts +++ b/src/pinia/stores/product.ts @@ -14,12 +14,24 @@ export interface Product { export const useProductStore = defineStore("product", () => { // 商品数据 - const labels = ref>([]) - const categories = ref([]) + const labels = ref>([]); + const categories = ref([]); + const shopId = ref(null); + + const setShopId = (id: number|string) => { + shopId.value = Number(id); + getGoods(); + } const getGoods = async () => { + const urlParams = new URLSearchParams(window.location.search); + const shopIdParams = urlParams.get('shopId') || undefined; + if (shopIdParams) { + shopId.value = Number(shopIdParams); + } + try { - const { data } = await getShopGoodsApi() + const { data } = await getShopGoodsApi(shopId.value); // 转换分类标签 labels.value = data.categoryList.map(c => ({ @@ -42,8 +54,7 @@ export const useProductStore = defineStore("product", () => { console.error("获取商品数据失败:", error) } } - getGoods() - return { labels, categories, getGoods } + return { labels, categories, shopId, getGoods, setShopId } }) /**