diff --git a/src/i18n/lang/en-US/search.ts b/src/i18n/lang/en-US/search.ts index a04dcdd..1c85535 100644 --- a/src/i18n/lang/en-US/search.ts +++ b/src/i18n/lang/en-US/search.ts @@ -16,5 +16,12 @@ export default { noMore: 'No more results', error: { searchFailed: 'Search failed' + }, + search: { + single: 'Single', + album: 'Album', + playlist: 'Playlist', + mv: 'MV', + bilibili: 'Bilibili' } }; diff --git a/src/i18n/lang/zh-CN/search.ts b/src/i18n/lang/zh-CN/search.ts index 06a18e1..a0189a3 100644 --- a/src/i18n/lang/zh-CN/search.ts +++ b/src/i18n/lang/zh-CN/search.ts @@ -16,5 +16,12 @@ export default { noMore: '没有更多了', error: { searchFailed: '搜索失败' + }, + search: { + single: '单曲', + album: '专辑', + playlist: '歌单', + mv: 'MV', + bilibili: 'B站' } }; diff --git a/src/renderer/auto-imports.d.ts b/src/renderer/auto-imports.d.ts index b4ca07c..12e91f3 100644 --- a/src/renderer/auto-imports.d.ts +++ b/src/renderer/auto-imports.d.ts @@ -70,6 +70,6 @@ declare global { // for type re-export declare global { // @ts-ignore - export type { Component, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue' + export type { Component, Slot, Slots, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue' import('vue') } diff --git a/src/renderer/components.d.ts b/src/renderer/components.d.ts index c1c31c1..db2771c 100644 --- a/src/renderer/components.d.ts +++ b/src/renderer/components.d.ts @@ -13,17 +13,13 @@ declare module 'vue' { NBadge: typeof import('naive-ui')['NBadge'] NButton: typeof import('naive-ui')['NButton'] NButtonGroup: typeof import('naive-ui')['NButtonGroup'] - NCard: typeof import('naive-ui')['NCard'] NCarousel: typeof import('naive-ui')['NCarousel'] NCarouselItem: typeof import('naive-ui')['NCarouselItem'] NCheckbox: typeof import('naive-ui')['NCheckbox'] NCheckboxGroup: typeof import('naive-ui')['NCheckboxGroup'] - NCollapse: typeof import('naive-ui')['NCollapse'] - NCollapseItem: typeof import('naive-ui')['NCollapseItem'] NCollapseTransition: typeof import('naive-ui')['NCollapseTransition'] NConfigProvider: typeof import('naive-ui')['NConfigProvider'] NDialogProvider: typeof import('naive-ui')['NDialogProvider'] - NDivider: typeof import('naive-ui')['NDivider'] NDrawer: typeof import('naive-ui')['NDrawer'] NDrawerContent: typeof import('naive-ui')['NDrawerContent'] NDropdown: typeof import('naive-ui')['NDropdown'] @@ -41,7 +37,6 @@ declare module 'vue' { NMessageProvider: typeof import('naive-ui')['NMessageProvider'] NModal: typeof import('naive-ui')['NModal'] NPopover: typeof import('naive-ui')['NPopover'] - NProgress: typeof import('naive-ui')['NProgress'] NRadio: typeof import('naive-ui')['NRadio'] NRadioGroup: typeof import('naive-ui')['NRadioGroup'] NScrollbar: typeof import('naive-ui')['NScrollbar'] diff --git a/src/renderer/const/bar-const.ts b/src/renderer/const/bar-const.ts index 49f174d..0b24b7e 100644 --- a/src/renderer/const/bar-const.ts +++ b/src/renderer/const/bar-const.ts @@ -23,51 +23,28 @@ export const USER_SET_OPTIONS = [ export const SEARCH_TYPES = [ { - label: '单曲', + label: 'search.search.single', // 单曲 key: 1 }, { - label: '专辑', + label: 'search.search.album', // 专辑 key: 10 }, - // { - // label: '歌手', - // key: 100, - // }, { - label: '歌单', + label: 'search.search.playlist', // 歌单 key: 1000 }, - // { - // label: '用户', - // key: 1002, - // }, { - label: 'MV', + label: 'search.search.mv', // MV key: 1004 }, { - label: 'B站', + label: 'search.search.bilibili', // B站 key: 2000 } - // { - // label: '歌词', - // key: 1006, - // }, - // { - // label: '电台', - // key: 1009, - // }, - // { - // label: '视频', - // key: 1014, - // }, - // { - // label: '综合', - // key: 1018, - // }, ]; + export const SEARCH_TYPE = { MUSIC: 1, // 单曲 ALBUM: 10, // 专辑 diff --git a/src/renderer/layout/components/SearchBar.vue b/src/renderer/layout/components/SearchBar.vue index a2e2ecf..455d2a7 100644 --- a/src/renderer/layout/components/SearchBar.vue +++ b/src/renderer/layout/components/SearchBar.vue @@ -19,7 +19,7 @@
- {{ searchTypeOptions.find((item) => item.key === searchStore.searchType)?.label }} + {{ searchTypeOptions.find(item => item.key === searchStore.searchType)?.label }}
@@ -126,7 +126,6 @@ import { computed, onMounted, ref, watch, watchEffect } from 'vue'; import { useI18n } from 'vue-i18n'; import { useRouter } from 'vue-router'; - import { getSearchKeyword } from '@/api/home'; import { getUserDetail } from '@/api/login'; import alipay from '@/assets/alipay.png'; @@ -147,7 +146,7 @@ const searchStore = useSearchStore(); const settingsStore = useSettingsStore(); const userStore = useUserStore(); const userSetOptions = ref(USER_SET_OPTIONS); -const { t } = useI18n(); +const { t, locale } = useI18n(); // 使用缩放hook const { @@ -271,7 +270,15 @@ const selectSearchType = (key: number) => { } }; -const searchTypeOptions = ref(SEARCH_TYPES); +const rawSearchTypes = ref(SEARCH_TYPES) +const searchTypeOptions = computed(() => { + // 引用 locale 以创建响应式依赖 + locale.value; + return rawSearchTypes.value.map(type => ({ + label: t(type.label), + key: type.key + })) +}); const selectItem = async (key: string) => { // switch 判断