From d0d31d0380a4bcf409089645cce994e01f9e14b7 Mon Sep 17 00:00:00 2001 From: xcbyy <2578898740@qq.com> Date: Mon, 19 Oct 2026 15:10:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(search):=20=E5=A4=A7=E7=A5=9E=E5=85=B3?= =?UTF-8?q?=E9=94=AE=E8=AF=8D=E6=90=9C=E7=B4=A2=E8=B5=B0=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=AB=AF=EF=BC=88=E6=98=B5=E7=A7=B0/=E5=93=81=E7=B1=BB/?= =?UTF-8?q?=E6=AE=B5=E4=BD=8D/=E6=A0=87=E7=AD=BE=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 仓储 getCompanions(keyword?):参数化 LIKE 搜索 name/track/rank_name/tags 及 id 精确匹配 - 接口 /api/companions 支持 ?keyword=(长度截断 40) - 小程序 api.js getCompanions(keyword) 带 encodeURIComponent;首页监听 searchKeyword 防抖 350ms 走服务端搜索,搜索态以服务端结果为准(含空结果不展示陈旧数据) - 回归 95 套件/668 用例全绿;冒烟 4/4(昵称/品类命中、无匹配空数组、无关键词向后兼容) --- pwuniapp/common/api.js | 8 +++++--- pwuniapp/pages/index/index.vue | 25 +++++++++++++++++++----- server/src/db/repository.ts | 17 ++++++++++++---- server/src/index.ts | 3 ++- server/tests/search-companions.spec.ts | 27 ++++++++++++++++++++++++++ 5 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 server/tests/search-companions.spec.ts diff --git a/pwuniapp/common/api.js b/pwuniapp/common/api.js index f7ee126..c492004 100644 --- a/pwuniapp/common/api.js +++ b/pwuniapp/common/api.js @@ -191,10 +191,12 @@ export async function getMyActivities(userId) { /** * 获取同城大神列表 */ -export async function getCompanions() { +export async function getCompanions(keyword) { try { - const list = await http.get('/companions'); - if (Array.isArray(list) && list.length > 0) { + const kw = String(keyword == null ? '' : keyword).trim(); + const query = kw ? `?keyword=${encodeURIComponent(kw)}` : ''; + const list = await http.get(`/companions${query}`); + if (Array.isArray(list)) { return list .filter((c) => !c.auditStatus || c.auditStatus === '已通过') .map((c) => ({ diff --git a/pwuniapp/pages/index/index.vue b/pwuniapp/pages/index/index.vue index 55f1d9b..987417f 100644 --- a/pwuniapp/pages/index/index.vue +++ b/pwuniapp/pages/index/index.vue @@ -266,7 +266,7 @@