更新ts类型导入导出语法

pull/1066/head
lyswhut 2022-11-25 23:01:39 +08:00
parent 5e9b3a16fa
commit 77ea6d3748
19 changed files with 527 additions and 513 deletions

View File

@ -1,466 +1,469 @@
declare namespace LX {
type AddMusicLocationType = 'top' | 'bottom'
interface AppSetting {
version: string
/**
* id
*/
'common.windowSizeId': number
/**
* id
*/
'common.fontSize': number
/**
*
*/
'common.startInFullscreen': boolean
/**
* id
*/
'common.langId': string | null
/**
* api id
*/
'common.apiSource': string
/**
*
*/
'common.sourceNameType': 'alias' | 'real'
/**
*
*/
'common.font': string
/**
*
*/
'common.isShowAnimation': boolean
/**
*
*/
'common.randomAnimate': boolean
/**
*
*/
'common.isAgreePact': boolean
/**
*
*/
'common.controlBtnPosition': 'left' | 'right'
/**
*
*/
'player.startupAutoPlay': boolean
/**
*
*/
'player.togglePlayMethod': 'listLoop' | 'random' | 'list' | 'singleLoop' | 'none'
/**
* 320k
*/
'player.highQuality': boolean
/**
*
*/
'player.isShowTaskProgess': boolean
/**
*
*/
'player.volume': number
/**
*
*/
'player.isMute': boolean
/**
* id
*/
'player.mediaDeviceId': string
/**
*
*/
'player.isMediaDeviceRemovedStopPlay': boolean
/**
*
*/
'player.isShowLyricTranslation': boolean
/**
*
*/
'player.isShowLyricRoma': boolean
/**
*
*/
'player.isS2t': boolean
/**
* OK
*/
'player.isPlayLxlrc': boolean
/**
*
*/
'player.isSavePlayTime': boolean
/**
*
*/
'player.audioVisualization': boolean
/**
* -
*/
'player.waitPlayEndStop': boolean
/**
* -
*/
'player.waitPlayEndStopTime': string
/**
*
*/
'player.autoSkipOnError': boolean
/**
* -
*/
'playDetail.isZoomActiveLrc': boolean
/**
* -
*/
'playDetail.isShowLyricProgressSetting': boolean
/**
* -
*/
'playDetail.style.fontSize': number
/**
* -
*/
'playDetail.style.align': 'center' | 'left' | 'right'
/**
*
*/
'desktopLyric.enable': boolean
/**
*
*/
'desktopLyric.isLock': boolean
/**
*
*/
'desktopLyric.isAlwaysOnTop': boolean
/**
*
*/
'desktopLyric.isAlwaysOnTopLoop': boolean
/**
*
*/
'desktopLyric.audioVisualization': boolean
/**
*
*/
'desktopLyric.width': number
/**
*
*/
'desktopLyric.height': number
/**
* x
*/
'desktopLyric.x': number | null
/**
* y
*/
'desktopLyric.y': number | null
/**
*
*/
'desktopLyric.isLockScreen': boolean
/**
*
*/
'desktopLyric.isDelayScroll': boolean
/**
*
*/
'desktopLyric.scrollAlign': 'top' | 'center'
/**
*
*/
'desktopLyric.isHoverHide': boolean
/**
*
*/
'desktopLyric.direction': 'horizontal' | 'vertical'
/**
*
*/
'desktopLyric.style.align': 'center' | 'left' | 'right'
/**
*
*/
'desktopLyric.style.font': string
/**
*
*/
'desktopLyric.style.fontSize': number
/**
*
*/
'desktopLyric.style.lineGap': number
/**
*
*/
'desktopLyric.style.lyricUnplayColor': string
/**
*
*/
'desktopLyric.style.lyricPlayedColor': string
/**
*
*/
'desktopLyric.style.lyricShadowColor': string
/**
*
*/
// 'desktopLyric.style.fontWeight': boolean
/**
*
*/
'desktopLyric.style.opacity': number
/**
*
*/
'desktopLyric.style.ellipsis': boolean
/**
*
*/
'desktopLyric.style.isZoomActiveLrc': boolean
/**
*
*/
'list.isClickPlayList': boolean
/**
*
*/
'list.isShowSource': boolean
/**
*
*/
'list.isSaveScrollLocation': boolean
/**
*
*/
'list.addMusicLocationType': LX.AddMusicLocationType
/**
*
*/
'list.actionButtonsVisible': boolean
/**
*
*/
'download.enable': boolean
/**
*
*/
'download.savePath': string
/**
*
*/
'download.fileName': '歌名 - 歌手' | '歌手 - 歌名' | '歌名'
/**
*
*/
'download.maxDownloadNum': number
/**
* lrc
*/
'download.isDownloadLrc': boolean
/**
*
*/
'download.isDownloadTLrc': boolean
/**
*
*/
'download.isDownloadRLrc': boolean
/**
* lrc
*/
'download.lrcFormat': 'utf8' | 'gbk'
/**
*
*/
'download.isEmbedPic': boolean
/**
*
*/
'download.isEmbedLyric': boolean
/**
*
*/
'download.isUseOtherSource': boolean
/**
* id
*/
'theme.id': string
/**
* id
*/
'theme.lightId': string
/**
* id
*/
'theme.darkId': string
/**
*
*/
'search.isShowHotSearch': boolean
/**
*
*/
'search.isShowHistorySearch': boolean
/**
*
*/
'search.isFocusSearchBox': boolean
/**
*
*/
'network.proxy.enable': boolean
/**
*
*/
'network.proxy.host': string
/**
*
*/
'network.proxy.port': string
/**
*
*/
'network.proxy.username': string
/**
*
*/
'network.proxy.password': string
/**
*
*/
'tray.enable': boolean
/**
*
*/
// 'tray.isToTray': boolean
/**
* id
*/
'tray.themeId': number
/**
*
*/
'sync.enable': boolean
/**
*
*/
'sync.port': '23332' | string
/**
*
*/
'odc.isAutoClearSearchInput': boolean
/**
*
*/
'odc.isAutoClearSearchList': boolean
import type { I18n } from '@/lang/i18n'
declare global {
declare namespace LX {
type AddMusicLocationType = 'top' | 'bottom'
interface AppSetting {
version: string
/**
* id
*/
'common.windowSizeId': number
/**
* id
*/
'common.fontSize': number
/**
*
*/
'common.startInFullscreen': boolean
/**
* id
*/
'common.langId': I18n['locale'] | null
/**
* api id
*/
'common.apiSource': string
/**
*
*/
'common.sourceNameType': 'alias' | 'real'
/**
*
*/
'common.font': string
/**
*
*/
'common.isShowAnimation': boolean
/**
*
*/
'common.randomAnimate': boolean
/**
*
*/
'common.isAgreePact': boolean
/**
*
*/
'common.controlBtnPosition': 'left' | 'right'
/**
*
*/
'player.startupAutoPlay': boolean
/**
*
*/
'player.togglePlayMethod': 'listLoop' | 'random' | 'list' | 'singleLoop' | 'none'
/**
* 320k
*/
'player.highQuality': boolean
/**
*
*/
'player.isShowTaskProgess': boolean
/**
*
*/
'player.volume': number
/**
*
*/
'player.isMute': boolean
/**
* id
*/
'player.mediaDeviceId': string
/**
*
*/
'player.isMediaDeviceRemovedStopPlay': boolean
/**
*
*/
'player.isShowLyricTranslation': boolean
/**
*
*/
'player.isShowLyricRoma': boolean
/**
*
*/
'player.isS2t': boolean
/**
* OK
*/
'player.isPlayLxlrc': boolean
/**
*
*/
'player.isSavePlayTime': boolean
/**
*
*/
'player.audioVisualization': boolean
/**
* -
*/
'player.waitPlayEndStop': boolean
/**
* -
*/
'player.waitPlayEndStopTime': string
/**
*
*/
'player.autoSkipOnError': boolean
/**
* -
*/
'playDetail.isZoomActiveLrc': boolean
/**
* -
*/
'playDetail.isShowLyricProgressSetting': boolean
/**
* -
*/
'playDetail.style.fontSize': number
/**
* -
*/
'playDetail.style.align': 'center' | 'left' | 'right'
/**
*
*/
'desktopLyric.enable': boolean
/**
*
*/
'desktopLyric.isLock': boolean
/**
*
*/
'desktopLyric.isAlwaysOnTop': boolean
/**
*
*/
'desktopLyric.isAlwaysOnTopLoop': boolean
/**
*
*/
'desktopLyric.audioVisualization': boolean
/**
*
*/
'desktopLyric.width': number
/**
*
*/
'desktopLyric.height': number
/**
* x
*/
'desktopLyric.x': number | null
/**
* y
*/
'desktopLyric.y': number | null
/**
*
*/
'desktopLyric.isLockScreen': boolean
/**
*
*/
'desktopLyric.isDelayScroll': boolean
/**
*
*/
'desktopLyric.scrollAlign': 'top' | 'center'
/**
*
*/
'desktopLyric.isHoverHide': boolean
/**
*
*/
'desktopLyric.direction': 'horizontal' | 'vertical'
/**
*
*/
'desktopLyric.style.align': 'center' | 'left' | 'right'
/**
*
*/
'desktopLyric.style.font': string
/**
*
*/
'desktopLyric.style.fontSize': number
/**
*
*/
'desktopLyric.style.lineGap': number
/**
*
*/
'desktopLyric.style.lyricUnplayColor': string
/**
*
*/
'desktopLyric.style.lyricPlayedColor': string
/**
*
*/
'desktopLyric.style.lyricShadowColor': string
/**
*
*/
// 'desktopLyric.style.fontWeight': boolean
/**
*
*/
'desktopLyric.style.opacity': number
/**
*
*/
'desktopLyric.style.ellipsis': boolean
/**
*
*/
'desktopLyric.style.isZoomActiveLrc': boolean
/**
*
*/
'list.isClickPlayList': boolean
/**
*
*/
'list.isShowSource': boolean
/**
*
*/
'list.isSaveScrollLocation': boolean
/**
*
*/
'list.addMusicLocationType': LX.AddMusicLocationType
/**
*
*/
'list.actionButtonsVisible': boolean
/**
*
*/
'download.enable': boolean
/**
*
*/
'download.savePath': string
/**
*
*/
'download.fileName': '歌名 - 歌手' | '歌手 - 歌名' | '歌名'
/**
*
*/
'download.maxDownloadNum': number
/**
* lrc
*/
'download.isDownloadLrc': boolean
/**
*
*/
'download.isDownloadTLrc': boolean
/**
*
*/
'download.isDownloadRLrc': boolean
/**
* lrc
*/
'download.lrcFormat': 'utf8' | 'gbk'
/**
*
*/
'download.isEmbedPic': boolean
/**
*
*/
'download.isEmbedLyric': boolean
/**
*
*/
'download.isUseOtherSource': boolean
/**
* id
*/
'theme.id': string
/**
* id
*/
'theme.lightId': string
/**
* id
*/
'theme.darkId': string
/**
*
*/
'search.isShowHotSearch': boolean
/**
*
*/
'search.isShowHistorySearch': boolean
/**
*
*/
'search.isFocusSearchBox': boolean
/**
*
*/
'network.proxy.enable': boolean
/**
*
*/
'network.proxy.host': string
/**
*
*/
'network.proxy.port': string
/**
*
*/
'network.proxy.username': string
/**
*
*/
'network.proxy.password': string
/**
*
*/
'tray.enable': boolean
/**
*
*/
// 'tray.isToTray': boolean
/**
* id
*/
'tray.themeId': number
/**
*
*/
'sync.enable': boolean
/**
*
*/
'sync.port': '23332' | string
/**
*
*/
'odc.isAutoClearSearchInput': boolean
/**
*
*/
'odc.isAutoClearSearchList': boolean
}
}
}
}

View File

@ -75,9 +75,6 @@ export {
unref,
onMounted,
markRaw,
ComputedRef,
Ref,
ShallowRef,
defineProps,
defineEmits,
defineComponent,
@ -85,3 +82,9 @@ export {
defineExpose,
withDefaults,
}
export type {
ComputedRef,
Ref,
ShallowRef,
}

View File

@ -1,22 +1,24 @@
import { App, ref } from 'vue'
import { messages, Messages, Message } from './index'
import { messages } from './index'
import type { Messages, Message } from './index'
type TranslateValues = Record<string, string | number | boolean>
type Langs = keyof Messages
export declare interface I18n {
locale: keyof Messages
fallbackLocale: keyof Messages
availableLocales: Array<keyof Messages>
locale: Langs
fallbackLocale: Langs
availableLocales: Langs[]
messages: Messages
message: Message
setLanguage: (locale: string) => void
setLanguage: (locale: Langs) => void
fillMessage: (message: string, val: TranslateValues) => string
getMessage: (key: keyof Message, val?: TranslateValues) => string
t: (key: keyof Message, val?: TranslateValues) => string
}
const locale = ref('zh-cn')
const locale = ref<Langs>('zh-cn')
let i18n: I18n
@ -47,7 +49,7 @@ const useI18n = () => {
}
}
const setLanguage = (lang: string) => {
const setLanguage = (lang: Langs) => {
i18n.setLanguage(lang)
}
@ -55,10 +57,10 @@ const createI18n = (): I18n => {
return i18n = {
locale: locale.value,
fallbackLocale: 'zh-cn',
availableLocales: Object.keys(messages),
availableLocales: Object.keys(messages) as Langs[],
messages,
message: messages[locale.value],
setLanguage(_locale: string) {
setLanguage(_locale: Langs) {
this.locale = _locale
this.message = messages[_locale]
locale.value = _locale
@ -74,7 +76,7 @@ const createI18n = (): I18n => {
return val ? this.fillMessage(targetMessage, val) : targetMessage
},
t(key: keyof Message, val?: TranslateValues): string {
trackReactivityValues()
// trackReactivityValues()
return this.getMessage(key, val)
},
}

View File

@ -6,20 +6,13 @@ type Message = Record<keyof typeof zh_cn, string>
| Record<keyof typeof zh_tw, string>
| Record<keyof typeof en_us, string>
interface Lang {
name: string
locale: string
alternate?: string
country: string
fallback?: boolean
message: Message
}
type Messages = Record<(typeof langs)[number]['locale'], Message>
const langs: Lang[] = [
const langs = [
{
name: '简体中文',
locale: 'zh-cn',
alternate: 'zh-hans',
// alternate: 'zh-hans',
country: 'cn',
fallback: true,
message: zh_cn,
@ -27,7 +20,7 @@ const langs: Lang[] = [
{
name: '繁体中文',
locale: 'zh-tw',
alternate: 'zh-hk',
// alternate: 'zh-hk',
country: 'cn',
message: zh_tw,
},
@ -37,20 +30,20 @@ const langs: Lang[] = [
country: 'us',
message: en_us,
},
]
] as const
const langList: Array<{
name: string
locale: string
locale: keyof Messages
alternate?: string
}> = []
type Messages = Record<string, Message>
// @ts-expect-error
const messages: Messages = {}
langs.forEach(item => {
langList.push({
name: item.name,
locale: item.locale,
alternate: item.alternate,
// alternate: item.alternate,
})
messages[item.locale] = item.message
})
@ -58,6 +51,9 @@ langs.forEach(item => {
export {
langList,
messages,
}
export type {
Messages,
Message,
}

View File

@ -1,7 +1,7 @@
import { Event as App, Type as AppType } from './AppEvent'
import { Event as List, Type as ListType } from './ListEvent'
export {
export type {
AppType,
ListType,
}

View File

@ -1,9 +1,11 @@
import { createI18n, i18nPlugin, useI18n, I18n } from '@/lang'
import type { I18n } from '@/lang'
import { createI18n, i18nPlugin, useI18n } from '@/lang'
window.i18n = createI18n()
export {
i18nPlugin,
useI18n,
I18n,
}
export type { I18n }

View File

@ -225,3 +225,4 @@
// getScrollTop,
// }
// }
export {}

View File

@ -14,7 +14,7 @@ const initPrevPlayInfo = async() => {
window.lx.restorePlayInfo = null
if (!info?.listId || info.index < 0) return
const list = await getListMusics(info.listId)
if (!list?.[info.index]) return
if (!list[info.index]) return
window.lx.restorePlayInfo = info
playList(info.listId, info.index)

View File

@ -39,7 +39,9 @@ export const registerEvents = () => {
// // unregisterRendererEvents()
// }
export { AppEventTypes } from './appEvent'
export { KeyEventTypes, clearDownKeys } from './keyEvent'
export { clearDownKeys } from './keyEvent'
export type { AppEventTypes } from './appEvent'
export type { KeyEventTypes } from './keyEvent'
registerEvents()

View File

@ -19,6 +19,8 @@ import router from './router'
import { getSetting, updateSetting } from './utils/ipc'
import { langList } from '@/lang'
import type { I18n } from '@/lang/i18n'
import { initSetting } from './store/setting'
// import { bubbleCursor } from './utils/cursor-effects/bubbleCursor'
@ -40,8 +42,8 @@ void getSetting().then(setting => {
// window.lx.appSetting = setting
// Set language automatically
if (!setting['common.langId'] || !window.i18n.availableLocales.includes(setting['common.langId'])) {
let langId = null
let locale = window.navigator.language.toLocaleLowerCase()
let langId: I18n['locale'] | null = null
let locale = window.navigator.language.toLocaleLowerCase() as I18n['locale']
if (window.i18n.availableLocales.includes(locale)) {
langId = locale
} else {

View File

@ -1,9 +1,11 @@
import { createI18n, i18nPlugin, useI18n, I18n } from '@/lang'
import type { I18n } from '@/lang'
import { createI18n, i18nPlugin, useI18n } from '@/lang'
window.i18n = createI18n()
export {
i18nPlugin,
useI18n,
I18n,
}
export type { I18n }

View File

@ -17,7 +17,7 @@ export const setUserLists = (lists: LX.List.UserListInfo[]) => {
export const setMusicList = (listId: string, musicList: LX.Music.MusicInfo[]) => {
const list = shallowReactive(markRawList(musicList))
allMusicList.set(listId, shallowReactive(musicList))
allMusicList.set(listId, list)
return list
}

View File

@ -2,7 +2,8 @@ import { markRawList } from '@common/utils/vueTools'
import music from '@renderer/utils/musicSdk'
import { sortInsert, similar } from '@common/utils/common'
import { sources, maxPages, listInfos, ListInfoItem, SearchListInfo } from './state'
import type { ListInfoItem, SearchListInfo } from './state'
import { sources, maxPages, listInfos } from './state'
interface SearchResult {
list: ListInfoItem[]

View File

@ -5,7 +5,7 @@ import music from '@renderer/utils/musicSdk'
import { ListInfo } from '@renderer/store/songList/state'
export { ListInfoItem } from '@renderer/store/songList/state'
export type { ListInfoItem } from '@renderer/store/songList/state'
export const sources: Array<LX.OnlineSource | 'all'> = markRaw([])

View File

@ -2,14 +2,12 @@
import { deduplicationList, toNewMusicInfo } from '@renderer/utils'
import musicSdk from '@renderer/utils/musicSdk'
import { markRaw, markRawList } from '@common/utils/vueTools'
import type { ListDetailInfo, ListInfoItem, ListInfo } from './state'
import {
tags,
TagInfo,
listInfo,
listDetailInfo,
ListDetailInfo,
ListInfoItem,
ListInfo,
selectListInfo,
isVisibleListDetail,
openSongListInputInfo,

View File

@ -53,7 +53,7 @@ export const getFontSizeWithScreen = (screenWidth: number = window.innerWidth):
export const deduplicationList = <T extends LX.Music.MusicInfo>(list: T[]): T[] => {
const ids: Set<string | number> = new Set()
const ids: Set<string> = new Set()
return list.filter(s => {
if (ids.has(s.id)) return false
ids.add(s.id)

View File

@ -3,7 +3,8 @@ import { ref, nextTick } from '@common/utils/vueTools'
import { addHistoryWord } from '@renderer/store/search/action'
// import { useI18n } from '@renderer/plugins/i18n'
// import { } from '@renderer/store/search/state'
import { search as searchSongList, listInfos, SearchListInfo, ListInfoItem } from '@renderer/store/search/songlist'
import type { SearchListInfo, ListInfoItem } from '@renderer/store/search/songlist'
import { search as searchSongList, listInfos } from '@renderer/store/search/songlist'
export declare type SearchSource = LX.OnlineSource | 'all'

View File

@ -34,7 +34,7 @@
<script setup lang="ts">
import { ref, defineEmits, defineExpose } from '@common/utils/vueTools'
import { ListInfo, ListInfoItem } from '@renderer/store/songList/state'
import type { ListInfo, ListInfoItem } from '@renderer/store/songList/state'
// import LX from '@renderer/types/lx'
import { useRoute, useRouter } from '@common/utils/vueRouter'

View File

@ -1,4 +1,5 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
@ -82,7 +83,7 @@
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
"isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
"allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": false, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */