index.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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, { togglePlay } from "/src/state";
  6. import qs from 'query-string'
  7. import { getInstrumentName, sortMusical } from "/src/constant/instruments";
  8. import { getQuery } from "/src/utils/queryString";
  9. export const toggleMusicSheet = reactive({
  10. show: false,
  11. toggle: (type = true) => {
  12. toggleMusicSheet.show = type
  13. },
  14. })
  15. export default defineComponent({
  16. name: 'ToggleMusicSheet',
  17. setup() {
  18. const query = getQuery();
  19. const partListNames = computed(() => {
  20. let partList = state.partListNames || []
  21. partList = partList.filter((item: any) => !item?.toLocaleUpperCase()?.includes('COMMON'))
  22. const arr = partList.map((item: any, index: number) => {
  23. // 该声轨能否被选
  24. const canselect = state.canSelectTracks.length == 0 || state.canSelectTracks.includes(item) ? true : false
  25. // console.log(canselect,index)
  26. const instrumentName = getInstrumentName(item)
  27. const sortId = sortMusical(instrumentName, index)
  28. return {
  29. text: item + (instrumentName ? `(${instrumentName})` : ''),
  30. value: index,
  31. sortId,
  32. canselect
  33. }
  34. }).filter((item: any) => item.canselect).sort((a: any, b: any) => a.sortId - b.sortId)
  35. return arr
  36. })
  37. const trackIdx: any = computed(() => {
  38. if (partListNames && partListNames.value.length) {
  39. const idx = partListNames.value.find((item: any) => item.value == state.partIndex).value
  40. console.log(3333,idx)
  41. return idx
  42. } else {
  43. return 0
  44. }
  45. })
  46. const switchMusic = (index: number) => {
  47. if (state.partIndex === index) return
  48. // 暂停播放
  49. togglePlay("paused");
  50. // 销毁播放器
  51. postMessage({
  52. api: 'cloudDestroy',
  53. })
  54. postMessage({
  55. api: 'cloudLoading',
  56. content: {
  57. show: true,
  58. type: 'fullscreen',
  59. },
  60. })
  61. const _url =
  62. location.origin +
  63. location.pathname +
  64. '?' +
  65. qs.stringify({
  66. ...query,
  67. behaviorId: sessionStorage.getItem('behaviorId') || '',
  68. _t: new Date().valueOf(),
  69. 'part-index': index,
  70. })
  71. console.log(_url)
  72. location.href = _url
  73. }
  74. return () => (
  75. <Popup class={styles.popup} v-model:show={toggleMusicSheet.show}>
  76. <ChoosePartName
  77. partIndex={trackIdx.value || 0}
  78. partListNames={partListNames.value}
  79. onClose={(value) => {
  80. console.log("🚀 ~ value:", value)
  81. toggleMusicSheet.show = false
  82. if (value !== undefined) {
  83. switchMusic(value)
  84. }
  85. }}
  86. />
  87. </Popup>
  88. )
  89. },
  90. })