diff --git a/src/common/apis/shop/type.ts b/src/common/apis/shop/type.ts index 0803c5f..219bd05 100644 --- a/src/common/apis/shop/type.ts +++ b/src/common/apis/shop/type.ts @@ -7,6 +7,7 @@ export type Goods = { status: number, coverImg: string, goodsDetail: string, + usageInstruction: string, cellId: number } diff --git a/src/pages/product/ProductList.vue b/src/pages/product/ProductList.vue index ed1177d..6a8cf35 100644 --- a/src/pages/product/ProductList.vue +++ b/src/pages/product/ProductList.vue @@ -42,6 +42,8 @@ const currentProduct = computed(() => // 购物车弹窗控制 const showCartPopup = ref(false) +const searchQuery = ref('') + // 点击分类导航 function handleCategoryClick(index: number) { activeCategory.value = index @@ -99,8 +101,16 @@ function getCartItemCount(cellId: number) { return item ? item.quantity : 0 } +function filterProductsByName(products: Product[], query: string) { + if (!query) return products + return products.filter(p => + p.name.toLowerCase().includes(query.toLowerCase()) + ) +} + const currentProducts = computed(() => { - return categories.value.filter(c => c.label === labels.value[activeCategory.value].id) + const filteredByCategory = categories.value.filter(c => c.label === labels.value[activeCategory.value].id) + return filterProductsByName(filteredByCategory, searchQuery.value) }) // 组件挂载时添加滚动监听 @@ -143,6 +153,12 @@ watch(() => route.path, (newPath) => {
+