hookehuyr

feat: 优化搜索页清空逻辑和分类引导文案

优化内容:
- 清空时重置到初始状态,不再显示"暂无搜索结果"
- 添加分类相关的动态引导文案(全部/产品/资料)
- 实时搜索监听器优化:清空关键词时也重置状态

影响文件:
- src/pages/search/index.vue
- docs/CHANGELOG.md

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
...@@ -5,6 +5,31 @@ ...@@ -5,6 +5,31 @@
5 5
6 --- 6 ---
7 7
8 +## [2026-02-03] - 优化搜索页清空逻辑和引导文案
9 +
10 +### 优化
11 +- 优化搜索页面的清空逻辑,清空时重置到初始状态(`src/pages/search/index.vue`
12 + - 点击清空按钮后,`hasSearched` 状态重置为 `false`
13 + - 不再显示"暂无搜索结果",而是回到初始状态引导用户
14 + - 实时搜索监听器优化:清空关键词时也重置到初始状态
15 +- 添加分类相关的动态引导文案,提升用户体验
16 + - **全部**分类:显示"搜索培训资料、案例、产品"+"输入关键词开始搜索"
17 + - **产品**分类:显示"搜索保险产品"+"输入产品名称或类型,如'重疾险'"
18 + - **资料**分类:显示"搜索培训资料"+"输入资料关键词,如'销售话术'"
19 +
20 +---
21 +
22 +**详细信息**
23 +- **影响文件**: `src/pages/search/index.vue`
24 +- **技术栈**: Vue 3, Composition API, Computed
25 +- **测试状态**: ✅ 已完成
26 +- **备注**:
27 + - 清空逻辑更符合用户预期,不会显示令人困惑的"暂无搜索结果"
28 + - 分类相关的引导文案帮助用户明确可以搜索什么内容
29 + - 使用 `computed` 属性 `initialStateText` 根据当前分类动态返回文案
30 +
31 +---
32 +
8 ## [2026-02-03] - 优化列表空状态显示 33 ## [2026-02-03] - 优化列表空状态显示
9 34
10 ### 优化 35 ### 优化
......
...@@ -120,8 +120,8 @@ ...@@ -120,8 +120,8 @@
120 <!-- Initial State (从未搜索过) --> 120 <!-- Initial State (从未搜索过) -->
121 <view v-else-if="isInitialState" class="flex flex-col items-center justify-center py-[120rpx]"> 121 <view v-else-if="isInitialState" class="flex flex-col items-center justify-center py-[120rpx]">
122 <IconFont name="search" class="text-gray-300 mb-[24rpx]" size="64" /> 122 <IconFont name="search" class="text-gray-300 mb-[24rpx]" size="64" />
123 - <view class="text-[#6B7280] text-[28rpx]">搜索培训资料、案例、产品</view> 123 + <view class="text-[#6B7280] text-[28rpx]">{{ initialStateText.title }}</view>
124 - <view class="text-[#9CA3AF] text-[24rpx] mt-[12rpx]">输入关键词开始搜索</view> 124 + <view class="text-[#9CA3AF] text-[24rpx] mt-[12rpx]">{{ initialStateText.subtitle }}</view>
125 </view> 125 </view>
126 </view> 126 </view>
127 </view> 127 </view>
...@@ -159,6 +159,40 @@ const isInitialState = computed(() => { ...@@ -159,6 +159,40 @@ const isInitialState = computed(() => {
159 }) 159 })
160 160
161 /** 161 /**
162 + * 初始状态的文案内容
163 + * @description 根据当前选中的分类显示不同的文案,提升用户体验
164 + */
165 +const initialStateText = computed(() => {
166 + const currentTab = tabsData.value.find(tab => tab.id === activeTabId.value)
167 +
168 + if (!currentTab) {
169 + return {
170 + title: '搜索培训资料、案例、产品',
171 + subtitle: '输入关键词开始搜索'
172 + }
173 + }
174 +
175 + // 根据分类返回不同的文案
176 + switch (currentTab.id) {
177 + case 'product':
178 + return {
179 + title: '搜索保险产品',
180 + subtitle: '输入产品名称或类型,如"重疾险"'
181 + }
182 + case 'material':
183 + return {
184 + title: '搜索培训资料',
185 + subtitle: '输入资料关键词,如"销售话术"'
186 + }
187 + default:
188 + return {
189 + title: '搜索培训资料、案例、产品',
190 + subtitle: '输入关键词开始搜索'
191 + }
192 + }
193 +})
194 +
195 +/**
162 * Tab 数据源 196 * Tab 数据源
163 * @description 包含分类信息和对应的列表 197 * @description 包含分类信息和对应的列表
164 */ 198 */
...@@ -333,16 +367,16 @@ const handleBlur = () => { ...@@ -333,16 +367,16 @@ const handleBlur = () => {
333 367
334 /** 368 /**
335 * 清空搜索 369 * 清空搜索
336 - * @description 清空搜索关键词,但保持 hasSearched 状态 370 + * @description 清空搜索关键词并重置到初始状态
337 - * 以显示"暂无搜索结果"而不是"初始状态" 371 + * 让用户可以重新开始搜索,在不同分类下显示对应的引导文案
338 */ 372 */
339 const clearSearch = () => { 373 const clearSearch = () => {
340 console.log('[Search Clear] 清空搜索关键词') 374 console.log('[Search Clear] 清空搜索关键词')
341 searchKeyword.value = '' 375 searchKeyword.value = ''
342 - // ❌ 不要重置 hasSearched,保持"已搜索"状态 376 + hasSearched.value = false // ✅ 重置到初始状态
343 - // hasSearched.value = false
344 listRenderKey.value += 1 377 listRenderKey.value += 1
345 - console.log('[Search Clear] hasSearched 保持为:', hasSearched.value) 378 + console.log('[Search Clear] hasSearched 已重置为 false,显示初始状态')
379 + console.log('[Search Clear] 当前分类:', activeTabId.value)
346 } 380 }
347 381
348 // Go to detail 382 // Go to detail
...@@ -366,6 +400,7 @@ initTabsData() ...@@ -366,6 +400,7 @@ initTabsData()
366 /** 400 /**
367 * 监听搜索关键词变化,实现实时搜索 401 * 监听搜索关键词变化,实现实时搜索
368 * @description 当用户输入关键词时,自动触发搜索,并标记"已搜索"状态 402 * @description 当用户输入关键词时,自动触发搜索,并标记"已搜索"状态
403 + * 当用户清空关键词时,重置到初始状态
369 */ 404 */
370 watch(searchKeyword, (newVal) => { 405 watch(searchKeyword, (newVal) => {
371 if (newVal.trim()) { 406 if (newVal.trim()) {
...@@ -375,9 +410,11 @@ watch(searchKeyword, (newVal) => { ...@@ -375,9 +410,11 @@ watch(searchKeyword, (newVal) => {
375 console.log('[Search Watch] 当前分类:', activeTabId.value) 410 console.log('[Search Watch] 当前分类:', activeTabId.value)
376 console.log('[Search Watch] 搜索结果数量:', searchResults.value.length) 411 console.log('[Search Watch] 搜索结果数量:', searchResults.value.length)
377 console.log('[Search Watch] hasSearched 设置为 true') 412 console.log('[Search Watch] hasSearched 设置为 true')
413 + } else {
414 + // ✅ 清空关键词时,重置到初始状态
415 + hasSearched.value = false
416 + console.log('[Search Watch] 关键词已清空,重置到初始状态')
378 } 417 }
379 - // ✅ 清空关键词时,不要重置 hasSearched
380 - // 这样可以保持"已搜索"状态,显示"暂无搜索结果"而不是"初始状态"
381 }) 418 })
382 </script> 419 </script>
383 420
......