index.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { computed, defineComponent, reactive } from 'vue'
  2. import styles from './index.module.less'
  3. import { Icon, Popup } from 'vant'
  4. import ChoosePartName from './choosePartName'
  5. import state from '/src/pages/detail/state'
  6. import runtime, * as RuntimeUtils from '/src/pages/detail/runtime'
  7. import qs from 'query-string'
  8. import { useOriginSearch } from '../../uses'
  9. import { getInstrumentName } from '../../helpers/instruments'
  10. export const toggleMusicSheet = reactive({
  11. show: false,
  12. toggle: (type = true) => {
  13. toggleMusicSheet.show = type
  14. },
  15. })
  16. export default defineComponent({
  17. name: 'ToggleMusicSheet',
  18. setup() {
  19. const search = useOriginSearch()
  20. const partListNames = computed(() => {
  21. let partList = state.activeDetail?.background || []
  22. partList = partList.filter((item: any) => !item.track?.toLocaleUpperCase()?.includes('COMMON'))
  23. return partList.map((item: any, index: number) => {
  24. const instrumentName = getInstrumentName(item.track)
  25. return {
  26. text: item.track + (instrumentName ? `(${instrumentName})` : ''),
  27. value: index,
  28. }
  29. }).filter(Boolean)
  30. })
  31. const switchMusic = (index: number) => {
  32. // 暂停播放
  33. RuntimeUtils.pause()
  34. // 销毁播放器
  35. postMessage({
  36. api: 'cloudDestroy',
  37. })
  38. postMessage({
  39. api: 'cloudLoading',
  40. content: {
  41. show: true,
  42. type: 'fullscreen',
  43. },
  44. })
  45. const _url =
  46. location.origin +
  47. location.pathname +
  48. '?' +
  49. qs.stringify({
  50. ...search,
  51. behaviorId: sessionStorage.getItem('behaviorId') || '',
  52. _t: new Date().valueOf(),
  53. 'part-index': index,
  54. })
  55. console.log(_url)
  56. location.href = _url
  57. }
  58. return () => (
  59. <Popup class={styles.popup} v-model:show={toggleMusicSheet.show}>
  60. <ChoosePartName
  61. partIndex={state.partIndex}
  62. partListNames={partListNames.value}
  63. onClose={(value) => {
  64. console.log("🚀 ~ value:", value)
  65. toggleMusicSheet.show = false
  66. if (value !== undefined) {
  67. switchMusic(value)
  68. }
  69. }}
  70. />
  71. </Popup>
  72. )
  73. },
  74. })