index.tsx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. import { Skeleton } from "vant";
  2. import { defineComponent, onBeforeMount, onBeforeUnmount, onMounted, reactive, Transition, watch, ref } from "vue";
  3. import { formateTimes } from "../../helpers/formateMusic";
  4. import state, { isRhythmicExercises, getMusicDetail, EnumMusicRenderType } from "../../state";
  5. import { setGlobalData } from "../../utils";
  6. import MusicScore from "../../view/music-score";
  7. import styles from "./index.module.less";
  8. import { api_cloudLoading, api_setStatusBarVisibility, isSpecialShapedScreen } from "/src/helpers/communication";
  9. import { getQuery } from "/src/utils/queryString";
  10. import { mappingVoicePart, subjectFingering } from "/src/view/fingering/fingering-config";
  11. import { api_musicPracticeRecordDetail, sysMusicScoreAccompanimentQueryPage } from "../api";
  12. import { getMusicSheetDetail } from "/src/utils/baseApi";
  13. import ShareTop from "./component/share-top";
  14. import { addMeasureScore } from "/src/view/evaluating";
  15. import TopArrow from "./component/note/topArrow";
  16. import BottomArrow from "./component/note/bottomArrow";
  17. import LeftArrow from "./component/note/leftArrow";
  18. import RightArrow from "./component/note/rightArrow";
  19. const colorsClass: any = {
  20. RIGHT: styles.right, // 正确
  21. WRONG: styles.wrong, // 错误
  22. NOT_PLAYED: styles.notPlay, // 未演奏
  23. EARLY: styles.cadence_fast, // 节奏快
  24. LATE: styles.cadence_slow, // 节奏慢
  25. HIGH: styles.intonation_high, // 音准高
  26. LOW: styles.intonation_low, // 音准低
  27. SHORT: styles.integrity_wrong, // 完整性(时值)不足
  28. };
  29. // const colorsClass: any = {
  30. // /** 音准 */
  31. // pitch: {
  32. // /** 高了 */
  33. // HIGH: styles.intonation_high,
  34. // /** 正常 */
  35. // RIGHT: styles.intonation_right,
  36. // /** 低了 */
  37. // LOW: styles.intonation_low,
  38. // /** 未演奏 */
  39. // NOT_PLAYED: styles.notPlay,
  40. // /** 错误 */
  41. // WRONG: styles.intonation_wrong,
  42. // /** 时值不足 */
  43. // DURATION_INSUFFICIENT: styles.integrity_wrong
  44. // },
  45. // /** 节奏 */
  46. // rhythmic: {
  47. // /** 过早 */
  48. // EARLY: styles.cadence_fast,
  49. // /** 正常 */
  50. // RIGHT: styles.cadence_right,
  51. // /** 过迟 */
  52. // LATE: styles.cadence_slow,
  53. // /** 未演奏 */
  54. // NOT_PLAYED: styles.notPlay,
  55. // /** 错误 */
  56. // WRONG: styles.cadence_wrong
  57. // }
  58. // }
  59. export default defineComponent({
  60. name: "music-list",
  61. setup() {
  62. const query: any = getQuery();
  63. const useedid = ref<string[]>([]);
  64. const allNote = ref<any[]>([]);
  65. const scoreData = reactive({
  66. videoFilePath: "", // 回放视频路径
  67. cadence: 0,
  68. integrity: 0,
  69. intonation: 0,
  70. score: 0,
  71. speed: 0,
  72. heardLevel: "",
  73. itemType: "intonation",
  74. musicType: "staff",
  75. });
  76. const detailData = reactive({
  77. isLoading: true,
  78. paddingLeft: "",
  79. headerHide: false,
  80. musicalNotesPlayStats: [] as any[],
  81. userMeasureScore: {} as any,
  82. isSpecialReport: false, // 是否是特殊的评测记录(含有listent、play等曲子的评测记录,非选段状态下可能返回的评测数据不是从第1小节开始的,这种情况需要兼容处理)
  83. });
  84. const getAPPData = async () => {
  85. const screenData = await isSpecialShapedScreen();
  86. if (screenData?.content) {
  87. const { isSpecialShapedScreen, notchHeight } = screenData.content;
  88. if (isSpecialShapedScreen) {
  89. detailData.paddingLeft = 25 + "px";
  90. }
  91. }
  92. // 普通webview 没有获取异性屏的方法
  93. detailData.paddingLeft = 20 + "px";
  94. };
  95. onBeforeMount(() => {
  96. getAPPData();
  97. api_setStatusBarVisibility();
  98. });
  99. // console.log(route.params, query)
  100. /** 获取曲谱数据 */
  101. const getMusicInfo = (res: any) => {
  102. const index = state.partIndex;
  103. const musicInfo = {
  104. ...res.data,
  105. ...res.data.background[index],
  106. };
  107. // console.log("🚀 ~ musicInfo:", musicInfo);
  108. setState(musicInfo, index);
  109. setCustom();
  110. detailData.isLoading = false;
  111. };
  112. const setState = (data: any, index: number) => {
  113. // console.log("🚀 ~ data:", data)
  114. state.scrollContainer = "scrollContainer";
  115. state.detailId = data.id;
  116. state.xmlUrl = data.xmlFileUrl;
  117. state.partIndex = index;
  118. state.subjectId = data.musicSubject;
  119. state.categoriesId = data.categoriesId;
  120. state.categoriesName = data.musicTagNames;
  121. state.enableEvaluation = data.canEvaluate ? true : false;
  122. state.examSongId = data.id + "";
  123. state.examSongName = data.musicSheetName;
  124. // 解析扩展字段
  125. if (data.extConfigJson) {
  126. try {
  127. state.extConfigJson = JSON.parse(data.extConfigJson as string);
  128. } catch (error) {
  129. console.error("解析扩展字段错误:", error);
  130. }
  131. }
  132. state.isOpenMetronome = data.mp3Type === "MP3_METRONOME" ? true : false;
  133. state.needTick = data.isOpenMetronome;
  134. state.isShowFingering = data.showFingering ? true : false;
  135. state.music = data.audioFileUrl;
  136. state.accompany = data.metronomeUrl || data.metronomeUrl;
  137. state.midiUrl = data.midiUrl;
  138. state.parentCategoriesId = data.musicTag;
  139. state.playMode = data.audioType === "MP3" ? "MP3" : "MIDI";
  140. state.originSpeed = state.speed = data.speed;
  141. state.track = data.track;
  142. state.enableNotation = data.notation ? true : false;
  143. // 映射声部ID
  144. state.subjectId = mappingVoicePart(state.subjectId as any, "ORCHESTRA");
  145. // console.log("🚀 ~ state.subjectId:", state.subjectId);
  146. // 是否打击乐
  147. state.isPercussion = state.subjectId == 23 || state.subjectId == 113 || state.subjectId == 121 || isRhythmicExercises();
  148. // 设置指法
  149. state.fingeringInfo = subjectFingering(state.subjectId);
  150. // console.log("🚀 ~ state.fingeringInfo:", state.fingeringInfo, state.subjectId, state.track)
  151. // state.isOpenPrepare = true
  152. };
  153. const setCustom = () => {
  154. if (state.extConfigJson.multitrack) {
  155. setGlobalData("multitrack", state.extConfigJson.multitrack);
  156. }
  157. };
  158. onMounted(async () => {
  159. state.isEvaluatReport = true;
  160. const res = await api_musicPracticeRecordDetail(query.id);
  161. state.partIndex = Number(res?.data?.partIndex);
  162. let resultData = {} as any;
  163. try {
  164. resultData = JSON.parse(res?.data?.scoreData);
  165. } catch (error) {
  166. console.error("解析评测结果:", error);
  167. }
  168. // console.log("🚀 ~ resultData:", resultData);
  169. // @ts-ignore
  170. // resultData.musicalNotesPlayStats?.notesData.forEach((item) => item.rhythmicAssessment.result = 'EARLY')
  171. console.log('结果11',resultData)
  172. detailData.musicalNotesPlayStats = resultData.musicalNotesPlayStats?.notesData || [];
  173. detailData.userMeasureScore = resultData.userMeasureScore || {};
  174. scoreData.heardLevel = res.data?.heardLevel;
  175. scoreData.cadence = res.data?.cadence;
  176. scoreData.integrity = res.data?.integrity;
  177. scoreData.intonation = res.data?.intonation;
  178. scoreData.score = res.data?.score;
  179. scoreData.speed = res.data?.speed;
  180. scoreData.videoFilePath = res.data?.videoFilePath || res.data?.recordFilePath;
  181. await getMusicDetail(resultData.musicalNotesPlayStats?.examSongId);
  182. // 从练习记录进入评测报告,默认显示五线谱
  183. // if (!query.musicRenderType) {
  184. // state.musicRenderType = EnumMusicRenderType.staff
  185. // }
  186. // 评测报告展示什么类型的谱面
  187. state.isSingleLine = false;
  188. scoreData.musicType = query.musicRenderType ? query.musicRenderType : resultData.musicType ? resultData.musicType : state.musicRenderType;
  189. // @ts-ignore
  190. state.musicRenderType = scoreData.musicType;
  191. detailData.isLoading = false;
  192. // Promise.all([
  193. // getMusicSheetDetail(resultData.musicalNotesPlayStats?.examSongId),
  194. // ]).then((values) => {
  195. // getMusicInfo(values[0]);
  196. // });
  197. });
  198. const getOffsetPosition = (type: keyof typeof colorsClass): string => {
  199. // 五线谱
  200. if (scoreData.musicType === "staff") {
  201. switch (type) {
  202. case "EARLY":
  203. return "translateX(-3px)";
  204. case "LATE":
  205. return "translateX(3px)";
  206. case "HIGH":
  207. return "translateY(-2px)";
  208. case "LOW":
  209. return "translateY(2px)";
  210. default:
  211. return "";
  212. }
  213. } else {
  214. switch (type) {
  215. case "EARLY":
  216. return "translateX(-3px)";
  217. case "LATE":
  218. return "translateX(3px)";
  219. case "HIGH":
  220. return "translateY(-2px)";
  221. case "LOW":
  222. return "translateY(-10px)";
  223. default:
  224. return "";
  225. }
  226. }
  227. };
  228. const filterNotes = () => {
  229. let include = ["RIGHT", "WRONG", "NOT_PLAYED"];
  230. if (scoreData.itemType === "intonation") {
  231. // 音准
  232. include.push(...["HIGH", "LOW"]);
  233. } else if (scoreData.itemType === "cadence") {
  234. // 节奏
  235. include.push(...["EARLY", "LATE"]);
  236. } else if (scoreData.itemType === "integrity") {
  237. // 完整性
  238. include = ["SHORT", "NORMAL", "NOT_PLAYED"];
  239. }
  240. if (scoreData.itemType === "cadence") {
  241. return detailData.musicalNotesPlayStats.filter((item: any) => include.includes(item.rhythmicAssessment.result));
  242. } else if (scoreData.itemType === "integrity") {
  243. return detailData.musicalNotesPlayStats.filter((item: any) => include.includes(item.integrityAssessment?.result));
  244. } else {
  245. return detailData.musicalNotesPlayStats.filter((item: any) => {
  246. let result = item.pitchAssessment.result;
  247. // if (scoreData.itemType === "integrity") {
  248. // result = result === "HIGH" || result === "LOW" || result === "WRONG" ? "RIGHT" : result;
  249. // }
  250. return include.includes(result);
  251. });
  252. }
  253. };
  254. const setViewColor = () => {
  255. clearViewColor();
  256. const notes = filterNotes();
  257. // console.log(1111,notes)
  258. for (const note of notes) {
  259. const idx = note.musicalNotesIndex !== undefined ? note.musicalNotesIndex : note.index;
  260. let active = allNote.value[idx];
  261. if (detailData.isSpecialReport) {
  262. active = allNote.value.find((item: any) => item.i === idx)
  263. }
  264. setTimeout(() => {
  265. if (useedid.value.includes(active.id)) {
  266. return;
  267. }
  268. useedid.value.push(active.id);
  269. const svgEl = document.getElementById("vf-" + active.id);
  270. const stemEl = document.getElementById("vf-" + active.id + "-stem");
  271. let errType = scoreData.itemType === "cadence" ? note.rhythmicAssessment.result : scoreData.itemType === "integrity" ? note.integrityAssessment.result : note.pitchAssessment.result;
  272. // console.log(1111222,errType)
  273. /**
  274. * 新版小酷AI不需要在当前的音符复制出来一个音符,所以注释掉isNeedCopyElement和copySvg
  275. */
  276. // const isNeedCopyElement = scoreData.itemType === "integrity" ? false : ["HIGH", "LOW", "EARLY", "LATE"].includes(errType);
  277. const isNeedCopyElement = false;
  278. // if (scoreData.itemType === "integrity") {
  279. // errType = errType = note.pitchAssessment.result === "HIGH" || note.pitchAssessment.result === "LOW" || note.pitchAssessment.result === "WRONG" ? "RIGHT" : errType;
  280. // }
  281. if (scoreData.itemType === "integrity") {
  282. errType = errType = note.integrityAssessment.result === "NORMAL" ? "RIGHT" : note.integrityAssessment.result === "SHORT" ? "SHORT" : errType;
  283. }
  284. stemEl?.classList.add(colorsClass[errType]);
  285. svgEl?.classList.add(colorsClass[errType]);
  286. // console.log(123456,'添加颜色',errType)
  287. // 评测过的音符,需要给小节添加背景色
  288. // if (errType !== "NOT_PLAYED") {
  289. // const staveNote = svgEl?.parentNode?.parentNode?.querySelector(".vf-stave");
  290. // if (staveNote) {
  291. // staveNote.querySelector(".vf-custom-bg")?.setAttribute("fill", "#132D4C");
  292. // }
  293. // }
  294. if (svgEl && isNeedCopyElement) {
  295. stemEl?.classList.remove(colorsClass[errType]);
  296. svgEl?.classList.remove(colorsClass[errType]);
  297. let copySvg: any = null;
  298. // 五线谱
  299. if (scoreData.musicType === "staff") {
  300. stemEl?.classList.add(colorsClass.RIGHT);
  301. svgEl?.classList.add(colorsClass.RIGHT);
  302. // copySvg = svgEl.querySelector(".vf-notehead")!.cloneNode(true) as SVGSVGElement;
  303. } else {
  304. //copySvg = svgEl.querySelector('.vf-numbered-note-head')!.cloneNode(true) as SVGSVGElement
  305. if (isNeedCopyElement) {
  306. svgEl?.classList.add(styles.inaccuracy);
  307. const targetId = errType === "HIGH" ? "topSvg" : errType === "LOW" ? "bottomSvg" : errType === "EARLY" ? "leftSvg" : errType === "LATE" ? "rightSvg" : "";
  308. // copySvg = document.getElementById(targetId)!.cloneNode(true) as SVGSVGElement;
  309. const { width, height } = svgEl.getBoundingClientRect() || {};
  310. // @ts-ignore
  311. let { x, y } = svgEl?.getBBox() || {};
  312. 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;
  313. 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;
  314. copySvg.setAttribute("x", x);
  315. copySvg.setAttribute("y", y);
  316. }
  317. // console.log(x,y,copySvg.getBoundingClientRect())
  318. // const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
  319. // rect.setAttribute("x", 0 +'px');
  320. // rect.setAttribute("y", 0+'px');
  321. // rect.setAttribute("width", `50`);
  322. // rect.setAttribute("height", `50`);
  323. // rect.setAttribute("fill", "#FF4444");
  324. // svgEl.prepend(rect);
  325. }
  326. if (scoreData.musicType === "staff") {
  327. // copySvg.style.transform = getOffsetPosition(errType);
  328. if (stemEl) {
  329. //
  330. }
  331. }
  332. // copySvg.id = "vf-" + active.id + "-copy";
  333. // copySvg?.classList.add(colorsClass[errType]);
  334. // @ts-ignore
  335. // state.osmd?.container.querySelector("svg")!.insertAdjacentElement("afterbegin", copySvg);
  336. }
  337. }, 300);
  338. }
  339. };
  340. const removeClass = (el?: HTMLElement | null) => {
  341. if (!el) return;
  342. const classList = el.classList.values();
  343. for (const val of classList) {
  344. if (val?.indexOf("vf-") !== 0) {
  345. el.classList.remove(val);
  346. }
  347. }
  348. };
  349. const clearViewColor = () => {
  350. for (const id of useedid.value) {
  351. removeClass(document.getElementById("vf-" + id));
  352. removeClass(document.getElementById("vf-" + id + "-stem"));
  353. const qid = "vf-" + id + "-copy";
  354. const copyEl = document.getElementById(qid);
  355. if (copyEl) {
  356. copyEl.remove();
  357. }
  358. }
  359. useedid.value = [];
  360. };
  361. const setPathColor = () => {
  362. console.log(11111, detailData.musicalNotesPlayStats, scoreData.itemType);
  363. for (const note of detailData.musicalNotesPlayStats) {
  364. const active = allNote.value[note.index];
  365. const svgEl = active?.id ? document.getElementById("vf-" + active?.id) : null;
  366. switch (scoreData.itemType) {
  367. case "intonation":
  368. svgEl?.classList.add(colorsClass.pitch[note.pitchAssessment.result]);
  369. break;
  370. case "cadence":
  371. svgEl?.classList.add(colorsClass.rhythmic[note.rhythmicAssessment.result]);
  372. break;
  373. case "integrity":
  374. svgEl?.classList.add(colorsClass.pitch[note.integrityAssessment.result]);
  375. break;
  376. default:
  377. break;
  378. }
  379. }
  380. };
  381. const setMearureColor = () => {
  382. for (let key in detailData.userMeasureScore) {
  383. addMeasureScore(detailData.userMeasureScore[key], false);
  384. }
  385. };
  386. /** 渲染完成 */
  387. const handleRendered = (osmd: any) => {
  388. state.musicRendered = true;
  389. state.osmd = osmd;
  390. allNote.value = formateTimes(osmd);
  391. console.log("🚀 ~ state.times:", allNote.value);
  392. // @ts-ignore
  393. const startMeasureNum = detailData.musicalNotesPlayStats?.[0]?.measureRenderIndex, endMeasureNum = detailData.musicalNotesPlayStats?.last()?.measureRenderIndex;
  394. allNote.value = allNote.value.filter((item: any) => (item.MeasureNumberXML >= startMeasureNum+1 && item.MeasureNumberXML <= endMeasureNum+1))
  395. // @ts-ignore
  396. const beams = Array.from(new Set(document.getElementsByClassName("vf-beam")));
  397. beams.forEach((item: any) => {
  398. item.classList.add(styles.beam);
  399. });
  400. detailData.isSpecialReport = startMeasureNum > 0 && detailData.musicalNotesPlayStats?.[0]?.musicalNotesIndex != 0;
  401. //setPathColor();
  402. setViewColor();
  403. // setMearureColor();
  404. api_cloudLoading();
  405. };
  406. watch(
  407. () => scoreData.itemType,
  408. () => {
  409. setViewColor();
  410. }
  411. );
  412. return () => (
  413. <div class={[styles.detail, state.setting.eyeProtection && "eyeProtection", styles.shareBox]} style={{ paddingLeft: detailData.paddingLeft }}>
  414. <Transition name="van-fade">
  415. {!state.musicRendered && (
  416. <div class={styles.skeleton}>
  417. <Skeleton class={styles.skeleton} row={8} />
  418. </div>
  419. )}
  420. </Transition>
  421. <div class={["headHeight", styles.headHeight, detailData.headerHide && styles.headHide]} onClick={(e: Event) => e.stopPropagation()}>
  422. <Transition name="van-slide-down">{state.musicRendered && <ShareTop scoreData={scoreData} />}</Transition>
  423. </div>
  424. <div id="scrollContainer" class={[styles.container, !state.setting.displayCursor && "hideCursor"]}>
  425. {/* 曲谱渲染 */}
  426. {!detailData.isLoading && <MusicScore musicColor={"#000000"} onRendered={handleRendered} />}
  427. {
  428. <div class={styles.arrowSvg}>
  429. <TopArrow />
  430. <BottomArrow />
  431. <LeftArrow />
  432. <RightArrow />
  433. </div>
  434. }
  435. </div>
  436. </div>
  437. );
  438. },
  439. });