Просмотр исходного кода

Merge branch 'gyt-feature-tianyong' into online

TIANYONG 1 год назад
Родитель
Сommit
135964c3ab

+ 67 - 1
src/pages/detail/helpers.ts

@@ -1,7 +1,7 @@
 import state from './state'
 import appState from '/src/state'
 import { browser } from '/src/helpers/utils'
-import runtime, { getFixTime } from './runtime'
+import runtime, { getFixTime, getFirsrNoteByMeasureListIndex, getBoundingBoxByNote } from './runtime'
 // @ts-ignore
 import {
   isSpecialMark,
@@ -236,6 +236,7 @@ export const getAllNodes = (osmd: any) => {
       for (const v of voiceEntries) {
         // 始终只取第一个声部中第一个音符的时间
         let note: any = v.notes[0]
+        // console.log( note.sourceMeasure.verticalMeasureList)
         if (['Piano'].includes(state.activeDetail?.code) || state.activeDetail?.musicSheetType == 'CONCERT') {
           let _notes = []
           try {
@@ -1517,3 +1518,68 @@ const getImageSize = (src: string): Promise<HTMLImageElement> => {
     img.onerror = (err) => reject(err)
   })
 }
+
+
+// 计算选择范围内的小节宽度高度
+export const setSettionBackground = () => {
+  // console.log(1111)
+  state.sectionBoundingBoxs = []
+  const [start, end] = state.section.sort((a, b) => a.i - b.i)
+  let startIndex = 0,
+    endIndex = 0
+  const selectNoteNum = Math.abs(end.i - start.i) + 1
+  startIndex = 0
+  endIndex = end.noteLength
+  const seteds: number[] = []
+  const heights: number[] = []
+  for (let index = 0; index < selectNoteNum; index++) {
+    const activeIndex = index + start.i
+    const activeTimeNote = state.times[activeIndex]
+    const activeNote = activeTimeNote.noteElement
+    const measureListIndex = activeNote.sourceMeasure.measureListIndex
+
+    // 如果没有节拍器,默认提前一个小节
+    if (index === 0 && measureListIndex !== 0 && !state.needTick) {
+      const firstNote = getFirsrNoteByMeasureListIndex(measureListIndex - 1)
+      const fnote = firstNote?.noteElement
+      if (fnote) {
+        // console.log(fnote.sourceMeasure?.measureListIndex, start.noteElement?.sourceMeasure?.measureListIndex)
+        for (
+          let j = fnote.sourceMeasure?.measureListIndex;
+          j < start.noteElement?.sourceMeasure?.measureListIndex;
+          j++
+        ) {
+          if (!seteds.includes(j)) {
+            for (const item of state.times) {
+              if (item.noteElement?.sourceMeasure?.measureListIndex === j && !seteds.includes(j)) {
+                const boundingBox = getBoundingBoxByNote(item.noteElement, {
+                  before: true,
+                })
+                state.befireSection = !boundingBox && state.befireSection ? state.befireSection : item
+                if (!boundingBox) {
+                  continue
+                }
+                state.sectionBoundingBoxs.push(boundingBox)
+                heights.push(boundingBox.height)
+                seteds.push(j)
+              }
+            }
+          }
+        }
+      }
+    }
+
+    if (!seteds.includes(measureListIndex)) {
+      seteds.push(measureListIndex)
+      const boundingBox = getBoundingBoxByNote(activeNote)
+      if (boundingBox) {
+        state.sectionBoundingBoxs.push(boundingBox)
+        heights.push(boundingBox.height)
+      }
+    }
+  }
+  state.sectionBoundingBoxs.map((item) => {
+    item.height = Math.max(...heights)
+    return item
+  })
+}

+ 21 - 0
src/pages/detail/runtime.ts

@@ -1048,3 +1048,24 @@ export const setCaptureMode = async () => {
     })
   }
 }
+
+
+export const getBoundingBoxByNote = (note: any, extra?: any) => {
+  const mBoundingBox = note.sourceMeasure?.verticalMeasureList?.[0]?.boundingBox
+  if (!mBoundingBox) {
+    return null
+  }
+  const boundingBox = {
+    ...mBoundingBox.absolutePosition,
+    ...mBoundingBox.size,
+    ...extra,
+  }
+  boundingBox.x = boundingBox.x * 10
+  boundingBox.y = boundingBox.y * 10
+  boundingBox.width = boundingBox.width * 10
+  boundingBox.height = boundingBox.height * 10
+  if (note?.sourceMeasure?.verticalMeasureList?.[0]?.stave?.height) {
+    boundingBox.height = note.sourceMeasure?.verticalMeasureList?.[0]?.stave?.height
+  }
+  return boundingBox
+}

+ 4 - 85
src/pages/detail/section-box/index.tsx

@@ -3,8 +3,8 @@ import { defineComponent, watchEffect, TransitionGroup, ref, Ref, reactive } fro
 import event from '/src/components/music-score/event'
 import SettingState from '/src/pages/detail/setting-state'
 import state from '../state'
-import runtime, { getFirsrNoteByMeasureListIndex } from '../runtime'
-import { getActtiveNoteByTimes, getBoundingBoxByverticalNote, getNoteBySlursStart } from '../helpers'
+import runtime, { getFirsrNoteByMeasureListIndex, getBoundingBoxByNote } from '../runtime'
+import { getActtiveNoteByTimes, getBoundingBoxByverticalNote, getNoteBySlursStart, setSettionBackground } from '../helpers'
 import { formatZoom } from '/src/helpers/utils'
 import styles from './index.module.less'
 import classNames from 'classnames'
@@ -88,87 +88,6 @@ export default defineComponent({
     }
   },
   methods: {
-    getBoundingBoxByNote(note: any, extra?: any) {
-      const mBoundingBox = note.sourceMeasure?.verticalMeasureList?.[0]?.boundingBox
-      if (!mBoundingBox) {
-        return null
-      }
-      const boundingBox = {
-        ...mBoundingBox.absolutePosition,
-        ...mBoundingBox.size,
-        ...extra,
-      }
-      boundingBox.x = boundingBox.x * 10
-      boundingBox.y = boundingBox.y * 10
-      boundingBox.width = boundingBox.width * 10
-      boundingBox.height = boundingBox.height * 10
-      if (note?.sourceMeasure?.verticalMeasureList?.[0]?.stave?.height) {
-        boundingBox.height = note.sourceMeasure?.verticalMeasureList?.[0]?.stave?.height
-      }
-      return boundingBox
-    },
-    // 计算选择范围内的小节宽度高度
-    setSettionBackground() {
-      state.sectionBoundingBoxs = []
-      const [start, end] = state.section.sort((a, b) => a.i - b.i)
-      let startIndex = 0,
-        endIndex = 0
-      const selectNoteNum = Math.abs(end.i - start.i) + 1
-      startIndex = 0
-      endIndex = end.noteLength
-      const seteds: number[] = []
-      const heights: number[] = []
-      for (let index = 0; index < selectNoteNum; index++) {
-        const activeIndex = index + start.i
-        const activeTimeNote = state.times[activeIndex]
-        const activeNote = activeTimeNote.noteElement
-        const measureListIndex = activeNote.sourceMeasure.measureListIndex
-
-        // 如果没有节拍器,默认提前一个小节
-        if (index === 0 && measureListIndex !== 0 && !state.needTick) {
-          const firstNote = getFirsrNoteByMeasureListIndex(measureListIndex - 1)
-          const fnote = firstNote?.noteElement
-          if (fnote) {
-            // console.log(fnote.sourceMeasure?.measureListIndex, start.noteElement?.sourceMeasure?.measureListIndex)
-            for (
-              let j = fnote.sourceMeasure?.measureListIndex;
-              j < start.noteElement?.sourceMeasure?.measureListIndex;
-              j++
-            ) {
-              if (!seteds.includes(j)) {
-                for (const item of state.times) {
-                  if (item.noteElement?.sourceMeasure?.measureListIndex === j && !seteds.includes(j)) {
-                    const boundingBox = this.getBoundingBoxByNote(item.noteElement, {
-                      before: true,
-                    })
-                    state.befireSection = item
-                    if (!boundingBox) {
-                      continue
-                    }
-                    state.sectionBoundingBoxs.push(boundingBox)
-                    heights.push(boundingBox.height)
-                    seteds.push(j)
-                  }
-                }
-              }
-            }
-          }
-        }
-
-        if (!seteds.includes(measureListIndex)) {
-          seteds.push(measureListIndex)
-          const boundingBox = this.getBoundingBoxByNote(activeNote)
-          if (boundingBox) {
-            state.sectionBoundingBoxs.push(boundingBox)
-            heights.push(boundingBox.height)
-          }
-        }
-      }
-      state.sectionBoundingBoxs.map((item) => {
-        item.height = Math.max(...heights)
-        return item
-      })
-    },
     setSection(evt: MouseEvent) {
       const activeNote = getActtiveNoteByTimes(evt)
       if (activeNote && state.section.length < 2) {
@@ -184,7 +103,7 @@ export default defineComponent({
       }
       if (state.section.length === 2) {
         Toast.clear()
-        this.setSettionBackground()
+        setSettionBackground()
       }
     },
     sectionClick(evt: MouseEvent): void {
@@ -278,7 +197,7 @@ export default defineComponent({
           const activeNumberIndex = (item?.noteElement?.sourceMeasure?.measureNumber + 1) || -2;
           // console.log(activeNumberIndex,'👀👀',metronomeData.activeMetro?.measureNumberXML)
           if (item.si === 0) {
-            boundingBox = this.getBoundingBoxByNote(item.noteElement)
+            boundingBox = getBoundingBoxByNote(item.noteElement)
           }
           return (
             <>

+ 23 - 0
src/subpages/colexiu/buttons/evaluating.tsx

@@ -43,6 +43,7 @@ const connentLoading = ref(false)
 const playUrl: Ref<string> = ref('')
 const endResult = ref(null)
 const browserInfo = browser()
+const scoreList: any[] = []
 
 /**
  * 默认按照442计算的音符频率,此处转化为按照设置进行调整
@@ -439,6 +440,7 @@ const submitEvaluationScore = async (data: any) => {
       Toast('完整演奏结束才算测验分数!')
       return
     }
+    (endResult.value as any)?.score && scoreList.push((endResult.value as any)?.score)
     /** 有单元测验时,存储分数缓存 */
     postMessage({
       api: 'setCache',
@@ -559,6 +561,26 @@ const handleComplexButton = (res?: IPostMessage) => {
 	}
 };
 
+// 离开之前再提交一次最高分数
+export const submitMaxScore = () => {
+  const search = useOriginSearch()
+  if (search.unitId && scoreList.length) {
+    console.log('最高分',scoreList,Math.max(...scoreList))
+    postMessage({
+      api: 'setCache',
+      content: {
+        key: 'h5-orchestra-unit',
+        value: JSON.stringify({
+          musicId: search.id || '',
+          unitId: search.unitId || '',
+          questionId: search.questionId || '',
+          score: Math.max(...scoreList),
+        }),
+      },
+    })
+  }
+}
+
 export default defineComponent({
   name: 'ColexiuButtonEvaluating',
   setup(props, { expose }) {
@@ -595,6 +617,7 @@ export default defineComponent({
       removeListenerMessage('cloudTimeUpdae', onProgress)
       hideComplexButton(() => {}, false);
       RuntimeUtils.event.off('tickEnd', evaluatStart)
+      submitMaxScore()
     })
 
     expose({

+ 2 - 0
src/subpages/colexiu/buttons/index.tsx

@@ -35,6 +35,7 @@ import { toggleMusicSheet } from '../plugins/toggleMusicSheet'
 import classNames from 'classnames'
 import Metronome, { metronomeData } from '/src/helpers/metronome'
 import { getAllNodes } from '/src/pages/detail/helpers'
+import { submitMaxScore } from '/src/subpages/colexiu/buttons/evaluating'
 
 export const confirmShow: Ref<boolean> = ref(false)
 
@@ -91,6 +92,7 @@ const beforeCheck = (cb: (status: boolean) => void) => {
 }
 
 const back: () => void = () => {
+  submitMaxScore()
   sendBackRecordTotalTime()
   postMessage({
     api: 'back',

+ 2 - 2
src/subpages/colexiu/index.tsx

@@ -364,7 +364,7 @@ export default defineComponent({
                 paddingBottom:
                   needFingering && (fingeringDetail.value as any).height
                     ? (fingeringDetail.value as any).height
-                    : SettingState.sett.eyeProtection ? '78px' : '60px',
+                    : '78px',
                 background: SettingState.sett.camera
                   ? `rgba(${SettingState.sett.eyeProtection ? '253,244,229' : '255,255,255'} ,${
                       SettingState.sett.opacity / 100
@@ -402,7 +402,7 @@ export default defineComponent({
                     onRenderError={onRenderError}
                     onRerender={onRerender}
                   />
-                  {needFingering && <Fingering code={detail.value.code} />}
+                  {needFingering && detailState.initRendered && <Fingering code={detail.value.code} />}
                 </>
               )}
               {modelType.value === 'follow' && <Follow ref={followRef} />}

+ 2 - 0
src/subpages/colexiu/unitTest/index.tsx

@@ -7,6 +7,7 @@ import state from '/src/pages/detail/state'
 import { Toast } from 'vant'
 import { userInfo } from '../App'
 import { browser } from '/src/helpers/utils'
+import { setSettionBackground } from '/src/pages/detail/helpers'
 
 interface IquestionExtendsInfo {
   /** 评测难度 */
@@ -100,6 +101,7 @@ export default defineComponent({
         if (questionExtendsInfo.value.speed) {
           changeSpeed(questionExtendsInfo.value.speed)
         }
+        setSettionBackground()
       }
     }
     onMounted(() => {