index.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import { computed, defineComponent, reactive, toRef, watch, ref } 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, handleGuide } 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. import { xmlDocRef, downloadXmlStr } from "/src/view/music-score"
  14. import IndexedDBService from "/src/utils/indexedDB";
  15. export const toggleMusicSheet = reactive({
  16. show: false,
  17. toggle: (type = true) => {
  18. toggleMusicSheet.show = type
  19. },
  20. })
  21. export default defineComponent({
  22. name: 'ToggleMusicSheet',
  23. setup() {
  24. const query = getQuery();
  25. const partListNames = computed(() => {
  26. let partList = state.partListNames || []
  27. partList = partList.filter((item: any) => !item?.toLocaleUpperCase()?.includes('COMMON'))
  28. const arr = partList.map((item: any, index: number) => {
  29. // 该声轨能否被选
  30. const canselect = state.canSelectTracks.length == 0 || state.canSelectTracks.includes(item) ? true : false
  31. // console.log(canselect,index)
  32. const instrumentName = getInstrumentName(item)
  33. const sortId = sortMusical(instrumentName, index)
  34. return {
  35. text: item + (instrumentName ? `(${instrumentName})` : ''),
  36. value: index,
  37. sortId,
  38. canselect
  39. }
  40. }).filter((item: any) => item.canselect)
  41. // 不需要自定义排序,改为按照xml声轨顺序显示
  42. // .sort((a: any, b: any) => a.sortId - b.sortId)
  43. return arr
  44. })
  45. const partIndexs: any = computed(() => {
  46. if(state.combinePartIndexs.length > 1){
  47. return state.combinePartIndexs
  48. }else{
  49. return [state.partIndex]
  50. }
  51. })
  52. // 切换的时候存储处理过后的xml
  53. const storeXmlData = async () => {
  54. const dbService = new IndexedDBService("MyDatabase", "MyStore");
  55. await dbService.save({ id: state.examSongId, xmlString: downloadXmlStr.value })
  56. .then(() => dbService.get(state.examSongId))
  57. .then((data) => console.log("数据:", data));
  58. }
  59. const switchMusic = async (partIndexs: number[]) => {
  60. const index = partIndexs.join(",") as any
  61. // 暂停播放
  62. togglePlay("paused");
  63. // 销毁播放器
  64. postMessage({
  65. api: 'cloudDestroy',
  66. })
  67. postMessage({
  68. api: 'cloudLoading',
  69. content: {
  70. show: true,
  71. type: 'fullscreen',
  72. },
  73. })
  74. // 存储当前 模式
  75. localStorage.setItem("musicScorePlayType", `${state.playType},${state.playSource}`)
  76. const _url =
  77. location.origin +
  78. location.pathname +
  79. '?' +
  80. qs.stringify({
  81. ...query,
  82. behaviorId: sessionStorage.getItem('behaviorId') || '',
  83. _t: new Date().valueOf(),
  84. 'part-index': index,
  85. 'part-name': ''
  86. })
  87. // const blob2 = new Blob([downloadXmlStr.value], { type: "text/html" });
  88. // console.log(_url,xmlDocRef.value,downloadXmlStr.value)
  89. state.evaluatAudioInitDone = false
  90. await storeXmlData()
  91. location.href = _url
  92. }
  93. const parentClassName = "switchBoxClass_drag";
  94. const userId = storeData.user?.id ? String(storeData.user?.id) : '';
  95. const positionInfo = state.platform !== IPlatform.PC ? {
  96. styleDrag: { value: null }
  97. } : useDrag(
  98. [
  99. `${parentClassName} .top_draging`,
  100. `${parentClassName} .bom_drag`
  101. ],
  102. parentClassName,
  103. toRef(toggleMusicSheet, 'show'),
  104. userId
  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.7)'}}>
  108. <ChoosePartName
  109. partIndexs={partIndexs.value}
  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. })