index.tsx 17 KB

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