diff --git a/src/renderer/core/useApp/compositions/usePlaySonglist.ts b/src/renderer/core/useApp/compositions/usePlaySonglist.ts index 35c77228..4acd5048 100644 --- a/src/renderer/core/useApp/compositions/usePlaySonglist.ts +++ b/src/renderer/core/useApp/compositions/usePlaySonglist.ts @@ -21,7 +21,7 @@ export default () => { const id = decodeURIComponent(link) const playListId = `${source}__${decodeURIComponent(link)}` let list = (await getListDetail(id, source, 1)).list - if (playIndex != null && list.length > playIndex) { + if (playIndex == null || list.length > playIndex) { isPlayingList = true await setTempList(playListId, list) playList(tempList.id, getListPlayIndex(list, playIndex)) diff --git a/src/renderer/core/useApp/index.ts b/src/renderer/core/useApp/index.ts index 459d9343..b4fc5436 100644 --- a/src/renderer/core/useApp/index.ts +++ b/src/renderer/core/useApp/index.ts @@ -6,7 +6,7 @@ import { appSetting } from '@renderer/store/setting' import useSync from './useSync' import useUpdate from './useUpdate' import useDataInit from './useDataInit' -// import useHandleEnvParams from './useHandleEnvParams' +import useHandleEnvParams from './useHandleEnvParams' import useEventListener from './useEventListener' import useDeeplink from './useDeeplink' import usePlayer from './usePlayer' @@ -29,7 +29,7 @@ export default () => { const initSyncService = useSync() useEventListener() const initPlayer = usePlayer() - // const handleEnvParams = useHandleEnvParams() + const handleEnvParams = useHandleEnvParams() const initData = useDataInit() const initDeeplink = useDeeplink() // const handleListAutoUpdate = useListAutoUpdate() @@ -61,7 +61,7 @@ export default () => { // 初始化我的列表、下载列表等数据 void initData().then(() => { initPlayer() - // handleEnvParams(envParams) // 处理传入的启动参数 + handleEnvParams(envParams) // 处理传入的启动参数 void initDeeplink(envParams) void initSyncService() handleListAutoUpdate() diff --git a/src/renderer/core/useApp/useDeeplink/useMusicAction.js b/src/renderer/core/useApp/useDeeplink/useMusicAction.js index 43632d83..4ad1e7ff 100644 --- a/src/renderer/core/useApp/useDeeplink/useMusicAction.js +++ b/src/renderer/core/useApp/useDeeplink/useMusicAction.js @@ -37,13 +37,15 @@ const useSearchMusic = () => { if (isShowPlayerDetail.value) setShowPlayerDetail(false) const sourceList = [...sources, 'all'] source = sourceList.includes(source) ? source : null - router.replace({ - path: '/search', - query: { - text, - source, - }, - }) + setTimeout(() => { + router.replace({ + path: '/search', + query: { + text, + source, + }, + }) + }, 500) focusWindow() } } diff --git a/src/renderer/core/useApp/useHandleEnvParams.ts b/src/renderer/core/useApp/useHandleEnvParams.ts index e54b1c72..ff94e742 100644 --- a/src/renderer/core/useApp/useHandleEnvParams.ts +++ b/src/renderer/core/useApp/useHandleEnvParams.ts @@ -1,90 +1,89 @@ -// import { useRouter } from '@common/utils/vueTools' -// import { parseUrlParams } from '@common/utils/renderer' -// import { defaultList, loveList, userLists } from '@renderer/store/list' -// import { getList } from '@renderer/store/utils' -// import usePlaySonglist from './compositions/usePlaySonglist' -// import { setPlayList } from '@renderer/store/player' +import { useRouter } from '@common/utils/vueRouter' +import { parseUrlParams } from '@common/utils/common' +import { defaultList, loveList, userLists } from '@renderer/store/list/state' +import { getListMusics } from '@renderer/store/list/action' +import usePlaySonglist from './compositions/usePlaySonglist' +import { playList } from '@renderer/core/player' -// const getListPlayIndex = (list: LX.Music.MusicInfo[], indexStr?: string): number => { -// let index: number -// if (indexStr == null) { -// index = 1 -// } else { -// index = parseInt(indexStr) -// if (Number.isNaN(index)) { -// index = 1 -// } else { -// if (index < 1) index = 1 -// else if (index > list.length) index = list.length -// } -// } -// return index - 1 -// } +const getListPlayIndex = (list: LX.Music.MusicInfo[], indexStr?: string): number => { + let index: number + if (indexStr == null) { + index = 1 + } else { + index = parseInt(indexStr) + if (Number.isNaN(index)) { + index = 1 + } else { + if (index < 1) index = 1 + else if (index > list.length) index = list.length + } + } + return index - 1 +} -// const useInitEnvParamSearch = () => { -// const router = useRouter() +const useInitEnvParamSearch = () => { + const router = useRouter() -// return (search?: string) => { -// if (search == null) return -// void router.push({ -// path: 'search', -// query: { -// text: search, -// }, -// }) -// } -// } -// const useInitEnvParamPlay = () => { -// // const setPlayList = useCommit('player', 'setList') + return (search?: string) => { + if (search == null) return + setTimeout(() => { + void router.replace({ + path: '/search', + query: { + text: search, + }, + }) + }, 1000) + } +} +const useInitEnvParamPlay = () => { + // const setPlayList = useCommit('player', 'setList') -// const playSongListDetail = usePlaySonglist() + const playSongListDetail = usePlaySonglist() -// return (playStr?: string) => { -// if (playStr == null || typeof playStr != 'string') return -// // -play="source=kw&link=链接、ID" -// // -play="source=myList&name=名字" -// // -play="source=myList&name=名字&index=位置" -// const params = parseUrlParams(playStr) -// if (params.type != 'songList') return -// switch (params.source) { -// case 'myList': -// if (params.name != null) { -// let targetList -// const lists = [defaultList, loveList, ...userLists] -// for (const list of lists) { -// if (list.name === params.name) { -// targetList = list -// break -// } -// } -// if (!targetList) return + return async(playStr?: string) => { + if (playStr == null || typeof playStr != 'string') return + // -play="source=kw&link=链接、ID" + // -play="source=myList&name=名字" + // -play="source=myList&name=名字&index=位置" + const params = parseUrlParams(playStr) + if (params.type != 'songList') return + switch (params.source) { + case 'myList': + if (params.name != null) { + let targetList + const lists = [defaultList, loveList, ...userLists] + for (const list of lists) { + if (list.name === params.name) { + targetList = list + break + } + } + if (!targetList) return -// setPlayList({ -// listId: targetList.id, -// index: getListPlayIndex(getList(targetList.id), params.index), -// }) -// } -// break -// case 'kw': -// case 'kg': -// case 'tx': -// case 'mg': -// case 'wy': -// playSongListDetail(params.source, params.link, params.index) -// break -// } -// } -// } + playList(targetList.id, getListPlayIndex(await getListMusics(targetList.id), params.index)) + } + break + case 'kw': + case 'kg': + case 'tx': + case 'mg': + case 'wy': + void playSongListDetail(params.source, params.link, parseInt(params.index)) + break + } + } +} -// export default () => { -// // 处理启动参数 search -// const initEnvParamSearch = useInitEnvParamSearch() +export default () => { + // 处理启动参数 search + const initEnvParamSearch = useInitEnvParamSearch() -// // 处理启动参数 play -// const initEnvParamPlay = useInitEnvParamPlay() + // 处理启动参数 play + const initEnvParamPlay = useInitEnvParamPlay() -// return (envParams: LX.EnvParams) => { -// initEnvParamSearch(envParams.cmdParams.search) -// initEnvParamPlay(envParams.cmdParams.play) -// } -// } + return (envParams: LX.EnvParams) => { + initEnvParamSearch(envParams.cmdParams.search) + void initEnvParamPlay(envParams.cmdParams.play) + } +} diff --git a/src/renderer/views/Search/components/BlankView.vue b/src/renderer/views/Search/components/BlankView.vue index 7dbe78b9..5f021045 100644 --- a/src/renderer/views/Search/components/BlankView.vue +++ b/src/renderer/views/Search/components/BlankView.vue @@ -66,7 +66,7 @@ if (appSetting['search.isShowHistorySearch']) { const router = useRouter() const handleSearch = (text) => { router.replace({ - path: 'search', + path: '/search', query: { text, },