mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-07-04 06:42:09 +08:00
为搜索、歌单、排行榜的歌曲菜单添加分享“分享歌曲”按钮
This commit is contained in:
parent
0b6b15e9a8
commit
e8901864b3
@ -1,5 +1,6 @@
|
||||
### 新增
|
||||
|
||||
- 为搜索、歌单、排行榜的歌曲菜单添加分享“分享歌曲”按钮
|
||||
- 新增设置-基本设置-分享设置,它用于控制歌曲菜单的分享行为,默认使用系统分享
|
||||
|
||||
### 变更
|
||||
|
@ -10,6 +10,7 @@ import LoadingMask from '@/components/common/LoadingMask'
|
||||
import { useTranslation } from '@/plugins/i18n'
|
||||
import { Loading as FooterLoading, End as FooterEnd } from './Footer'
|
||||
import { LIST_ID_PLAY_LATER } from '@/config/constant'
|
||||
import { shareMusic } from '@/utils/tools'
|
||||
|
||||
export default memo(({
|
||||
list,
|
||||
@ -30,6 +31,8 @@ export default memo(({
|
||||
const setPlayList = useDispatch('player', 'setList')
|
||||
const setTempPlayList = useDispatch('player', 'setTempPlayList')
|
||||
const isClickPlayList = useGetter('common', 'isClickPlayList')
|
||||
const downloadFileName = useGetter('common', 'downloadFileName')
|
||||
const shareType = useGetter('common', 'shareType')
|
||||
const [buttonPosition, setButtonPosition] = useState({ w: 0, h: 0, x: 0, y: 0 })
|
||||
const selectedData = useRef({ data: null, index: -1 })
|
||||
const [visibleMenu, setVisibleMenu] = useState(false)
|
||||
@ -146,7 +149,7 @@ export default memo(({
|
||||
return [
|
||||
{ action: 'play', label: t('play') },
|
||||
{ action: 'playLater', label: t('play_later') },
|
||||
// { action: 'copyName', label: t('copy_name') },
|
||||
{ action: 'copyName', label: t('copy_name') },
|
||||
// { action: 'download', label: '下载' },
|
||||
// { action: 'add', label: '添加到...' },
|
||||
// { action: 'move', label: '移动到...' },
|
||||
@ -179,8 +182,9 @@ export default memo(({
|
||||
setTempPlayList([{ listId: LIST_ID_PLAY_LATER, musicInfo: selectedData.current.data }])
|
||||
}
|
||||
break
|
||||
// case 'copyName':
|
||||
// break
|
||||
case 'copyName':
|
||||
shareMusic(shareType, downloadFileName, selectedData.current.data)
|
||||
break
|
||||
case 'add':
|
||||
// console.log(selectedListRef.current.length)
|
||||
selectedListRef.current.length
|
||||
@ -190,7 +194,7 @@ export default memo(({
|
||||
default:
|
||||
break
|
||||
}
|
||||
}, [addMultiMusicToList, handleCancelMultiSelect, handlePlay, setTempPlayList])
|
||||
}, [addMultiMusicToList, downloadFileName, handleCancelMultiSelect, handlePlay, setTempPlayList, shareType])
|
||||
|
||||
useEffect(() => {
|
||||
if (isLoading && page == 1) {
|
||||
|
@ -10,8 +10,7 @@ import Button from '@/components/common/Button'
|
||||
import ExitMultipleModeBar from './components/ExitMultipleModeBar'
|
||||
import MyList from './components/MyList'
|
||||
import ListItem from './components/ListItem'
|
||||
import { getListScrollPosition, saveListScrollPosition, clipboardWriteText, toast } from '@/utils/tools'
|
||||
import { shareText } from '@/utils/utils'
|
||||
import { getListScrollPosition, saveListScrollPosition, shareMusic } from '@/utils/tools'
|
||||
import { useTranslation } from '@/plugins/i18n'
|
||||
import { LIST_ITEM_HEIGHT } from '@/config/constant'
|
||||
import MusicPositionModal from './components/MusicPositionModal'
|
||||
@ -19,7 +18,6 @@ import MusicPositionModal from './components/MusicPositionModal'
|
||||
import ListSearchBar from './components/ListSearchBar'
|
||||
import { debounceSearchList } from './utils'
|
||||
import { useLayout } from '@/utils/hooks'
|
||||
import music from '@/utils/music'
|
||||
// const shadow = {
|
||||
// shadowOffset: 2,
|
||||
// shadowOpacity: 0.23,
|
||||
@ -217,17 +215,7 @@ const List = () => {
|
||||
: setVisibleMusicAddModal(true)
|
||||
break
|
||||
case 'copyName':
|
||||
switch (shareType) {
|
||||
case 'system':
|
||||
shareText(t('share_card_title_music', { name: selectedDataRef.current.data.name }), t('share_title_music'), `${downloadFileName.replace('歌名', selectedDataRef.current.data.name)
|
||||
.replace('歌手', selectedDataRef.current.data.singer).replace(/\s/g, '')}\n${music[selectedDataRef.current.data.source].getMusicDetailPageUrl(selectedDataRef.current.data)}`)
|
||||
break
|
||||
case 'clipboard':
|
||||
clipboardWriteText(`${downloadFileName.replace('歌名', selectedDataRef.current.data.name)
|
||||
.replace('歌手', selectedDataRef.current.data.singer)} ${music[selectedDataRef.current.data.source].getMusicDetailPageUrl(selectedDataRef.current.data)}`)
|
||||
toast(t('copy_name_tip'))
|
||||
break
|
||||
}
|
||||
shareMusic(shareType, downloadFileName, selectedDataRef.current.data)
|
||||
break
|
||||
case 'changePosition':
|
||||
setVIsibleMusicPosition(true)
|
||||
@ -243,7 +231,7 @@ const List = () => {
|
||||
default:
|
||||
break
|
||||
}
|
||||
}, [handlePlay, shareType, setTempPlayList, handleCancelMultiSelect, t, downloadFileName, removeListMultiItem, removeListItem])
|
||||
}, [handlePlay, shareType, setTempPlayList, handleCancelMultiSelect, downloadFileName, removeListMultiItem, removeListItem])
|
||||
|
||||
const handleScroll = useCallback(({ nativeEvent }) => {
|
||||
saveListScrollPosition(currentListRef.current.id, nativeEvent.contentOffset.y)
|
||||
|
@ -6,8 +6,9 @@ import { storageDataPrefix } from '@/config'
|
||||
import { throttle } from './index'
|
||||
import { gzip, ungzip } from '@/utils/gzip'
|
||||
import { readFile, writeFile, temporaryDirectoryPath, unlink } from '@/utils/fs'
|
||||
import { isNotificationsEnabled, openNotificationPermissionActivity } from '@/utils/utils'
|
||||
import { isNotificationsEnabled, openNotificationPermissionActivity, shareText } from '@/utils/utils'
|
||||
import { i18n } from '@/plugins/i18n'
|
||||
import music from '@/utils/music'
|
||||
|
||||
const playInfoStorageKey = storageDataPrefix.playInfo
|
||||
const listPositionPrefix = storageDataPrefix.listPosition
|
||||
@ -356,6 +357,22 @@ export const resetNotificationPermissionCheck = () => {
|
||||
return removeData(notificationTipEnableKey)
|
||||
}
|
||||
|
||||
export const shareMusic = (shareType, downloadFileName, musicInfo) => {
|
||||
const name = musicInfo.name
|
||||
const singer = musicInfo.singer
|
||||
const detailUrl = music[musicInfo.source]?.getMusicDetailPageUrl(musicInfo) ?? ''
|
||||
const musicTitle = downloadFileName.replace('歌名', name).replace('歌手', singer)
|
||||
switch (shareType) {
|
||||
case 'system':
|
||||
shareText(i18n.t('share_card_title_music', { name }), i18n.t('share_title_music'), `${musicTitle.replace(/\s/g, '')} \n${detailUrl}`)
|
||||
break
|
||||
case 'clipboard':
|
||||
clipboardWriteText(`${musicTitle} ${detailUrl}`)
|
||||
toast(i18n.t('copy_name_tip'))
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
deviceLanguage,
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user