28
28
/>
29
29
</Transition >
30
30
<!-- 默认内容 -->
31
- <SearchDefault @to-search =" toSearch" />
31
+ <SearchDefault v-if = " settingStore.useOnlineService " @to-search =" toSearch" />
32
32
<!-- 搜索结果 -->
33
33
<SearchSuggest @to-search =" toSearch" />
34
34
<!-- 右键菜单 -->
37
37
</template >
38
38
39
39
<script setup lang="ts">
40
- import { useStatusStore , useDataStore } from " @/stores" ;
40
+ import { useStatusStore , useDataStore , useSettingStore } from " @/stores" ;
41
41
import { searchDefault } from " @/api/search" ;
42
42
import SearchInpMenu from " @/components/Menu/SearchInpMenu.vue" ;
43
43
import player from " @/utils/player" ;
@@ -47,13 +47,16 @@ import { formatSongsList } from "@/utils/format";
47
47
const router = useRouter ();
48
48
const dataStore = useDataStore ();
49
49
const statusStore = useStatusStore ();
50
+ const settingStore = useSettingStore ();
50
51
51
52
// 右键菜单
52
53
const searchInpMenuRef = ref <InstanceType <typeof SearchInpMenu > | null >(null );
53
54
54
55
// 搜索框数据
55
56
const searchInputRef = ref <HTMLInputElement | null >(null );
56
- const searchPlaceholder = ref <string >(" 搜索音乐 / 视频" );
57
+ const searchPlaceholder = ref <string >(
58
+ settingStore .useOnlineService ? " 搜索音乐 / 视频" : " 搜索本地音乐" ,
59
+ );
57
60
const searchRealkeyword = ref <string >(" " );
58
61
59
62
// 搜索框输入限制
@@ -94,14 +97,23 @@ const updatePlaceholder = async () => {
94
97
95
98
// 前往搜索
96
99
const toSearch = async (key : any , type : string = " keyword" ) => {
100
+ // 关闭搜索框
101
+ statusStore .searchFocus = false ;
102
+ searchInputRef .value ?.blur ();
97
103
// 未输入内容且不存在推荐
98
104
if (! key && searchPlaceholder .value === " 搜索音乐 / 视频" ) return ;
99
105
if (! key && searchPlaceholder .value !== " 搜索音乐 / 视频" && searchRealkeyword .value ) {
100
106
key = searchRealkeyword .value ?.trim ();
101
107
}
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
+ }
105
117
// 更新推荐
106
118
updatePlaceholder ();
107
119
// 前往搜索
@@ -143,9 +155,10 @@ const toSearch = async (key: any, type: string = "keyword") => {
143
155
};
144
156
145
157
onMounted (() => {
146
- updatePlaceholder ();
147
158
// 每分钟更新
148
- useIntervalFn (updatePlaceholder , 60 * 1000 );
159
+ if (settingStore .useOnlineService ) {
160
+ useIntervalFn (updatePlaceholder , 60 * 1000 , { immediate: true });
161
+ }
149
162
});
150
163
</script >
151
164
0 commit comments