index.tsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. import { Skeleton } from "vant";
  2. import { computed, defineComponent, nextTick, onBeforeMount, onMounted, reactive, Transition, watch, watchEffect } from "vue";
  3. import { useRoute } from "vue-router";
  4. import { formateTimes } from "../../helpers/formateMusic";
  5. import Metronome, { metronomeData } from "../../helpers/metronome";
  6. import state, { isRhythmicExercises } from "../../state";
  7. import { storeData } from "../../store";
  8. import { setGlobalData } from "../../utils";
  9. import AudioList from "../../view/audio-list";
  10. import MusicScore, { resetMusicScore } from "../../view/music-score";
  11. import { sysMusicScoreAccompanimentQueryPage, sysMusicScoreCategoriesQueryTree } from "../api";
  12. import EvaluatModel from "../evaluat-model";
  13. import HeaderTop from "../header-top";
  14. import styles from "./index.module.less";
  15. import { api_openCamera, api_setStatusBarVisibility, isSpecialShapedScreen } from "/src/helpers/communication";
  16. import { getQuery } from "/src/utils/queryString";
  17. import Evaluating, { evaluatingData } from "/src/view/evaluating";
  18. import MeasureSpeed from "/src/view/plugins/measure-speed";
  19. import { mappingVoicePart, subjectFingering } from "/src/view/fingering/fingering-config";
  20. import Fingering from "/src/view/fingering";
  21. import store from "store";
  22. export default defineComponent({
  23. name: "music-list",
  24. setup() {
  25. const route = useRoute();
  26. const query: any = {
  27. ...getQuery(),
  28. ...route.query,
  29. };
  30. const detailData = reactive({
  31. isLoading: true,
  32. paddingLeft: "",
  33. });
  34. const getAPPData = async () => {
  35. const screenData = await isSpecialShapedScreen();
  36. if (screenData?.content) {
  37. // console.log("🚀 ~ screenData:", screenData.content);
  38. const { isSpecialShapedScreen, notchHeight } = screenData.content;
  39. if (isSpecialShapedScreen) {
  40. detailData.paddingLeft = 25 + "px";
  41. }
  42. }
  43. };
  44. onBeforeMount(() => {
  45. getAPPData();
  46. api_setStatusBarVisibility();
  47. const settting = store.get("musicscoresetting");
  48. if (settting) {
  49. state.setting = settting;
  50. if (state.setting.camera) {
  51. api_openCamera();
  52. }
  53. // console.log("🚀 ~ settting:", settting)
  54. }
  55. });
  56. // console.log(route.params, query)
  57. /** 获取曲谱数据 */
  58. const getMusicInfo = (res: any) => {
  59. const index = query["part-index"] ? parseInt(query["part-index"] as string) : 0;
  60. const musicInfo = {
  61. ...res.data,
  62. ...res.data.background[index],
  63. };
  64. // console.log("🚀 ~ musicInfo:", musicInfo);
  65. setState(musicInfo, index);
  66. setCustom();
  67. detailData.isLoading = false;
  68. };
  69. const setState = (data: any, index: number) => {
  70. state.appName = 'COLEXIU'
  71. state.detailId = data.id;
  72. state.xmlUrl = data.xmlFileUrl;
  73. state.partIndex = index;
  74. state.subjectId = data.musicSubject;
  75. state.categoriesId = data.categoriesId;
  76. state.categoriesName = data.musicTagNames;
  77. state.enableEvaluation = data.canEvaluate ? true : false;
  78. state.examSongId = data.id + "";
  79. state.examSongName = data.musicSheetName;
  80. // 解析扩展字段
  81. if (data.extConfigJson) {
  82. try {
  83. state.extConfigJson = JSON.parse(data.extConfigJson as string);
  84. } catch (error) {
  85. console.error("解析扩展字段错误:", error);
  86. }
  87. }
  88. state.isOpenMetronome = data.mp3Type === "MP3_METRONOME" ? true : false;
  89. state.needTick = data.isOpenMetronome;
  90. state.isShowFingering = data.showFingering ? true : false;
  91. state.music = data.audioFileUrl;
  92. state.accompany = data.metronomeUrl || data.metronomeUrl;
  93. state.midiUrl = data.midiUrl;
  94. state.parentCategoriesId = data.musicTag;
  95. state.playMode = data.audioType === "MP3" ? "mp3" : "midi";
  96. state.originSpeed = state.speed = data.playSpeed;
  97. state.track = data.track;
  98. // 映射声部ID
  99. state.subjectId = mappingVoicePart(state.track as any, "COLEXIU");
  100. // 是否打击乐
  101. state.isPercussion = state.subjectId == 23 || state.subjectId == 113 || state.subjectId == 121 || isRhythmicExercises();
  102. // 设置指法
  103. state.fingeringInfo = subjectFingering(state.subjectId);
  104. // console.log("🚀 ~ state.fingeringInfo:", state.fingeringInfo, state.subjectId)
  105. };
  106. const setCustom = () => {
  107. if (state.extConfigJson.multitrack) {
  108. setGlobalData("multitrack", state.extConfigJson.multitrack);
  109. }
  110. };
  111. onMounted(() => {
  112. (window as any).appName = "colexiu";
  113. Promise.all([sysMusicScoreAccompanimentQueryPage(query.id)]).then((values) => {
  114. getMusicInfo(values[0]);
  115. });
  116. });
  117. /** 渲染完成 */
  118. const handleRendered = (osmd: any) => {
  119. state.musicRendered = true;
  120. state.osmd = osmd;
  121. const saveSpeed = (store.get('speeds') || {})[state.examSongId]
  122. const bpm = (osmd as any).bpm || osmd.Sheet.userStartTempoInBPM
  123. state.originSpeed = state.speed = saveSpeed || bpm || 100
  124. state.times = formateTimes(osmd);
  125. console.log("🚀 ~ state.times:", state.times);
  126. try {
  127. metronomeData.metro = new Metronome();
  128. metronomeData.metro.init(state.times);
  129. } catch (error) {}
  130. };
  131. /** 指法配置 */
  132. const fingerConfig = computed<any>(() => {
  133. if (state.setting.displayFingering && state.fingeringInfo?.name) {
  134. if (state.fingeringInfo.direction === "transverse") {
  135. return {
  136. container: {
  137. paddingBottom: state.fingeringInfo.height,
  138. },
  139. fingerBox: {
  140. height: state.fingeringInfo.height,
  141. },
  142. };
  143. } else {
  144. return {
  145. container: {
  146. paddingRight: state.fingeringInfo.width,
  147. },
  148. fingerBox: {
  149. position: "absolute",
  150. width: state.fingeringInfo.width,
  151. height: "100%",
  152. right: 0,
  153. top: 0,
  154. },
  155. };
  156. }
  157. }
  158. return {
  159. container: {},
  160. fingerBox: {},
  161. };
  162. });
  163. // 监听指法显示
  164. watch(
  165. () => state.setting.displayFingering,
  166. () => {
  167. if (state.fingeringInfo.direction === "vertical") {
  168. if (state.setting.displayFingering) {
  169. document.getElementById("musicAndSelection")?.style.removeProperty("--music-zoom");
  170. } else {
  171. nextTick(() => {
  172. resetMusicScore();
  173. });
  174. }
  175. }
  176. }
  177. );
  178. return () => (
  179. <div class={[styles.detail, state.setting.camera && styles.opencamera]} style={{ paddingLeft: detailData.paddingLeft }}>
  180. {!state.musicRendered && (
  181. <div class={styles.skeleton}>
  182. <Skeleton class={styles.skeleton} row={8} />
  183. </div>
  184. )}
  185. <div class={styles.headHeight}>
  186. <Transition name="van-slide-down">{state.musicRendered && <HeaderTop />}</Transition>
  187. </div>
  188. <div
  189. style={{ ...fingerConfig.value.container }}
  190. class={[styles.container, state.setting.eyeProtection && "eyeProtection", !state.setting.displayCursor && "hideCursor"]}
  191. >
  192. {/* 曲谱渲染 */}
  193. {!detailData.isLoading && <MusicScore onRendered={handleRendered} />}
  194. {/* 播放 */}
  195. {!detailData.isLoading && <AudioList />}
  196. {/* 评测 */}
  197. {state.modeType === "evaluating" && (
  198. <>
  199. <Evaluating />
  200. {evaluatingData.rendered && <EvaluatModel />}
  201. </>
  202. )}
  203. {/* 指法 */}
  204. {state.setting.displayFingering && state.fingeringInfo?.name && (
  205. <div style={{ ...fingerConfig.value.fingerBox }}>
  206. <Fingering />
  207. </div>
  208. )}
  209. </div>
  210. {/* 公用的插件 */}
  211. <div class={styles.plugins}>
  212. {state.musicRendered && (
  213. <>
  214. <MeasureSpeed />
  215. </>
  216. )}
  217. </div>
  218. </div>
  219. );
  220. },
  221. });