index.tsx 7.7 KB

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