Skip to content

Commit 405e01d

Browse files
authored
Merge pull request #1004 from MoYingJi/pr/nhs
feat(Search): 增加了是否显示热搜的开关
2 parents 6983106 + b9feeec commit 405e01d

3 files changed

Lines changed: 37 additions & 12 deletions

File tree

src/components/Search/SearchDefault.vue

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
<n-card v-if="isShow" class="search-default" content-style="padding: 0">
44
<n-scrollbar class="scrollbar">
55
<!-- 搜索历史 -->
6-
<div
7-
v-if="settingStore.showSearchHistory && dataStore.searchHistory.length > 0"
8-
class="history"
9-
>
6+
<div v-if="isShowSearchHistory" class="history">
107
<div class="title">
118
<SvgIcon name="History" />
129
<n-text class="name">搜索历史 </n-text>
@@ -25,7 +22,7 @@
2522
</n-flex>
2623
</div>
2724
<!-- 热搜榜 -->
28-
<div v-if="searchHotData.length > 0" class="hot-list">
25+
<div v-if="isShowHotSearch" class="hot-list">
2926
<div class="title">
3027
<SvgIcon name="Fire" />
3128
<n-text class="name">热搜榜 </n-text>
@@ -86,18 +83,30 @@ const settingStore = useSettingStore();
8683
8784
const searchHotData = ref<SearchHotItem[]>([]);
8885
89-
// 是否展示
86+
// 是否展示 SearchDefault
9087
const isShow = computed(() => {
9188
return (
9289
!statusStore.searchInputValue &&
9390
statusStore.searchFocus &&
94-
(searchHotData.value.length > 0 || dataStore.searchHistory.length > 0)
91+
(isShowHotSearch.value || isShowSearchHistory.value)
92+
);
93+
});
94+
95+
// 是否展示搜索历史
96+
const isShowSearchHistory = computed(() => {
97+
return settingStore.showSearchHistory && dataStore.searchHistory.length > 0;
98+
});
99+
100+
// 是否展示热搜榜
101+
const isShowHotSearch = computed(() => {
102+
return (
103+
settingStore.useOnlineService && settingStore.showHotSearch && searchHotData.value.length > 0
95104
);
96105
});
97106
98107
// 获取热搜数据
99108
const getSearchHotData = async () => {
100-
if (!settingStore.useOnlineService) return;
109+
if (!settingStore.useOnlineService || !settingStore.showHotSearch) return;
101110
const result = await getCacheData(searchHot, {
102111
key: "searchHotData",
103112
time: 10,

src/components/Setting/config/general.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,17 +308,30 @@ export const useGeneralSettings = (): SettingConfig => {
308308
{
309309
key: "showSearchHistory",
310310
label: "显示搜索历史",
311+
description: "是否在搜索框的默认显示内容中显示当前搜索历史",
311312
type: "switch",
312313
value: computed({
313314
get: () => settingStore.showSearchHistory,
314315
set: (v) => (settingStore.showSearchHistory = v),
315316
}),
316317
},
318+
{
319+
key: "showHotSearch",
320+
label: "显示热搜榜",
321+
type: "switch",
322+
show: computed(() => settingStore.useOnlineService),
323+
description: "是否在搜索框的默认显示内容中显示热搜榜单",
324+
value: computed({
325+
get: () => settingStore.showHotSearch,
326+
set: (v) => (settingStore.showHotSearch = v),
327+
}),
328+
},
317329
{
318330
key: "enableSearchKeyword",
319331
label: "搜索关键词建议",
320332
type: "switch",
321-
description: "是否启用搜索关键词建议",
333+
show: computed(() => settingStore.useOnlineService),
334+
description: "将搜索框闲置时的默认显示内容替换为搜索关键词建议",
322335
value: computed({
323336
get: () => settingStore.enableSearchKeyword,
324337
set: (v) => (settingStore.enableSearchKeyword = v),

src/stores/setting.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,6 @@ export interface SettingState {
214214
lyricsBlendMode: "screen" | "plus-lighter";
215215
/** 播放试听 */
216216
playSongDemo: boolean;
217-
/** 显示搜索历史 */
218-
showSearchHistory: boolean;
219217
/** 是否使用 AMLL 歌词 */
220218
useAMLyrics: boolean;
221219
/** 是否使用 AMLL 歌词弹簧效果 */
@@ -410,6 +408,10 @@ export interface SettingState {
410408
};
411409
/** 启用搜索关键词获取 */
412410
enableSearchKeyword: boolean;
411+
/** 显示搜索历史 */
412+
showSearchHistory: boolean;
413+
/** 显示热搜榜 */
414+
showHotSearch: boolean;
413415
/** 搜索框行为 */
414416
searchInputBehavior: "normal" | "clear" | "sync";
415417
/** 显示主页问好 */
@@ -500,7 +502,6 @@ export const useSettingStore = defineStore("setting", {
500502
englishLyricFont: "follow",
501503
koreanLyricFont: "follow",
502504
hideVipTag: false,
503-
showSearchHistory: true,
504505
menuShowCover: true,
505506
menuExpandedKeys: [],
506507
routeAnimation: "slide",
@@ -703,6 +704,8 @@ export const useSettingStore = defineStore("setting", {
703704
musicTagEditor: true,
704705
},
705706
enableSearchKeyword: true,
707+
showSearchHistory: true,
708+
showHotSearch: true,
706709
searchInputBehavior: "normal",
707710
showHomeGreeting: true,
708711
homePageSections: [

0 commit comments

Comments
 (0)