mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-07-04 12:12: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 { useTranslation } from '@/plugins/i18n'
|
||||||
import { Loading as FooterLoading, End as FooterEnd } from './Footer'
|
import { Loading as FooterLoading, End as FooterEnd } from './Footer'
|
||||||
import { LIST_ID_PLAY_LATER } from '@/config/constant'
|
import { LIST_ID_PLAY_LATER } from '@/config/constant'
|
||||||
|
import { shareMusic } from '@/utils/tools'
|
||||||
|
|
||||||
export default memo(({
|
export default memo(({
|
||||||
list,
|
list,
|
||||||
@ -30,6 +31,8 @@ export default memo(({
|
|||||||
const setPlayList = useDispatch('player', 'setList')
|
const setPlayList = useDispatch('player', 'setList')
|
||||||
const setTempPlayList = useDispatch('player', 'setTempPlayList')
|
const setTempPlayList = useDispatch('player', 'setTempPlayList')
|
||||||
const isClickPlayList = useGetter('common', 'isClickPlayList')
|
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 [buttonPosition, setButtonPosition] = useState({ w: 0, h: 0, x: 0, y: 0 })
|
||||||
const selectedData = useRef({ data: null, index: -1 })
|
const selectedData = useRef({ data: null, index: -1 })
|
||||||
const [visibleMenu, setVisibleMenu] = useState(false)
|
const [visibleMenu, setVisibleMenu] = useState(false)
|
||||||
@ -146,7 +149,7 @@ export default memo(({
|
|||||||
return [
|
return [
|
||||||
{ action: 'play', label: t('play') },
|
{ action: 'play', label: t('play') },
|
||||||
{ action: 'playLater', label: t('play_later') },
|
{ action: 'playLater', label: t('play_later') },
|
||||||
// { action: 'copyName', label: t('copy_name') },
|
{ action: 'copyName', label: t('copy_name') },
|
||||||
// { action: 'download', label: '下载' },
|
// { action: 'download', label: '下载' },
|
||||||
// { action: 'add', label: '添加到...' },
|
// { action: 'add', label: '添加到...' },
|
||||||
// { action: 'move', label: '移动到...' },
|
// { action: 'move', label: '移动到...' },
|
||||||
@ -179,8 +182,9 @@ export default memo(({
|
|||||||
setTempPlayList([{ listId: LIST_ID_PLAY_LATER, musicInfo: selectedData.current.data }])
|
setTempPlayList([{ listId: LIST_ID_PLAY_LATER, musicInfo: selectedData.current.data }])
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
// case 'copyName':
|
case 'copyName':
|
||||||
// break
|
shareMusic(shareType, downloadFileName, selectedData.current.data)
|
||||||
|
break
|
||||||
case 'add':
|
case 'add':
|
||||||
// console.log(selectedListRef.current.length)
|
// console.log(selectedListRef.current.length)
|
||||||
selectedListRef.current.length
|
selectedListRef.current.length
|
||||||
@ -190,7 +194,7 @@ export default memo(({
|
|||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}, [addMultiMusicToList, handleCancelMultiSelect, handlePlay, setTempPlayList])
|
}, [addMultiMusicToList, downloadFileName, handleCancelMultiSelect, handlePlay, setTempPlayList, shareType])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isLoading && page == 1) {
|
if (isLoading && page == 1) {
|
||||||
|
@ -10,8 +10,7 @@ import Button from '@/components/common/Button'
|
|||||||
import ExitMultipleModeBar from './components/ExitMultipleModeBar'
|
import ExitMultipleModeBar from './components/ExitMultipleModeBar'
|
||||||
import MyList from './components/MyList'
|
import MyList from './components/MyList'
|
||||||
import ListItem from './components/ListItem'
|
import ListItem from './components/ListItem'
|
||||||
import { getListScrollPosition, saveListScrollPosition, clipboardWriteText, toast } from '@/utils/tools'
|
import { getListScrollPosition, saveListScrollPosition, shareMusic } from '@/utils/tools'
|
||||||
import { shareText } from '@/utils/utils'
|
|
||||||
import { useTranslation } from '@/plugins/i18n'
|
import { useTranslation } from '@/plugins/i18n'
|
||||||
import { LIST_ITEM_HEIGHT } from '@/config/constant'
|
import { LIST_ITEM_HEIGHT } from '@/config/constant'
|
||||||
import MusicPositionModal from './components/MusicPositionModal'
|
import MusicPositionModal from './components/MusicPositionModal'
|
||||||
@ -19,7 +18,6 @@ import MusicPositionModal from './components/MusicPositionModal'
|
|||||||
import ListSearchBar from './components/ListSearchBar'
|
import ListSearchBar from './components/ListSearchBar'
|
||||||
import { debounceSearchList } from './utils'
|
import { debounceSearchList } from './utils'
|
||||||
import { useLayout } from '@/utils/hooks'
|
import { useLayout } from '@/utils/hooks'
|
||||||
import music from '@/utils/music'
|
|
||||||
// const shadow = {
|
// const shadow = {
|
||||||
// shadowOffset: 2,
|
// shadowOffset: 2,
|
||||||
// shadowOpacity: 0.23,
|
// shadowOpacity: 0.23,
|
||||||
@ -217,17 +215,7 @@ const List = () => {
|
|||||||
: setVisibleMusicAddModal(true)
|
: setVisibleMusicAddModal(true)
|
||||||
break
|
break
|
||||||
case 'copyName':
|
case 'copyName':
|
||||||
switch (shareType) {
|
shareMusic(shareType, downloadFileName, selectedDataRef.current.data)
|
||||||
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
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
case 'changePosition':
|
case 'changePosition':
|
||||||
setVIsibleMusicPosition(true)
|
setVIsibleMusicPosition(true)
|
||||||
@ -243,7 +231,7 @@ const List = () => {
|
|||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}, [handlePlay, shareType, setTempPlayList, handleCancelMultiSelect, t, downloadFileName, removeListMultiItem, removeListItem])
|
}, [handlePlay, shareType, setTempPlayList, handleCancelMultiSelect, downloadFileName, removeListMultiItem, removeListItem])
|
||||||
|
|
||||||
const handleScroll = useCallback(({ nativeEvent }) => {
|
const handleScroll = useCallback(({ nativeEvent }) => {
|
||||||
saveListScrollPosition(currentListRef.current.id, nativeEvent.contentOffset.y)
|
saveListScrollPosition(currentListRef.current.id, nativeEvent.contentOffset.y)
|
||||||
|
@ -6,8 +6,9 @@ import { storageDataPrefix } from '@/config'
|
|||||||
import { throttle } from './index'
|
import { throttle } from './index'
|
||||||
import { gzip, ungzip } from '@/utils/gzip'
|
import { gzip, ungzip } from '@/utils/gzip'
|
||||||
import { readFile, writeFile, temporaryDirectoryPath, unlink } from '@/utils/fs'
|
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 { i18n } from '@/plugins/i18n'
|
||||||
|
import music from '@/utils/music'
|
||||||
|
|
||||||
const playInfoStorageKey = storageDataPrefix.playInfo
|
const playInfoStorageKey = storageDataPrefix.playInfo
|
||||||
const listPositionPrefix = storageDataPrefix.listPosition
|
const listPositionPrefix = storageDataPrefix.listPosition
|
||||||
@ -356,6 +357,22 @@ export const resetNotificationPermissionCheck = () => {
|
|||||||
return removeData(notificationTipEnableKey)
|
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 {
|
export {
|
||||||
deviceLanguage,
|
deviceLanguage,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user