index.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { computed, defineComponent, reactive, toRef, watch } from 'vue'
  2. import styles from './index.module.less'
  3. import { Icon, Popup } from 'vant'
  4. import ChoosePartName from './choosePartName'
  5. import state, { togglePlay, IPlatform } 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. import useDrag from "/src/view/plugins/useDrag/index";
  10. import Dragbom from "/src/view/plugins/useDrag/dragbom";
  11. import { setGuidance } from "/src/page-instrument/custom-plugins/guide-page/api";
  12. import { storeData } from "/src/store";
  13. export const toggleMusicSheet = reactive({
  14. show: false,
  15. toggle: (type = true) => {
  16. toggleMusicSheet.show = type
  17. },
  18. })
  19. export default defineComponent({
  20. name: 'ToggleMusicSheet',
  21. setup() {
  22. const query = getQuery();
  23. const partListNames = computed(() => {
  24. let partList = state.partListNames || []
  25. partList = partList.filter((item: any) => !item?.toLocaleUpperCase()?.includes('COMMON'))
  26. const arr = partList.map((item: any, index: number) => {
  27. // 该声轨能否被选
  28. const canselect = state.canSelectTracks.length == 0 || state.canSelectTracks.includes(item) ? true : false
  29. // console.log(canselect,index)
  30. const instrumentName = getInstrumentName(item)
  31. const sortId = sortMusical(instrumentName, index)
  32. return {
  33. text: item + (instrumentName ? `(${instrumentName})` : ''),
  34. value: index,
  35. sortId,
  36. canselect
  37. }
  38. }).filter((item: any) => item.canselect)
  39. // 不需要自定义排序,改为按照xml声轨顺序显示
  40. // .sort((a: any, b: any) => a.sortId - b.sortId)
  41. // 支持总谱渲染的时候 加上总谱字段
  42. state.isScoreRender && arr.unshift({canselect:true, sortId:999, text: "总谱", value: 999})
  43. return arr
  44. })
  45. const trackIdx: any = computed(() => {
  46. if (partListNames && partListNames.value.length) {
  47. const idx = partListNames.value.find((item: any) => item.value == state.partIndex)?.value || 0
  48. console.log(3333,idx)
  49. return idx
  50. } else {
  51. return 0
  52. }
  53. })
  54. const switchMusic = (index: number) => {
  55. if (state.partIndex === index) return
  56. // 暂停播放
  57. togglePlay("paused");
  58. // 销毁播放器
  59. postMessage({
  60. api: 'cloudDestroy',
  61. })
  62. postMessage({
  63. api: 'cloudLoading',
  64. content: {
  65. show: true,
  66. type: 'fullscreen',
  67. },
  68. })
  69. // 存储当前 模式
  70. localStorage.setItem("musicScorePlayType", `${state.playType},${state.playSource}`)
  71. const _url =
  72. location.origin +
  73. location.pathname +
  74. '?' +
  75. qs.stringify({
  76. ...query,
  77. behaviorId: sessionStorage.getItem('behaviorId') || '',
  78. _t: new Date().valueOf(),
  79. 'part-index': index,
  80. })
  81. console.log(_url)
  82. location.href = _url
  83. }
  84. const parentClassName = "switchBoxClass_drag";
  85. const userId = storeData.user?.id ? String(storeData.user?.id) : '';
  86. const positionInfo = state.platform !== IPlatform.PC ? {
  87. styleDrag: { value: null }
  88. } : useDrag(
  89. [
  90. `${parentClassName} .top_draging`,
  91. `${parentClassName} .bom_drag`
  92. ],
  93. parentClassName,
  94. toRef(toggleMusicSheet, 'show'),
  95. userId
  96. )
  97. // 完成拖动弹窗引导页
  98. const handleGuide = async () => {
  99. state.guideInfo.teacherDrag = true;
  100. try{
  101. const res = await setGuidance({guideTag:'guideInfo',guideValue:JSON.stringify(state.guideInfo)})
  102. }catch(e){
  103. console.log(e)
  104. }
  105. }
  106. return () => (
  107. <Popup v-model:show={toggleMusicSheet.show} class="popup-custom van-scale center-closeBtn switchBoxClass_drag" transition="van-scale" teleport="body" style={positionInfo.styleDrag.value} overlay-style={{background:'rgba(0, 0, 0, 0.3)'}}>
  108. <ChoosePartName
  109. partIndex={trackIdx.value || 0}
  110. partListNames={partListNames.value}
  111. onClose={(value) => {
  112. console.log("🚀 ~ value:", value)
  113. toggleMusicSheet.show = false
  114. if (value !== undefined) {
  115. switchMusic(value)
  116. }
  117. }}
  118. />
  119. { state.platform === IPlatform.PC && <Dragbom showGuide={!state.guideInfo?.teacherDrag} onGuideDone={handleGuide} /> }
  120. </Popup>
  121. )
  122. },
  123. })