123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- import { Skeleton } from "vant";
- import { computed, defineComponent, nextTick, onBeforeMount, onBeforeUnmount, onMounted, reactive, Transition, watch, watchEffect } from "vue";
- import { useRoute } from "vue-router";
- import { formateTimes } from "../../helpers/formateMusic";
- import Metronome, { metronomeData } from "../../helpers/metronome";
- import state, { isRhythmicExercises, musicscoresettingKey } from "../../state";
- import { storeData } from "../../store";
- import { setGlobalData } from "../../utils";
- import AudioList from "../../view/audio-list";
- import MusicScore, { resetMusicScore } from "../../view/music-score";
- import { sysMusicScoreAccompanimentQueryPage } from "../api";
- import EvaluatModel from "../evaluat-model";
- import HeaderTop from "../header-top";
- import styles from "./index.module.less";
- import { api_cloudLoading, api_openCamera, api_setStatusBarVisibility, isSpecialShapedScreen } from "/src/helpers/communication";
- import { getQuery } from "/src/utils/queryString";
- import Evaluating, { evaluatingData } from "/src/view/evaluating";
- import MeasureSpeed from "/src/view/plugins/measure-speed";
- import { mappingVoicePart, subjectFingering } from "/src/view/fingering/fingering-config";
- import Fingering from "/src/view/fingering";
- import store from "store";
- import Tick, { handleInitTick } from "/src/view/tick";
- import FollowPractice from "/src/view/follow-practice";
- import FollowModel from "../follow-model";
- import RecordingTime from "../custom-plugins/recording-time";
- import UnitTest from "../custom-plugins/unitTest";
- export default defineComponent({
- name: "music-list",
- setup() {
- const query: any = getQuery();
- const detailData = reactive({
- isLoading: true,
- paddingLeft: "",
- headerHide: false,
- });
- const getAPPData = async () => {
- const screenData = await isSpecialShapedScreen();
- if (screenData?.content) {
- // console.log("🚀 ~ screenData:", screenData.content);
- const { isSpecialShapedScreen, notchHeight } = screenData.content;
- if (isSpecialShapedScreen) {
- detailData.paddingLeft = 25 + "px";
- }
- }
- };
- onBeforeMount(() => {
- getAPPData();
- api_setStatusBarVisibility();
- const settting = store.get(musicscoresettingKey);
- if (settting) {
- state.setting = settting;
- if (state.setting.camera) {
- api_openCamera();
- }
- // console.log("🚀 ~ settting:", settting)
- }
- });
- // console.log(route.params, query)
- /** 获取曲谱数据 */
- const getMusicInfo = (res: any) => {
- const index = query["part-index"] ? parseInt(query["part-index"] as string) : 0;
- const musicInfo = {
- ...res.data,
- ...res.data.background[index],
- };
- // console.log("🚀 ~ musicInfo:", musicInfo);
- setState(musicInfo, index);
- setCustom();
- detailData.isLoading = false;
- };
- const setState = (data: any, index: number) => {
- // console.log("🚀 ~ data:", data)
- state.scrollContainer = "scrollContainer";
- state.detailId = data.id;
- state.xmlUrl = data.xmlFileUrl;
- state.partIndex = index;
- state.subjectId = data.musicSubject;
- state.categoriesId = data.categoriesId;
- state.categoriesName = data.musicTagNames;
- state.enableEvaluation = data.canEvaluate ? true : false;
- state.examSongId = data.id + "";
- state.examSongName = data.musicSheetName;
- // 解析扩展字段
- if (data.extConfigJson) {
- try {
- state.extConfigJson = JSON.parse(data.extConfigJson as string);
- } catch (error) {
- console.error("解析扩展字段错误:", error);
- }
- }
- state.isOpenMetronome = data.mp3Type === "MP3_METRONOME" ? true : false;
- state.needTick = data.isOpenMetronome;
- state.isShowFingering = data.showFingering ? true : false;
- state.music = data.audioFileUrl;
- state.accompany = data.metronomeUrl || data.metronomeUrl;
- state.midiUrl = data.midiUrl;
- state.parentCategoriesId = data.musicTag;
- state.playMode = data.audioType === "MP3" ? "mp3" : "midi";
- state.originSpeed = state.speed = data.speed;
- state.track = data.track;
- state.enableNotation = data.notation ? true : false;
- // 映射声部ID
- state.subjectId = mappingVoicePart(state.subjectId as any, "ORCHESTRA");
- console.log("🚀 ~ state.subjectId:", state.subjectId);
- // 是否打击乐
- state.isPercussion = state.subjectId == 23 || state.subjectId == 113 || state.subjectId == 121 || isRhythmicExercises();
- // 设置指法
- state.fingeringInfo = subjectFingering(state.subjectId);
- // console.log("🚀 ~ state.fingeringInfo:", state.fingeringInfo, state.subjectId, state.track)
- };
- const setCustom = () => {
- if (state.extConfigJson.multitrack) {
- setGlobalData("multitrack", state.extConfigJson.multitrack);
- }
- };
- onMounted(() => {
- (window as any).appName = "colexiu";
- Promise.all([sysMusicScoreAccompanimentQueryPage(query.id)]).then((values) => {
- getMusicInfo(values[0]);
- });
- });
- /** 渲染完成 */
- const handleRendered = (osmd: any) => {
- state.musicRendered = true;
- state.osmd = osmd;
- const saveSpeed = (store.get("speeds") || {})[state.examSongId];
- const bpm = (osmd as any).bpm || osmd.Sheet.userStartTempoInBPM;
- // state.originSpeed =
- // state.speed = saveSpeed || bpm || 100;
- state.times = formateTimes(osmd);
- console.log("🚀 ~ state.times:", state.times);
- try {
- metronomeData.metro = new Metronome();
- metronomeData.metro.init(state.times);
- } catch (error) {}
- // 设置节拍器
- if (state.needTick) {
- const beatLengthInMilliseconds = osmd?.Sheet?.SheetPlaybackSetting?.beatLengthInMilliseconds || (60 / bpm) * 1000;
- handleInitTick(beatLengthInMilliseconds, osmd?.Sheet?.SheetPlaybackSetting?.Rhythm?.Numerator || 4);
- }
- api_cloudLoading();
- };
- /** 指法配置 */
- const fingerConfig = computed<any>(() => {
- if (state.setting.displayFingering && state.fingeringInfo?.name) {
- if (state.fingeringInfo.direction === "transverse") {
- return {
- container: {
- paddingBottom: state.fingeringInfo.height,
- },
- fingerBox: {
- position: "absolute",
- width: "100%",
- height: state.fingeringInfo.height,
- left: 0,
- bottom: 0,
- background: "var(--container-background)",
- },
- };
- } else {
- return {
- container: {
- paddingRight: state.fingeringInfo.width,
- },
- fingerBox: {
- position: "absolute",
- width: state.fingeringInfo.width,
- height: "100%",
- right: 0,
- top: 0, //"calc(var(--header-height) / 2)",
- },
- };
- }
- }
- return {
- container: {},
- fingerBox: {},
- };
- });
- // 监听指法显示
- watch(
- () => state.setting.displayFingering,
- () => {
- if (state.fingeringInfo.direction === "vertical") {
- if (state.setting.displayFingering) {
- document.getElementById("musicAndSelection")?.style.removeProperty("--music-zoom");
- } else {
- nextTick(() => {
- resetMusicScore();
- });
- }
- }
- }
- );
- // 监听播放状态
- watch(
- () => state.playState,
- () => {
- detailData.headerHide = state.playState === "play" ? true : false;
- }
- );
- // 设置改变触发
- watch(
- [() => state.setting],
- () => {
- store.set(musicscoresettingKey, state.setting);
- },
- { deep: true }
- );
- onMounted(() => {
- window.addEventListener("resize", resetMusicScore);
- });
- onBeforeUnmount(() => {
- window.removeEventListener("resize", resetMusicScore);
- });
- return () => (
- <div
- class={[styles.detail, state.setting.eyeProtection && "eyeProtection"]}
- style={{ paddingLeft: detailData.paddingLeft, opacity: state.setting.camera ? `${state.setting.cameraOpacity / 100}` : "" }}
- onClick={(e: Event) => {
- if (state.playState === "play") {
- detailData.headerHide = !detailData.headerHide;
- }
- }}
- >
- {!state.musicRendered && (
- <div class={styles.skeleton}>
- <Skeleton class={styles.skeleton} row={8} />
- </div>
- )}
- <div class={[styles.headHeight, detailData.headerHide && styles.headHide]} onClick={(e: Event) => e.stopPropagation()}>
- <Transition name="van-slide-down">{state.musicRendered && <HeaderTop />}</Transition>
- </div>
- <div id="scrollContainer" style={{ ...fingerConfig.value.container }} class={[styles.container, !state.setting.displayCursor && "hideCursor"]}>
- {/* 曲谱渲染 */}
- {!detailData.isLoading && <MusicScore onRendered={handleRendered} />}
- {/* 播放 */}
- {!detailData.isLoading && <AudioList />}
- {/* 评测 */}
- {state.modeType === "evaluating" && (
- <>
- <Evaluating />
- {evaluatingData.rendered && <EvaluatModel />}
- </>
- )}
- </div>
- {/* 指法 */}
- {state.setting.displayFingering && state.fingeringInfo?.name && (
- <div style={{ ...fingerConfig.value.fingerBox }}>
- <Fingering />
- </div>
- )}
- {/* 公用的插件 */}
- <div class="plugins-box">
- {state.musicRendered && (
- <>
- <MeasureSpeed />
- {/* 统计训练时长 */}
- {storeData.platformType === 'STUDENT' && <RecordingTime />}
- {/* 单元测验 和 课后训练 */}
- {storeData.platformType === 'STUDENT' && <UnitTest />}
- </>
- )}
- </div>
- {/* 节拍器 */}
- {state.needTick && <Tick />}
- {/* 跟练模式 */}
- {state.modeType === "follow" && (
- <>
- <FollowPractice />
- <FollowModel />
- </>
- )}
- </div>
- );
- },
- });
|