lex 1 年間 前
コミット
021a0a0550
1 ファイル変更62 行追加59 行削除
  1. 62 59
      src/state.ts

+ 62 - 59
src/state.ts

@@ -48,7 +48,7 @@ export type ISonges = {
 /**
  * 特殊教材分类id
  */
-const classids = [1,2,3,4,6,7,8,9,10,11,12,13,14,15,16,17,30,31,35,36,38,108,150,151,152,153,154,155,156,157,158,178,179,180,181,182]; // 大雅金唐, 竖笛教程, 声部训练展开的分类ID
+const classids = [1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 30, 31, 35, 36, 38, 108, 150, 151, 152, 153, 154, 155, 156, 157, 158, 178, 179, 180, 181, 182]; // 大雅金唐, 竖笛教程, 声部训练展开的分类ID
 
 // 乐器code码
 export const musicalInstrumentCodeInfo = [
@@ -298,7 +298,7 @@ const state = reactive({
   /** 分类ID */
   musicSheetCategoriesId: 0,
   /** 各产品端的分类ID,(管乐迷、管乐团、酷乐秀、课堂乐器) */
-  bizMusicCategoryId: 0,  
+  bizMusicCategoryId: 0,
   /** 资源类型: mp3 | midi */
   playMode: "MP3" as "MP3" | "MIDI",
   /** 设置的速度 */
@@ -413,7 +413,7 @@ const state = reactive({
   /** 用户选择的结束小节数 */
   userChooseEndIndex: 0,
   /** 重播小节集合信息 */
-  repeatInfo: [] as any,  
+  repeatInfo: [] as any,
   /** 多分轨的曲子,可支持筛选的分轨 */
   canSelectTracks: [] as any,
   /** 声部codeId */
@@ -432,10 +432,10 @@ const state = reactive({
   isPreView: false,
   /** 是否为评测报告模式 */
   isEvaluatReport: false,
-  /** midi播放器是否初始化中 */  
+  /** midi播放器是否初始化中 */
   midiPlayIniting: false,
   /** 曲目信息 */
-  songs: {} as ISonges,  
+  songs: {} as ISonges,
   isAppPlay: false, // 是否midi音频,midi是app播放
   /** 音频播放器实例 */
   audiosInstance: null as any,
@@ -471,6 +471,8 @@ const state = reactive({
   guideInfo: null as any,
   noteCoords: [] as any,
   specialPosInit: false,
+  /** 资源类型 */
+  paymentType: null,
   /** 播放模式,默认练习模式 */
   defaultModeType: 1,
 });
@@ -592,10 +594,10 @@ const handlePlaying = () => {
       }
 
       // if (Math.abs(selectEndItem.endtime - currentTime) < offset_duration) {
-        // if (currentTime - selectEndItem.endtime > offset_duration) {
-          //console.log(currentTime,selectEndItem.endtime)
-        if (currentTime - selectEndItem.endtime >= 0) {
-        console.log("选段播放结束",state.setting.repeatAutoPlay);
+      // if (currentTime - selectEndItem.endtime > offset_duration) {
+      //console.log(currentTime,selectEndItem.endtime)
+      if (currentTime - selectEndItem.endtime >= 0) {
+        console.log("选段播放结束", state.setting.repeatAutoPlay);
         // 如果为选段评测模式
         if (state.modeType === "evaluating" && state.isSelectMeasureMode) {
           onEnded();
@@ -627,7 +629,7 @@ const handlePlaying = () => {
       uniformMoveSvgDom();
     }
   }
-  
+
 };
 /** 跳转到指定音符开始播放 */
 export const skipNotePlay = async (itemIndex: number, isStart = false) => {
@@ -664,7 +666,7 @@ export const togglePlay = async (playState?: "play" | "paused", sourceType?: str
   }
   // midi播放
   if (state.isAppPlay) {
-    if( playState === "paused" ) {
+    if (playState === "paused") {
       await api_cloudSuspend({
         songID: state.examSongId,
       })
@@ -728,7 +730,7 @@ export const resetPlaybackToStart = () => {
 export const gotoCustomNote = (index: number) => {
   try {
     state.osmd.cursor.reset();
-  } catch (error) {}
+  } catch (error) { }
   for (let i = 0; i < index; i++) {
     state.osmd.cursor.next();
   }
@@ -749,13 +751,13 @@ const computedDistance = (x: number, y: number) => {
       //min为元素中离目标元素最近元素的距离
       minDistance = c
       minidx = idx
-    }		
+    }
   })
   return minidx
 };
 
 const customNotePosition = (note: any, cursor: any) => {
-  const specialIds = ['1788850864767643649','1788502467554750466','1788501975122489346'];
+  const specialIds = ['1788850864767643649', '1788502467554750466', '1788501975122489346'];
   if (specialIds.includes(state.cbsExamSongId) && note.multipleRestMeasures === 0) {
     const pageLeft = document.getElementById('scrollContainer')?.getBoundingClientRect()?.x || 0;
     // 元素的位置
@@ -764,17 +766,17 @@ const customNotePosition = (note: any, cursor: any) => {
     if (element.x && element.y) {
       const noteIdx = computedDistance(element.x, element.y);
       const targetX = state.noteCoords[noteIdx]?.x - pageLeft;
-      console.log('音符索引',noteIdx)
+      console.log('音符索引', noteIdx)
       cursor.cursorElement.style.left = targetX + "px";
       cursor.cursorElement.style.transform = `translateX(0px)`;
     }
-    
+
   }
 }
 
 const setCursorPosition = (note: any, cursor: any, flag?: string) => {
   // console.log('音符',note?.i,state.osmd.Cursor.noteGraphicalId,note.svgElement?.attrs?.id)
-  
+
   if (state.musicRenderType === EnumMusicRenderType.firstTone || state.musicRenderType === EnumMusicRenderType.fixedTone) {
     /**
      * bug:#9920、#9940
@@ -784,31 +786,31 @@ const setCursorPosition = (note: any, cursor: any, flag?: string) => {
       return
 
     }
-    const specialIds = ['1788850864767643649','1788502467554750466','1788501975122489346'];
+    const specialIds = ['1788850864767643649', '1788502467554750466', '1788501975122489346'];
     if (specialIds.includes(state.cbsExamSongId) && note.multipleRestMeasures === 0) {
-        // console.log('音符idx',note?.i,cursor.cursorElement.style.left)
-        const cursorLeft = cursor?.cursorElement?.style?.left ? parseFloat(cursor.cursorElement.style.left) : 0;
-        let patchX = 0;
-        if (state.cbsExamSongId == '1788502467554750466') {
-          if (state.musicRenderType === EnumMusicRenderType.firstTone) {
-            patchX = (note.i == 0 || note.i == 60) ? 21 : (note.i == 1 || note.i == 7 || note.i == 23 || note.i == 38 || note.i == 44 || note.i == 52 || note.i == 58) ? -6 : (note.i >= 2 || note.i <= 6) || (note.i >= 8 || note.i <= 22) || (note.i >= 24 || note.i <= 37) || (note.i >= 39 || note.i <= 43) || (note.i >= 45 || note.i <= 51) || (note.i >= 53 || note.i <= 57) || (note.i == 59) ? 6 : 0;
-          }
-          if (state.musicRenderType === EnumMusicRenderType.fixedTone) {
-            patchX = note.i == 0 ? 31 : (note.i == 8 || note.i == 14 || note.i == 30 || note.i == 45 || note.i == 51 || note.i == 59 || note.i == 65) ? -10 : note.i == 67 ? 31 : 0;
-          }
-        } else if (state.cbsExamSongId == '1788501975122489346') {
-          if (state.musicRenderType === EnumMusicRenderType.firstTone) {
-            patchX = (note.i == 0) ? 21 : (note.i == 1 || note.i == 7 || note.i == 23 || note.i == 38 || note.i == 44 || note.i == 52 || note.i == 58) ? -6 : (note.i == 9 || note.i == 10 || note.i == 12 || note.i == 13) ? 3 : (note.i == 14 || note.i == 30 || note.i == 45 || note.i == 51 || note.i == 59) ? 6 : (note.i == 45) ? -8 : (note.i >= 15 || note.i <= 29) || (note.i >= 31 || note.i <= 36) || (note.i >= 38 || note.i <= 44) || (note.i >= 46 || note.i <= 50) || (note.i >= 52 || note.i <= 58) || (note.i >= 60 || note.i <= 64) || (note.i == 66) ? 4 : 0;
-          }
-          if (state.musicRenderType === EnumMusicRenderType.fixedTone) {
-            patchX = note.i == 0 ? 31 : (note.i == 8 || note.i == 14 || note.i == 30 || note.i == 45 || note.i == 51 || note.i == 59 || note.i == 65) ? -10 : note.i == 67 ? 31 : 0;
-          }
+      // console.log('音符idx',note?.i,cursor.cursorElement.style.left)
+      const cursorLeft = cursor?.cursorElement?.style?.left ? parseFloat(cursor.cursorElement.style.left) : 0;
+      let patchX = 0;
+      if (state.cbsExamSongId == '1788502467554750466') {
+        if (state.musicRenderType === EnumMusicRenderType.firstTone) {
+          patchX = (note.i == 0 || note.i == 60) ? 21 : (note.i == 1 || note.i == 7 || note.i == 23 || note.i == 38 || note.i == 44 || note.i == 52 || note.i == 58) ? -6 : (note.i >= 2 || note.i <= 6) || (note.i >= 8 || note.i <= 22) || (note.i >= 24 || note.i <= 37) || (note.i >= 39 || note.i <= 43) || (note.i >= 45 || note.i <= 51) || (note.i >= 53 || note.i <= 57) || (note.i == 59) ? 6 : 0;
+        }
+        if (state.musicRenderType === EnumMusicRenderType.fixedTone) {
+          patchX = note.i == 0 ? 31 : (note.i == 8 || note.i == 14 || note.i == 30 || note.i == 45 || note.i == 51 || note.i == 59 || note.i == 65) ? -10 : note.i == 67 ? 31 : 0;
         }
-        if (flag === 'refresh' || (flag === 'init' && !state.specialPosInit)) {
-          // console.log('音符idx',note?.i,cursor.cursorElement.style.left)
-          cursor.cursorElement.style.left = cursorLeft + patchX + "px";
-          state.specialPosInit = true;
+      } else if (state.cbsExamSongId == '1788501975122489346') {
+        if (state.musicRenderType === EnumMusicRenderType.firstTone) {
+          patchX = (note.i == 0) ? 21 : (note.i == 1 || note.i == 7 || note.i == 23 || note.i == 38 || note.i == 44 || note.i == 52 || note.i == 58) ? -6 : (note.i == 9 || note.i == 10 || note.i == 12 || note.i == 13) ? 3 : (note.i == 14 || note.i == 30 || note.i == 45 || note.i == 51 || note.i == 59) ? 6 : (note.i == 45) ? -8 : (note.i >= 15 || note.i <= 29) || (note.i >= 31 || note.i <= 36) || (note.i >= 38 || note.i <= 44) || (note.i >= 46 || note.i <= 50) || (note.i >= 52 || note.i <= 58) || (note.i >= 60 || note.i <= 64) || (note.i == 66) ? 4 : 0;
         }
+        if (state.musicRenderType === EnumMusicRenderType.fixedTone) {
+          patchX = note.i == 0 ? 31 : (note.i == 8 || note.i == 14 || note.i == 30 || note.i == 45 || note.i == 51 || note.i == 59 || note.i == 65) ? -10 : note.i == 67 ? 31 : 0;
+        }
+      }
+      if (flag === 'refresh' || (flag === 'init' && !state.specialPosInit)) {
+        // console.log('音符idx',note?.i,cursor.cursorElement.style.left)
+        cursor.cursorElement.style.left = cursorLeft + patchX + "px";
+        state.specialPosInit = true;
+      }
     } else {
       nextTick(() => {
         let bbox = note.bbox;
@@ -872,7 +874,7 @@ export const gotoNext = (note: any, skipNote?: boolean) => {
     //   osmd.cursor.next();
     // }
     osmd.cursor.next();
-    
+
   } else if (prev && num - prev > 0) {
     while (num - prev > 0) {
       prev++;
@@ -995,7 +997,7 @@ export const handleSelection = (item: any) => {
   if (state.section.length !== 2 && item) {
     state.section.push(item);
     if (state.section.length === 2) {
-      setSection(state.section[0].MeasureNumberXML,state.section[1].MeasureNumberXML)
+      setSection(state.section[0].MeasureNumberXML, state.section[1].MeasureNumberXML)
       //state.section = formateSelectMearure(state.section);
       closeToast();
     }
@@ -1023,7 +1025,7 @@ export const setSection = (start: number, end: number, userSpeed?: number) => {
   let lastEndNotes = endNotes.filter((n: any) => n.noteId === lastEndId)
   // 是否符合重播规则
   const canRepeatInfo = verifyCanRepeat(start, end)
-  console.log('能否重播',canRepeatInfo)
+  console.log('能否重播', canRepeatInfo)
   const isCanRepeat = canRepeatInfo.canRepeat
   // 如果符合重播规则,但是lastEndNotes长度为1,则需要向前找,直到找到lastEndNotes长度为2
   /**
@@ -1049,8 +1051,8 @@ export const setSection = (start: number, end: number, userSpeed?: number) => {
   const endIdx: any = (isCanRepeat && canRepeatInfo.repeatIdx == state.repeatInfo.length - 1) ? lastEndNotes.length - 1 : 0
   const startNote = startNotes[0]
   // const endNote = endNotes[endNotes.length - 1]
-  const endNote = lastEndNotes[endIdx]			
-  
+  const endNote = lastEndNotes[endIdx]
+
   if (startNote && endNote) {
     state.isSelectMeasureMode = true;
     // 设置小节
@@ -1061,7 +1063,7 @@ export const setSection = (start: number, end: number, userSpeed?: number) => {
       handleSetSpeed(userSpeed);
     }
   }
-}	
+}
 
 
 /** 直接设置选段 */
@@ -1070,7 +1072,7 @@ export const hanldeDirectSelection = (list: any[]) => {
   state.sectionStatus = true;
   setTimeout(() => {
     state.section = formateSelectMearure(list);
-    console.log('选段小节',state.section)
+    console.log('选段小节', state.section)
   }, 500);
 };
 let offsetTop = 0;
@@ -1161,6 +1163,7 @@ const setState = (data: any, index: number) => {
   state.appName = "COLEXIU";
   state.detailId = data.bizId;
   state.xmlUrl = data.xmlFileUrl;
+  state.paymentType = data.paymentType
   state.partIndex = index;
   state.trackId = data.track;
   state.subjectId = data.subjectIds ? data.subjectIds.split(',')?.[0] : 0;
@@ -1248,11 +1251,11 @@ const setState = (data: any, index: number) => {
   console.log("🚀 ~ state.fingeringInfo:", code, state.fingeringInfo, state.trackId, state.track);
   state.musicalCodeId = state.fingeringInfo?.id || 0
   state.musicalCode = musicalInstrumentCodeInfo.find(item => item.id === state.musicalCodeId)?.code || state.trackId
-  ;(window as any).DYSubjectId = state.musicalCodeId
-  // 开启自定义每行显示的小节数
-  ;(window as any).customSectionAmount = true
-  // 标识是课堂乐器,用于移调时进行区分处理
-  ;(window as any).DYProjectName = 'musicScore';
+    ; (window as any).DYSubjectId = state.musicalCodeId
+    // 开启自定义每行显示的小节数
+    ; (window as any).customSectionAmount = true
+    // 标识是课堂乐器,用于移调时进行区分处理
+    ; (window as any).DYProjectName = 'musicScore';
   // 如果切换的声轨没有指法,择指法开关置灰并且不可点击
   if (!state.fingeringInfo.name && state.setting.displayFingering) {
     state.setting.displayFingering = false
@@ -1290,7 +1293,7 @@ const setState = (data: any, index: number) => {
   /**
    * TODO:摇篮曲特殊处理
    */
-  if (['1788501975122489346','1788502467554750466','1789839575249596417'].includes(state.cbsExamSongId)) {
+  if (['1788501975122489346', '1788502467554750466', '1789839575249596417'].includes(state.cbsExamSongId)) {
     if (state.musicRenderType === 'fixedTone') {
       state.musicRenderType = EnumMusicRenderType.firstTone;
     }
@@ -1324,7 +1327,7 @@ export const followBeatPaly = () => {
     metroTimer = null
     return;
   }
-  const time = state.measureTime*1000 / metronomeData.totalNumerator
+  const time = state.measureTime * 1000 / metronomeData.totalNumerator
   requestAnimationFrame(() => {
     const endTime = Date.now();
     if (endTime - state.beatStartTime < time) {
@@ -1409,7 +1412,7 @@ export const createFixedCursor = () => {
   state.cursorDom = cursorDom;
   let copyCursor: any = cursorDom?.cloneNode(true);
   if (copyCursor) {
-    copyCursor.setAttribute('id','cursor-copy');
+    copyCursor.setAttribute('id', 'cursor-copy');
     copyCursor.style.position = 'sticky';
     copyCursor.style.zIndex = '2';
     // if (!state.times[0]?.id) {
@@ -1482,13 +1485,13 @@ export const moveSvgDom = (skipNote?: boolean) => {
 /** 平滑移动svgdom */
 export const smoothMoveSvgDom = () => {
   const currentTime = getAudioCurrentTime();
-  const matchNoteIdx = state.times.findIndex((item: any) => Math.abs(item.time - currentTime) * 1000 < 100 )
+  const matchNoteIdx = state.times.findIndex((item: any) => Math.abs(item.time - currentTime) * 1000 < 100)
   // if (matchNoteIdx >= 0) {
   //   console.log('匹配',matchNoteIdx,currentTime)
   // }
-  
+
   if (currentTime <= state.fixtime) return;
-  if (currentTime > state.times.last()?.time) return; 
+  if (currentTime > state.times.last()?.time) return;
   // console.log('跳转音符',currentTime)
   const currentBBox = state.times[state.activeNoteIndex]?.bbox;
   let nextIndex = state.activeNoteIndex + 1;
@@ -1509,7 +1512,7 @@ export const smoothMoveSvgDom = () => {
     //   noteDistance = noteDistance - state.times[state.activeNoteIndex]?.bbox?.svgBodyLeft;
     // }
     const distance = noteDistance * playProgress;
-    
+
     // 上一个音符和第一个音符的间距
     let preDistance = state.times[state.activeNoteIndex].bbox?.x - state.times[0].bbox?.x + state.times[state.activeNoteIndex].bbox?.width / 4;
 
@@ -1528,7 +1531,7 @@ export const smoothMoveSvgDom = () => {
 export const uniformMoveSvgDom = () => {
   const currentTime = getAudioCurrentTime();
   if (currentTime <= state.fixtime) return;
-  if (currentTime > state.times.last()?.time) return; 
+  if (currentTime > state.times.last()?.time) return;
   const playProgress = (currentTime - state.fixtime) / state.times.last()?.time;
   const distance = playProgress * state.noteDistance || 0;
   state.osdmScrollDom.scrollLeft = distance;