index.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import { computed, defineComponent, reactive, toRef } 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).sort((a: any, b: any) => a.sortId - b.sortId)
  39. return arr
  40. })
  41. const trackIdx: any = computed(() => {
  42. if (partListNames && partListNames.value.length) {
  43. const idx = partListNames.value.find((item: any) => item.value == state.partIndex)?.value || 0
  44. console.log(3333,idx)
  45. return idx
  46. } else {
  47. return 0
  48. }
  49. })
  50. const switchMusic = (index: number) => {
  51. if (state.partIndex === index) return
  52. // 暂停播放
  53. togglePlay("paused");
  54. // 销毁播放器
  55. postMessage({
  56. api: 'cloudDestroy',
  57. })
  58. postMessage({
  59. api: 'cloudLoading',
  60. content: {
  61. show: true,
  62. type: 'fullscreen',
  63. },
  64. })
  65. const _url =
  66. location.origin +
  67. location.pathname +
  68. '?' +
  69. qs.stringify({
  70. ...query,
  71. behaviorId: sessionStorage.getItem('behaviorId') || '',
  72. _t: new Date().valueOf(),
  73. 'part-index': index,
  74. })
  75. console.log(_url)
  76. location.href = _url
  77. }
  78. const parentClassName = "switchBoxClass_drag";
  79. const userId = storeData.user?.id ? String(storeData.user?.id) : '';
  80. const positionInfo = state.platform !== IPlatform.PC ? {
  81. styleDrag: { value: null }
  82. } : useDrag(
  83. [
  84. `${parentClassName} .top_drag`,
  85. `${parentClassName} .bom_drag`
  86. ],
  87. parentClassName,
  88. toRef(toggleMusicSheet, 'show'),
  89. userId
  90. )
  91. // 完成拖动弹窗引导页
  92. const handleGuide = async () => {
  93. state.guideInfo.teacherDrag = true;
  94. try{
  95. const res = await setGuidance({guideTag:'guideInfo',guideValue:JSON.stringify(state.guideInfo)})
  96. }catch(e){
  97. console.log(e)
  98. }
  99. }
  100. return () => (
  101. <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)'}}>
  102. <ChoosePartName
  103. partIndex={trackIdx.value || 0}
  104. partListNames={partListNames.value}
  105. onClose={(value) => {
  106. console.log("🚀 ~ value:", value)
  107. toggleMusicSheet.show = false
  108. if (value !== undefined) {
  109. switchMusic(value)
  110. }
  111. }}
  112. />
  113. { state.platform === IPlatform.PC && <Dragbom showGuide={!state.guideInfo?.teacherDrag} onGuideDone={handleGuide} /> }
  114. </Popup>
  115. )
  116. },
  117. })