From 380a8c65729e1b503bf4f6db43cc37a0f98c9aa2 Mon Sep 17 00:00:00 2001 From: gyq <875626088@qq.com> Date: Fri, 15 May 2026 13:40:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=95=86=E5=93=81=E6=8C=89?= =?UTF-8?q?=E5=AD=97=E6=AF=8D=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/store/modules/carts.ts | 25 +++++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 63acc46..d6ee231 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "path-browserify": "^1.0.1", "path-to-regexp": "^8.2.0", "pinia": "^2.3.1", + "pinyin-match": "^1.2.10", "qrcode": "^1.5.4", "qs": "^6.14.0", "sockjs-client": "^1.6.1", diff --git a/src/store/modules/carts.ts b/src/store/modules/carts.ts index 4a7c0a1..58cfc86 100644 --- a/src/store/modules/carts.ts +++ b/src/store/modules/carts.ts @@ -8,6 +8,7 @@ import shopUserApi from '@/api/account/shopUser' import limitTimeDiscountApi from '@/api/market/limitTimeDiscount.js' import { BigNumber } from "bignumber.js"; import _ from "lodash"; +import PinyinMatch from 'pinyin-match' // 导入工具库及相关类型 import { @@ -308,11 +309,17 @@ export const useCartsStore = defineStore("carts", () => { console.log('代客下单页面商品缓存.获取当前店铺可用的限时折扣', limitDiscountRes.value); + // 1. 先把 query.name 提取出来,接口调用时不传,避免后端限制 + const searchName = query.name || ''; + const queryParams = { ...query }; + delete queryParams.name; + + // 2. 调用接口(不带 name 参数,拿全量数据,前端自己过滤) const res = await productApi.getPage({ page: 1, size: 999, status: "on_sale", - ...query, + ...queryParams, }); interface ProductItem { @@ -332,7 +339,21 @@ export const useCartsStore = defineStore("carts", () => { limitDiscountPrice: number; } - goods.value = (res.records as ProductItem[]).map((item: ProductItem): GoodsWithDiscount => { + // 3. 【核心:拼音 + 汉字 模糊过滤】 + let filteredList = res.records as ProductItem[]; + if (searchName) { + filteredList = filteredList.filter(item => { + if (!item.name) return false; + // 汉字模糊搜索 + const hasName = item.name.includes(searchName); + // 拼音/首字母搜索(zs / zhangsan / 张三 都支持) + const hasPinyin = PinyinMatch.match(item.name, searchName); + return hasName || hasPinyin; + }); + } + + // 4. 价格处理(完全不变) + goods.value = filteredList.map((item: ProductItem): GoodsWithDiscount => { item.salePrice = item.lowPrice item.memberPrice = item.lowMemberPrice