2828 />
2929 </Transition >
3030 <!-- 默认内容 -->
31- <SearchDefault @to-search =" toSearch" />
31+ <SearchDefault v-if = " settingStore.useOnlineService " @to-search =" toSearch" />
3232 <!-- 搜索结果 -->
3333 <SearchSuggest @to-search =" toSearch" />
3434 <!-- 右键菜单 -->
3737</template >
3838
3939<script setup lang="ts">
40- import { useStatusStore , useDataStore } from " @/stores" ;
40+ import { useStatusStore , useDataStore , useSettingStore } from " @/stores" ;
4141import { searchDefault } from " @/api/search" ;
4242import SearchInpMenu from " @/components/Menu/SearchInpMenu.vue" ;
4343import player from " @/utils/player" ;
@@ -47,13 +47,16 @@ import { formatSongsList } from "@/utils/format";
4747const router = useRouter ();
4848const dataStore = useDataStore ();
4949const statusStore = useStatusStore ();
50+ const settingStore = useSettingStore ();
5051
5152// 右键菜单
5253const searchInpMenuRef = ref <InstanceType <typeof SearchInpMenu > | null >(null );
5354
5455// 搜索框数据
5556const searchInputRef = ref <HTMLInputElement | null >(null );
56- const searchPlaceholder = ref <string >(" 搜索音乐 / 视频" );
57+ const searchPlaceholder = ref <string >(
58+ settingStore .useOnlineService ? " 搜索音乐 / 视频" : " 搜索本地音乐" ,
59+ );
5760const searchRealkeyword = ref <string >(" " );
5861
5962// 搜索框输入限制
@@ -94,14 +97,23 @@ const updatePlaceholder = async () => {
9497
9598// 前往搜索
9699const toSearch = async (key : any , type : string = " keyword" ) => {
100+ // 关闭搜索框
101+ statusStore .searchFocus = false ;
102+ searchInputRef .value ?.blur ();
97103 // 未输入内容且不存在推荐
98104 if (! key && searchPlaceholder .value === " 搜索音乐 / 视频" ) return ;
99105 if (! key && searchPlaceholder .value !== " 搜索音乐 / 视频" && searchRealkeyword .value ) {
100106 key = searchRealkeyword .value ?.trim ();
101107 }
102- // 关闭搜索框
103- statusStore .searchFocus = false ;
104- searchInputRef .value ?.blur ();
108+ // 本地搜索
109+ if (! settingStore .useOnlineService ) {
110+ // 跳转本地搜索页面
111+ router .push ({
112+ name: " search" ,
113+ query: { keyword: key },
114+ });
115+ return ;
116+ }
105117 // 更新推荐
106118 updatePlaceholder ();
107119 // 前往搜索
@@ -143,9 +155,10 @@ const toSearch = async (key: any, type: string = "keyword") => {
143155};
144156
145157onMounted (() => {
146- updatePlaceholder ();
147158 // 每分钟更新
148- useIntervalFn (updatePlaceholder , 60 * 1000 );
159+ if (settingStore .useOnlineService ) {
160+ useIntervalFn (updatePlaceholder , 60 * 1000 , { immediate: true });
161+ }
149162});
150163 </script >
151164
0 commit comments