| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453 |
- import { Skeleton } from "vant";
- import { defineComponent, onBeforeMount, onBeforeUnmount, onMounted, reactive, Transition, watch, ref } from "vue";
- import { formateTimes } from "../../helpers/formateMusic";
- import state, { isRhythmicExercises, getMusicDetail, EnumMusicRenderType } from "../../state";
- import { setGlobalData } from "../../utils";
- import MusicScore, { resetMusicScore } from "../../view/music-score";
- import styles from "./index.module.less";
- import {
- api_cloudLoading,
- api_setStatusBarVisibility,
- isSpecialShapedScreen,
- } from "/src/helpers/communication";
- import { getQuery } from "/src/utils/queryString";
- import { mappingVoicePart, subjectFingering } from "/src/view/fingering/fingering-config";
- import { api_musicPracticeRecordDetail, sysMusicScoreAccompanimentQueryPage } from "../api";
- import { getMusicSheetDetail } from "/src/utils/baseApi"
- import ShareTop from "./component/share-top";
- import { addMeasureScore } from "/src/view/evaluating";
- import TopArrow from "./component/note/topArrow";
- import BottomArrow from "./component/note/bottomArrow";
- import LeftArrow from "./component/note/leftArrow";
- import RightArrow from "./component/note/rightArrow";
- const colorsClass: any = {
- RIGHT: styles.right, // 正确
- WRONG: styles.wrong, // 错误
- NOT_PLAYED: styles.notPlay, // 未演奏
- EARLY: styles.cadence_fast, // 节奏快
- LATE: styles.cadence_slow, // 节奏慢
- HIGH: styles.intonation_high, // 音准高
- LOW: styles.intonation_low, // 音准低
- DURATION_INSUFFICIENT: styles.integrity_wrong // 完整性(时值)不足
- }
- // const colorsClass: any = {
- // /** 音准 */
- // pitch: {
- // /** 高了 */
- // HIGH: styles.intonation_high,
- // /** 正常 */
- // RIGHT: styles.intonation_right,
- // /** 低了 */
- // LOW: styles.intonation_low,
- // /** 未演奏 */
- // NOT_PLAYED: styles.notPlay,
- // /** 错误 */
- // WRONG: styles.intonation_wrong,
- // /** 时值不足 */
- // DURATION_INSUFFICIENT: styles.integrity_wrong
- // },
- // /** 节奏 */
- // rhythmic: {
- // /** 过早 */
- // EARLY: styles.cadence_fast,
- // /** 正常 */
- // RIGHT: styles.cadence_right,
- // /** 过迟 */
- // LATE: styles.cadence_slow,
- // /** 未演奏 */
- // NOT_PLAYED: styles.notPlay,
- // /** 错误 */
- // WRONG: styles.cadence_wrong
- // }
- // }
- export default defineComponent({
- name: "music-list",
- setup() {
- const query: any = getQuery();
- const useedid = ref<string[]>([])
- const scoreData = reactive({
- videoFilePath: "", // 回放视频路径
- cadence: 0,
- integrity: 0,
- intonation: 0,
- score: 0,
- heardLevel: "",
- itemType: "intonation",
- musicType: 'staff',
- });
- const detailData = reactive({
- isLoading: true,
- paddingLeft: "",
- headerHide: false,
- musicalNotesPlayStats: [] as any[],
- userMeasureScore: {} as any,
- });
- const getAPPData = async () => {
- const screenData = await isSpecialShapedScreen();
- if (screenData?.content) {
- const { isSpecialShapedScreen, notchHeight } = screenData.content;
- if (isSpecialShapedScreen) {
- detailData.paddingLeft = 25 + "px";
- }
- }
- // 普通webview 没有获取异性屏的方法
- detailData.paddingLeft = 20 + "px";
- };
- onBeforeMount(() => {
- getAPPData();
- api_setStatusBarVisibility();
- });
- // console.log(route.params, query)
- /** 获取曲谱数据 */
- const getMusicInfo = (res: any) => {
- const index = state.partIndex;
- const musicInfo = {
- ...res.data,
- ...res.data.background[index],
- };
- // console.log("🚀 ~ musicInfo:", musicInfo);
- setState(musicInfo, index);
- setCustom();
- detailData.isLoading = false;
- };
- const setState = (data: any, index: number) => {
- // console.log("🚀 ~ data:", data)
- state.scrollContainer = "scrollContainer";
- state.detailId = data.id;
- state.xmlUrl = data.xmlFileUrl;
- state.partIndex = index;
- state.subjectId = data.musicSubject;
- state.categoriesId = data.categoriesId;
- state.categoriesName = data.musicTagNames;
- state.enableEvaluation = data.canEvaluate ? true : false;
- state.examSongId = data.id + "";
- state.examSongName = data.musicSheetName;
- // 解析扩展字段
- if (data.extConfigJson) {
- try {
- state.extConfigJson = JSON.parse(data.extConfigJson as string);
- } catch (error) {
- console.error("解析扩展字段错误:", error);
- }
- }
- state.isOpenMetronome = data.mp3Type === "MP3_METRONOME" ? true : false;
- state.needTick = data.isOpenMetronome;
- state.isShowFingering = data.showFingering ? true : false;
- state.music = data.audioFileUrl;
- state.accompany = data.metronomeUrl || data.metronomeUrl;
- state.midiUrl = data.midiUrl;
- state.parentCategoriesId = data.musicTag;
- state.playMode = data.audioType === "MP3" ? "MP3" : "MIDI";
- state.originSpeed = state.speed = data.speed;
- state.track = data.track;
- state.enableNotation = data.notation ? true : false;
- // 映射声部ID
- state.subjectId = mappingVoicePart(state.subjectId as any, "ORCHESTRA");
- // console.log("🚀 ~ state.subjectId:", state.subjectId);
- // 是否打击乐
- state.isPercussion =
- state.subjectId == 23 ||
- state.subjectId == 113 ||
- state.subjectId == 121 ||
- isRhythmicExercises();
- // 设置指法
- state.fingeringInfo = subjectFingering(state.subjectId);
- // console.log("🚀 ~ state.fingeringInfo:", state.fingeringInfo, state.subjectId, state.track)
- // state.isOpenPrepare = true
- };
- const setCustom = () => {
- if (state.extConfigJson.multitrack) {
- setGlobalData("multitrack", state.extConfigJson.multitrack);
- }
- };
- onMounted(async () => {
- const res = await api_musicPracticeRecordDetail(query.id);
- state.partIndex = Number(res?.data?.partIndex);
- let resultData = {} as any;
- try {
- resultData = JSON.parse(res?.data?.scoreData);
- } catch (error) {
- console.error("解析评测结果:", error);
- }
- // console.log("🚀 ~ resultData:", resultData);
- // @ts-ignore
- // resultData.musicalNotesPlayStats?.notesData.forEach((item) => item.rhythmicAssessment.result = 'EARLY')
- detailData.musicalNotesPlayStats = resultData.musicalNotesPlayStats?.notesData || [];
- detailData.userMeasureScore = resultData.userMeasureScore || {};
- scoreData.heardLevel = res.data?.heardLevel;
- scoreData.cadence = res.data?.cadence;
- scoreData.integrity = res.data?.integrity;
- scoreData.intonation = res.data?.intonation;
- scoreData.score = res.data?.score;
- scoreData.videoFilePath = res.data?.videoFilePath || res.data?.recordFilePath;
- state.isEvaluatReport = true;
- await getMusicDetail(resultData.musicalNotesPlayStats?.examSongId);
- // 从练习记录进入评测报告,默认显示五线谱
- // if (!query.musicRenderType) {
- // state.musicRenderType = EnumMusicRenderType.staff
- // }
- scoreData.musicType = query.musicRenderType ? query.musicRenderType : state.musicRenderType;
- detailData.isLoading = false;
- // Promise.all([
- // getMusicSheetDetail(resultData.musicalNotesPlayStats?.examSongId),
- // ]).then((values) => {
- // getMusicInfo(values[0]);
- // });
- });
- const getOffsetPosition = (type: keyof typeof colorsClass): string => {
- // 五线谱
- if (scoreData.musicType === 'staff') {
- switch (type) {
- case 'EARLY':
- return 'translateX(-3px)'
- case 'LATE':
- return 'translateX(3px)'
- case 'HIGH':
- return 'translateY(-2px)'
- case 'LOW':
- return 'translateY(2px)'
- default:
- return ''
- }
- } else {
- switch (type) {
- case 'EARLY':
- return 'translateX(-3px)'
- case 'LATE':
- return 'translateX(3px)'
- case 'HIGH':
- return 'translateY(-2px)'
- case 'LOW':
- return 'translateY(-10px)'
- default:
- return ''
- }
- }
- }
-
- const filterNotes = () => {
- let include = ['RIGHT', 'WRONG', 'NOT_PLAYED']
- if (scoreData.itemType === 'intonation') { // 音准
- include.push(...['HIGH', 'LOW', 'DURATION_INSUFFICIENT'])
- } else if (scoreData.itemType === 'cadence') { // 节奏
- include.push(...['EARLY', 'LATE'])
- } else if (scoreData.itemType === 'integrity') { // 完整性
- include = ['DURATION_INSUFFICIENT', 'RIGHT', 'NOT_PLAYED']
- }
- if (scoreData.itemType === 'cadence') {
- return detailData.musicalNotesPlayStats.filter((item: any) => include.includes(item.rhythmicAssessment.result))
- } else {
- return detailData.musicalNotesPlayStats.filter((item: any) => {
- let result = item.pitchAssessment.result
- if (scoreData.itemType === 'integrity') {
- result = (result === 'HIGH' || result === 'LOW' || result === 'WRONG') ? 'RIGHT' : result
- }
- return include.includes(result)
- })
- }
- }
-
- const setViewColor = () => {
- clearViewColor()
- const notes = filterNotes()
- // console.log(1111,notes)
- for (const note of notes) {
- const active = state.times[note.index]
- setTimeout(() => {
- if (useedid.value.includes(active.id)) {
- return
- }
- useedid.value.push(active.id)
- const svgEl = document.getElementById('vf-' + active.id)
- const stemEl = document.getElementById('vf-' + active.id + '-stem')
- let errType = scoreData.itemType === 'cadence' ? note.rhythmicAssessment.result : note.pitchAssessment.result
- // console.log(1111222,errType)
- const isNeedCopyElement = scoreData.itemType === 'integrity' ? false : ['HIGH', 'LOW', 'EARLY', 'LATE'].includes(
- errType
- )
- if (scoreData.itemType === 'integrity') {
- errType = errType = (note.pitchAssessment.result === 'HIGH' || note.pitchAssessment.result === 'LOW' || note.pitchAssessment.result === 'WRONG') ? 'RIGHT' : errType
- }
- stemEl?.classList.add(colorsClass[errType])
- svgEl?.classList.add(colorsClass[errType])
- if (svgEl && isNeedCopyElement) {
- stemEl?.classList.remove(colorsClass[errType])
- svgEl?.classList.remove(colorsClass[errType])
- let copySvg: any = null;
- // 五线谱
- if (scoreData.musicType === 'staff') {
- stemEl?.classList.add(colorsClass.RIGHT)
- svgEl?.classList.add(colorsClass.RIGHT)
- copySvg = svgEl.querySelector('.vf-notehead')!.cloneNode(true) as SVGSVGElement
- } else {
- //copySvg = svgEl.querySelector('.vf-numbered-note-head')!.cloneNode(true) as SVGSVGElement
-
- if (isNeedCopyElement) {
- svgEl?.classList.add(styles.inaccuracy)
- const targetId = errType === 'HIGH' ? 'topSvg' : errType === 'LOW' ? 'bottomSvg' : errType === 'EARLY' ? 'leftSvg' : errType === 'LATE' ? 'rightSvg' : ''
- copySvg = document.getElementById(targetId)!.cloneNode(true) as SVGSVGElement
- const { width, height } = svgEl.getBoundingClientRect() || {}
- // @ts-ignore
- let { x, y } = svgEl?.getBBox() || {}
- x = errType === 'HIGH' ? x + (width - 15)/2 + 2 : errType === 'LOW' ? x + (width - 15)/2 + 2 : errType === 'EARLY' ? x - Math.abs((width - 15)/2) - 12 : errType === 'LATE' ? x + width + 6 : x
- y = errType === 'HIGH' ? y - Math.abs((height-10)/2) - 10 : errType === 'LOW' ? y + height + 8 : errType === 'EARLY' ? y + (height - 10)/2 : errType === 'LATE' ? y + (height - 10)/2 : y
- copySvg.setAttribute("x", x)
- copySvg.setAttribute("y", y)
- }
- // console.log(x,y,copySvg.getBoundingClientRect())
- // const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
- // rect.setAttribute("x", 0 +'px');
- // rect.setAttribute("y", 0+'px');
- // rect.setAttribute("width", `50`);
- // rect.setAttribute("height", `50`);
- // rect.setAttribute("fill", "#FF4444");
- // svgEl.prepend(rect);
- }
- if (scoreData.musicType === 'staff') {
- copySvg.style.transform = getOffsetPosition(errType)
- //svgEl.style.opacity = '.7'
- if (stemEl) {
- //stemEl.style.opacity = '.7'
- }
- }
- copySvg.id = 'vf-' + active.id + '-copy'
- copySvg?.classList.add(colorsClass[errType])
- // stemEl?.classList.add(colorsClass.RIGHT)
- // @ts-ignore
- state.osmd?.container.querySelector('svg')!.insertAdjacentElement('afterbegin', copySvg)
- // svgEl?.parentElement?.appendChild(copySvg)
- }
- }, 300)
- }
- }
-
- const removeClass = (el?: HTMLElement | null) => {
- if (!el) return
- const classList = el.classList.values()
- for (const val of classList) {
- if (val?.indexOf('vf-') !== 0) {
- el.classList.remove(val)
- }
- }
- }
-
- const clearViewColor = () => {
- for (const id of useedid.value) {
- removeClass(document.getElementById('vf-' + id))
- removeClass(document.getElementById('vf-' + id + '-stem'))
- const qid = 'vf-' + id + '-copy'
- const copyEl = document.getElementById(qid)
- if (copyEl) {
- copyEl.remove()
- }
- }
- useedid.value = []
- }
-
- const setPathColor = () => {
- console.log(11111,detailData.musicalNotesPlayStats,scoreData.itemType)
- for (const note of detailData.musicalNotesPlayStats) {
- const active = state.times[note.index];
- const svgEl = active?.id ? document.getElementById("vf-" + active?.id) : null;
- switch (scoreData.itemType) {
- case "intonation":
- svgEl?.classList.add(colorsClass.pitch[note.pitchAssessment.result]);
- break;
- case "cadence":
- svgEl?.classList.add(colorsClass.rhythmic[note.rhythmicAssessment.result]);
- break;
- case "integrity":
- svgEl?.classList.add(colorsClass.pitch[note.pitchAssessment.result]);
- break;
- default:
- break;
- }
- }
- };
- const setMearureColor = () => {
- for (let key in detailData.userMeasureScore) {
- addMeasureScore(detailData.userMeasureScore[key], false);
- }
- };
- /** 渲染完成 */
- const handleRendered = (osmd: any) => {
- state.musicRendered = true;
- state.osmd = osmd;
- state.times = formateTimes(osmd);
- console.log("🚀 ~ state.times:", state.times);
- // @ts-ignore
- const beams = Array.from(new Set(document.getElementsByClassName('vf-beam')))
- beams.forEach((item: any) => {
- item.classList.add(styles.beam)
- })
- //setPathColor();
- setViewColor();
- // setMearureColor();
- api_cloudLoading();
- };
- onMounted(() => {
- window.addEventListener("resize", resetMusicScore);
- });
- onBeforeUnmount(() => {
- window.removeEventListener("resize", resetMusicScore);
- });
- watch(
- () => scoreData.itemType,
- () => {
- setViewColor();
- }
- );
- return () => (
- <div
- class={[styles.detail, state.setting.eyeProtection && "eyeProtection", styles.shareBox]}
- style={{ paddingLeft: detailData.paddingLeft }}
- >
- <Transition name="van-fade">
- {!state.musicRendered && (
- <div class={styles.skeleton}>
- <Skeleton class={styles.skeleton} row={8} />
- </div>
- )}
- </Transition>
- <div
- class={[styles.headHeight, detailData.headerHide && styles.headHide]}
- onClick={(e: Event) => e.stopPropagation()}
- >
- <Transition name="van-slide-down">
- {state.musicRendered && <ShareTop scoreData={scoreData} />}
- </Transition>
- </div>
- <div
- id="scrollContainer"
- class={[styles.container, !state.setting.displayCursor && "hideCursor"]}
- >
- {/* 曲谱渲染 */}
- {!detailData.isLoading && <MusicScore musicColor={'#ADADAD'} onRendered={handleRendered} />}
- {
- <div class={styles.arrowSvg}>
- <TopArrow />
- <BottomArrow />
- <LeftArrow />
- <RightArrow />
- </div>
- }
- </div>
- </div>
- );
- },
- });
|