index.tsx 18 KB

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