Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/components/Search/SearchDefault.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
<n-card v-if="isShow" class="search-default" content-style="padding: 0">
<n-scrollbar class="scrollbar">
<!-- 搜索历史 -->
<div
v-if="settingStore.showSearchHistory && dataStore.searchHistory.length > 0"
class="history"
>
<div v-if="isShowSearchHistory" class="history">
<div class="title">
<SvgIcon name="History" />
<n-text class="name">搜索历史 </n-text>
Expand All @@ -25,7 +22,7 @@
</n-flex>
</div>
<!-- 热搜榜 -->
<div v-if="searchHotData.length > 0" class="hot-list">
<div v-if="isShowHotSearch" class="hot-list">
<div class="title">
<SvgIcon name="Fire" />
<n-text class="name">热搜榜 </n-text>
Expand Down Expand Up @@ -86,18 +83,30 @@ const settingStore = useSettingStore();

const searchHotData = ref<SearchHotItem[]>([]);

// 是否展示
// 是否展示 SearchDefault
const isShow = computed(() => {
return (
!statusStore.searchInputValue &&
statusStore.searchFocus &&
(searchHotData.value.length > 0 || dataStore.searchHistory.length > 0)
(isShowHotSearch.value || isShowSearchHistory.value)
);
});

// 是否展示搜索历史
const isShowSearchHistory = computed(() => {
return settingStore.showSearchHistory && dataStore.searchHistory.length > 0;
});

// 是否展示热搜榜
const isShowHotSearch = computed(() => {
return (
settingStore.useOnlineService && settingStore.showHotSearch && searchHotData.value.length > 0
);
});

// 获取热搜数据
const getSearchHotData = async () => {
if (!settingStore.useOnlineService) return;
if (!settingStore.useOnlineService || !settingStore.showHotSearch) return;
const result = await getCacheData(searchHot, {
key: "searchHotData",
Comment on lines 107 to 111
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

聚焦搜索框是 SearchDefault 显示的必要条件,用户无法在 SearchDefault 打开时跑到设置去把 showHotSearch 打开,这个没有必要

time: 10,
Expand Down
15 changes: 14 additions & 1 deletion src/components/Setting/config/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,17 +308,30 @@ export const useGeneralSettings = (): SettingConfig => {
{
key: "showSearchHistory",
label: "显示搜索历史",
description: "是否在搜索框的默认显示内容中显示当前搜索历史",
type: "switch",
value: computed({
get: () => settingStore.showSearchHistory,
set: (v) => (settingStore.showSearchHistory = v),
}),
},
{
key: "showHotSearch",
label: "显示热搜榜",
type: "switch",
show: computed(() => settingStore.useOnlineService),
description: "是否在搜索框的默认显示内容中显示热搜榜单",
value: computed({
get: () => settingStore.showHotSearch,
set: (v) => (settingStore.showHotSearch = v),
}),
},
{
key: "enableSearchKeyword",
label: "搜索关键词建议",
type: "switch",
description: "是否启用搜索关键词建议",
show: computed(() => settingStore.useOnlineService),
description: "将搜索框闲置时的默认显示内容替换为搜索关键词建议",
value: computed({
get: () => settingStore.enableSearchKeyword,
set: (v) => (settingStore.enableSearchKeyword = v),
Expand Down
9 changes: 6 additions & 3 deletions src/stores/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ export interface SettingState {
lyricsBlendMode: "screen" | "plus-lighter";
/** 播放试听 */
playSongDemo: boolean;
/** 显示搜索历史 */
showSearchHistory: boolean;
/** 是否使用 AMLL 歌词 */
useAMLyrics: boolean;
/** 是否使用 AMLL 歌词弹簧效果 */
Expand Down Expand Up @@ -410,6 +408,10 @@ export interface SettingState {
};
/** 启用搜索关键词获取 */
enableSearchKeyword: boolean;
/** 显示搜索历史 */
showSearchHistory: boolean;
/** 显示热搜榜 */
showHotSearch: boolean;
/** 搜索框行为 */
searchInputBehavior: "normal" | "clear" | "sync";
/** 显示主页问好 */
Expand Down Expand Up @@ -500,7 +502,6 @@ export const useSettingStore = defineStore("setting", {
englishLyricFont: "follow",
koreanLyricFont: "follow",
hideVipTag: false,
showSearchHistory: true,
menuShowCover: true,
menuExpandedKeys: [],
routeAnimation: "slide",
Expand Down Expand Up @@ -703,6 +704,8 @@ export const useSettingStore = defineStore("setting", {
musicTagEditor: true,
},
enableSearchKeyword: true,
showSearchHistory: true,
showHotSearch: true,
searchInputBehavior: "normal",
showHomeGreeting: true,
homePageSections: [
Expand Down
Loading