Skip to content

Commit e466021

Browse files
author
Taois
committed
feat:最近搜索记录和热门搜索点击处理事件
1 parent 9e5aa75 commit e466021

File tree

2 files changed

+81
-8
lines changed

2 files changed

+81
-8
lines changed

dashboard/src/components/Header.vue

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@
5555
<icon-settings/>
5656
</template>
5757
</a-button>
58+
<a-button
59+
v-if="hasSearchResults"
60+
class="close-search-btn"
61+
shape="circle"
62+
@click="closeSearchResults"
63+
:title="'关闭搜索结果'"
64+
>
65+
<template #icon>
66+
<icon-close/>
67+
</template>
68+
</a-button>
5869
</div>
5970
</div>
6071

@@ -128,6 +139,11 @@ export default defineComponent({
128139
return route.name === 'SearchAggregation';
129140
});
130141
142+
// 检测是否有搜索结果(当在搜索页面且有搜索关键词时)
143+
const hasSearchResults = computed(() => {
144+
return isSearchAggregationPage.value && route.query.keyword;
145+
});
146+
131147
// 从localStorage获取聚搜功能状态
132148
const getSearchAggregationStatus = () => {
133149
try {
@@ -176,6 +192,7 @@ export default defineComponent({
176192
searchValue,
177193
showSearchSettings: ref(false),
178194
isSearchAggregationPage,
195+
hasSearchResults,
179196
router
180197
};
181198
},
@@ -255,6 +272,11 @@ export default defineComponent({
255272
Message.success(`已选择 ${selectedCount} 个搜索源`);
256273
this.showSearchSettings = false;
257274
},
275+
closeSearchResults() {
276+
// 关闭搜索结果,回到搜索页面的初始状态
277+
this.searchValue = '';
278+
this.$router.push({ name: 'SearchAggregation' });
279+
},
258280
minimize() {
259281
Message.info("最小化窗口");
260282
// 最小化窗口的逻辑,可以通过调用系统接口来实现
@@ -486,6 +508,31 @@ export default defineComponent({
486508
background: var(--color-fill-4) !important;
487509
}
488510
511+
/* 关闭搜索按钮样式 */
512+
.close-search-btn {
513+
width: 36px !important;
514+
height: 36px !important;
515+
border-radius: 8px !important;
516+
border: 1px solid var(--color-border-2) !important;
517+
background: var(--color-bg-2) !important;
518+
color: var(--color-text-2) !important;
519+
transition: all 0.2s ease !important;
520+
flex-shrink: 0;
521+
}
522+
523+
.close-search-btn:hover {
524+
background: var(--color-danger-light-1) !important;
525+
border-color: var(--color-danger-light-3) !important;
526+
color: var(--color-danger-6) !important;
527+
transform: translateY(-1px);
528+
box-shadow: 0 2px 8px rgba(245, 63, 63, 0.15) !important;
529+
}
530+
531+
.close-search-btn:active {
532+
transform: translateY(0) !important;
533+
background: var(--color-danger-light-2) !important;
534+
}
535+
489536
.search-container :deep(.arco-input-search:focus-within) {
490537
border-color: var(--color-primary-6);
491538
box-shadow: 0 0 0 2px var(--color-primary-1);

dashboard/src/views/SearchAggregation.vue

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@
1212
<icon-history class="title-icon"/>
1313
最近搜索记录
1414
</h3>
15-
<a-button type="text" size="small" class="refresh-btn" @click="clearRecentSearches">清空</a-button>
15+
<a-button type="text" size="small" class="refresh-btn" @click="clearRecentSearches">
16+
<template #icon>
17+
<icon-delete/>
18+
</template>
19+
清空
20+
</a-button>
1621
</div>
1722
<div class="recent-search-tags">
1823
<a-tag
1924
v-for="tag in recentSearches"
2025
:key="tag"
2126
class="recent-tag"
22-
@click="performSearch(tag)"
27+
@click="searchRecentTag(tag)"
2328
>
2429
{{ tag }}
2530
</a-tag>
@@ -218,7 +223,8 @@ import {
218223
IconCheckCircle,
219224
IconCloseCircle,
220225
IconExclamationCircle,
221-
IconEmpty
226+
IconEmpty,
227+
IconDelete
222228
} from '@arco-design/web-vue/es/icon';
223229
import SearchSettingsModal from '@/components/SearchSettingsModal.vue';
224230
import siteService from '@/api/services/site';
@@ -235,7 +241,8 @@ export default defineComponent({
235241
IconCheckCircle,
236242
IconCloseCircle,
237243
IconExclamationCircle,
238-
IconEmpty
244+
IconEmpty,
245+
IconDelete
239246
},
240247
setup() {
241248
const route = useRoute();
@@ -497,13 +504,24 @@ export default defineComponent({
497504
};
498505
499506
const searchHotTag = (tag) => {
500-
searchKeyword.value = tag;
501-
performSearch(tag);
507+
router.push({
508+
name: 'SearchAggregation',
509+
query: { keyword: tag }
510+
});
502511
};
503512
504513
const searchSuggestion = (suggestion) => {
505-
searchKeyword.value = suggestion;
506-
performSearch(suggestion);
514+
router.push({
515+
name: 'SearchAggregation',
516+
query: { keyword: suggestion }
517+
});
518+
};
519+
520+
const searchRecentTag = (tag) => {
521+
router.push({
522+
name: 'SearchAggregation',
523+
query: { keyword: tag }
524+
});
507525
};
508526
509527
const onSearchSettingsConfirm = (settings) => {
@@ -580,6 +598,13 @@ export default defineComponent({
580598
if (keyword) {
581599
searchKeyword.value = keyword;
582600
performSearch(keyword);
601+
} else {
602+
// 当没有keyword参数时,重置搜索状态
603+
hasSearched.value = false;
604+
searchKeyword.value = '';
605+
searchResults.value = {};
606+
activeSource.value = '';
607+
currentPage.value = 1;
583608
}
584609
}, { immediate: true });
585610
// 监听输入草稿用于生成建议
@@ -627,6 +652,7 @@ export default defineComponent({
627652
onSearchInput,
628653
searchHotTag,
629654
searchSuggestion,
655+
searchRecentTag,
630656
onSearchSettingsConfirm,
631657
playVideo,
632658
handleImageError,

0 commit comments

Comments
 (0)