From 561768934340bb3fe46c6d9dc2b4d67e2cbf51c4 Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Sat, 20 Sep 2025 14:25:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E6=90=9C=E7=B4=A2=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=E6=B7=BB=E5=8A=A0=E5=88=86=E9=A1=B5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 为搜索界面限制每页显示条目数量,并添加分页功能 --- app/pages/search.vue | 136 ++++++++++++++++++++++++++++++------------- 1 file changed, 97 insertions(+), 39 deletions(-) diff --git a/app/pages/search.vue b/app/pages/search.vue index 3b5c97f..8311224 100644 --- a/app/pages/search.vue +++ b/app/pages/search.vue @@ -29,39 +29,75 @@
-
-
-

- {{ getIndexLabel(section.indexUid) }} - {{ - $t('search.result-count', { count: section.estimatedTotalHits }) - }} -

-
-
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + - - {{ getHitTitle(hit) }} - -

{{ getHitTitle(hit) }}

-

- {{ getHitSummary(hit) }} -

-
-
-
+ {{ getHitTitle(hit.content) }} + +

{{ getHitTitle(hit.content) }}

+

+ {{ getHitSummary(hit.content) }} +

+

+ 内容类型: + {{ getIndexLabel(hit.type) }} +

+ +
+ + +
+ +
([]); const localeSections = computed(() => sections.value.map((section) => ({ @@ -105,6 +143,16 @@ const filteredSections = computed(() => localeSections.value.filter((section) => section.hits.length > 0) ); + const hits = computed(() => + filteredSections.value.flatMap((item) => + item.hits.map((content) => ({ content, type: item.indexUid })) + ) + ); + const paginatedHits = computed(() => { + const start = (currentPage.value - 1) * pageSize.value; + const end = currentPage.value * pageSize.value; + return hits.value.slice(start, end); + }); const activeRequestId = ref(0); const indexLabels = computed>(() => ({ @@ -204,8 +252,8 @@ if (requestId === activeRequestId.value) { sections.value = results; } - console.log(results); - console.log(localeSections.value); + console.log('hits:', hits.value); + console.log('paginatedHits:', paginatedHits.value); } catch (error) { console.error('Failed to perform search', error); if (requestId === activeRequestId.value) { @@ -234,16 +282,16 @@ }; } - // const handleInput = debounce((value: string) => { - // performSearch(value); - // }, 300); - const handleClear = () => { keyword.value = ''; sections.value = []; router.replace(localePath({ path: '/search' })); }; + const handleCurrentChange = (page: number) => { + currentPage.value = page; + }; + watch( () => route.query.query, (newQuery) => { @@ -367,16 +415,26 @@ font-size: 1.2rem; font-weight: 600; color: var(--el-color-primary); - margin-bottom: 0.5rem; display: inline-block; } .result-summary { font-size: 0.95rem; color: var(--el-text-color-regular); + margin-bottom: 0.5rem; line-height: 1.6; } + .result-type { + font-size: 0.8rem; + color: var(--el-text-color-secondary); + } + + .result-type-name { + margin-left: 4px; + color: var(--el-color-primary); + } + @media (max-width: 640px) { .search-page { padding: 2rem 1rem; -- 2.49.0 From e4a140e2161630346ed3e79b6fce1a5520d41edc Mon Sep 17 00:00:00 2001 From: R2m1liA <15258427350@163.com> Date: Sat, 20 Sep 2025 14:26:15 +0800 Subject: [PATCH 2/2] =?UTF-8?q?chore:=20=E8=AF=B7=E7=94=A8typescript?= =?UTF-8?q?=E7=9A=84=E7=B1=BB=E5=9E=8B=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nuxt.config.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nuxt.config.ts b/nuxt.config.ts index ef7f4cf..3e65fea 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -36,6 +36,16 @@ export default defineNuxtConfig({ provider: 'local', }, + typescript: { + tsConfig: { + compilerOptions: { + noUnUsedLocals: false, + noUnUsedParameters: false, + strict: false, + }, + }, + }, + // css css: [ '@unocss/reset/tailwind.css', -- 2.49.0