优化代码

This commit is contained in:
lyswhut 2023-03-30 09:09:34 +08:00
parent b481d0367f
commit b5201495f1
8 changed files with 15 additions and 20 deletions

View File

@ -160,7 +160,7 @@ export const getOnlineOtherSourceMusicUrl = async({ musicInfos, quality, onToggl
if (retryedSource.includes(musicInfo.source)) continue if (retryedSource.includes(musicInfo.source)) continue
retryedSource.push(musicInfo.source) retryedSource.push(musicInfo.source)
if (!assertApiSupport(musicInfo.source)) continue if (!assertApiSupport(musicInfo.source)) continue
itemQuality = quality ?? getPlayQuality(settingState.setting['player.highQuality'], musicInfo) itemQuality = quality ?? getPlayQuality(settingState.setting['player.isPlayHighQuality'], musicInfo)
if (!musicInfo.meta._qualitys[itemQuality]) continue if (!musicInfo.meta._qualitys[itemQuality]) continue
console.log('try toggle to: ', musicInfo.source, musicInfo.name, musicInfo.singer, musicInfo.interval) console.log('try toggle to: ', musicInfo.source, musicInfo.name, musicInfo.singer, musicInfo.interval)
@ -205,7 +205,7 @@ export const handleGetOnlineMusicUrl = async({ musicInfo, quality, onToggleSourc
isFromCache: boolean isFromCache: boolean
}> => { }> => {
// console.log(musicInfo.source) // console.log(musicInfo.source)
const targetQuality = quality ?? getPlayQuality(settingState.setting['player.highQuality'], musicInfo) const targetQuality = quality ?? getPlayQuality(settingState.setting['player.isPlayHighQuality'], musicInfo)
let reqPromise let reqPromise
try { try {

View File

@ -67,7 +67,7 @@ const getMusicPlayUrl = async(musicInfo: LX.Music.MusicInfo | LX.Download.ListIt
// this.musicInfo.url = await getMusicPlayUrl(targetSong, type) // this.musicInfo.url = await getMusicPlayUrl(targetSong, type)
setStatusText(global.i18n.t('player__geting_url')) setStatusText(global.i18n.t('player__geting_url'))
// const type = getPlayType(settingState.setting['player.highQuality'], musicInfo) // const type = getPlayType(settingState.setting['player.isPlayHighQuality'], musicInfo)
return getMusicUrl({ return getMusicUrl({
musicInfo, musicInfo,

View File

@ -106,8 +106,8 @@ export class StateEvent extends Event {
this.emit('componentIdsUpdated', ids) this.emit('componentIdsUpdated', ids)
} }
navActiveIdUpdated(index: CommonState['navActiveId']) { navActiveIdUpdated(id: CommonState['navActiveId']) {
this.emit('navActiveIdUpdated', index) this.emit('navActiveIdUpdated', id)
} }
sourceNamesUpdated(names: CommonState['sourceNames']) { sourceNamesUpdated(names: CommonState['sourceNames']) {

View File

@ -5,23 +5,22 @@ import { Icon } from '@/components/common/Icon'
import { pop } from '@/navigation' import { pop } from '@/navigation'
// import { AppColors } from '@/theme' // import { AppColors } from '@/theme'
import StatusBar from '@/components/common/StatusBar' import StatusBar from '@/components/common/StatusBar'
import { useComponentIds } from '@/store/common/hook'
import { useI18n } from '@/lang' import { useI18n } from '@/lang'
import { createStyle } from '@/utils/tools' import { createStyle } from '@/utils/tools'
import Text from '@/components/common/Text' import Text from '@/components/common/Text'
import { HEADER_HEIGHT as _HEADER_HEIGHT } from '@/config/constant' import { HEADER_HEIGHT as _HEADER_HEIGHT } from '@/config/constant'
import { scaleSizeH } from '@/utils/pixelRatio' import { scaleSizeH } from '@/utils/pixelRatio'
import commonState from '@/store/common/state'
const HEADER_HEIGHT = scaleSizeH(_HEADER_HEIGHT) const HEADER_HEIGHT = scaleSizeH(_HEADER_HEIGHT)
export default memo(({ musicInfo }: { export default memo(({ musicInfo }: {
musicInfo: LX.Music.MusicInfo musicInfo: LX.Music.MusicInfo
}) => { }) => {
const componentIds = useComponentIds()
const t = useI18n() const t = useI18n()
const back = () => { const back = () => {
void pop(componentIds.comment as string) void pop(commonState.componentIds.comment as string)
} }
return ( return (

View File

@ -31,7 +31,7 @@ export default () => {
// setWidth(getWindowSise().width * 0.82) // setWidth(getWindowSise().width * 0.82)
global.app_event.on('homeNavPagerChanged', handleFixDrawer) global.state_event.on('navActiveIdUpdated', handleFixDrawer)
global.app_event.on('changeLoveListVisible', changeVisible) global.app_event.on('changeLoveListVisible', changeVisible)
// 就放旋转屏幕后的宽度没有更新的问题 // 就放旋转屏幕后的宽度没有更新的问题
@ -43,7 +43,7 @@ export default () => {
// }) // })
return () => { return () => {
global.app_event.off('homeNavPagerChanged', handleFixDrawer) global.state_event.off('navActiveIdUpdated', handleFixDrawer)
global.app_event.off('changeLoveListVisible', changeVisible) global.app_event.off('changeLoveListVisible', changeVisible)
// changeEvent.remove() // changeEvent.remove()
} }

View File

@ -27,12 +27,12 @@ export default () => {
drawer.current?.closeDrawer() drawer.current?.closeDrawer()
} }
global.app_event.on('homeNavPagerChanged', handleFixDrawer) global.state_event.on('navActiveIdUpdated', handleFixDrawer)
global.app_event.on('showSonglistTagList', handleShow) global.app_event.on('showSonglistTagList', handleShow)
global.app_event.on('hideSonglistTagList', handleHide) global.app_event.on('hideSonglistTagList', handleHide)
return () => { return () => {
global.app_event.off('homeNavPagerChanged', handleFixDrawer) global.state_event.off('navActiveIdUpdated', handleFixDrawer)
global.app_event.off('showSonglistTagList', handleShow) global.app_event.off('showSonglistTagList', handleShow)
global.app_event.off('hideSonglistTagList', handleHide) global.app_event.off('hideSonglistTagList', handleHide)
} }

View File

@ -1,14 +1,12 @@
import React from 'react' import React from 'react'
import Btn from './Btn' import Btn from './Btn'
import { useComponentIds } from '@/store/common/hook'
import { navigations } from '@/navigation' import { navigations } from '@/navigation'
import commonState from '@/store/common/state'
export default () => { export default () => {
const componentIds = useComponentIds()
const handleShowCommentScreen = () => { const handleShowCommentScreen = () => {
navigations.pushCommentScreen(componentIds.playDetail as string) navigations.pushCommentScreen(commonState.componentIds.playDetail as string)
} }
return <Btn icon="comment" onPress={handleShowCommentScreen} /> return <Btn icon="comment" onPress={handleShowCommentScreen} />

View File

@ -1,14 +1,12 @@
import React from 'react' import React from 'react'
import Btn from './Btn' import Btn from './Btn'
import { useComponentIds } from '@/store/common/hook'
import { navigations } from '@/navigation' import { navigations } from '@/navigation'
import commonState from '@/store/common/state'
export default () => { export default () => {
const componentIds = useComponentIds()
const handleShowCommentScreen = () => { const handleShowCommentScreen = () => {
navigations.pushCommentScreen(componentIds.playDetail as string) navigations.pushCommentScreen(commonState.componentIds.playDetail as string)
} }
return <Btn icon="comment" onPress={handleShowCommentScreen} /> return <Btn icon="comment" onPress={handleShowCommentScreen} />