index.tsx 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. import { Transition, computed, defineComponent, onMounted, onUnmounted, reactive, ref, watch, toRef, ComputedRef, nextTick } from "vue";
  2. import styles from "./index.module.less";
  3. import iconBack from "./image/icon-back.png";
  4. import listImg from "./image/list.png";
  5. import iconMode from "./image/mode.png";
  6. import { headImg } from "./image";
  7. import { Badge, Circle, Popover, Popup, showConfirmDialog, showToast, NoticeBar } from "vant";
  8. import Speed from "./speed";
  9. import { evaluatingData, handleStartEvaluat } from "/src/view/evaluating";
  10. import Settting from "./settting";
  11. import state, { IPlatform, handleChangeSection, handleResetPlay, handleRessetState, togglePlay, IPlayState, refreshMusicSvg } from "/src/state";
  12. import { getAudioCurrentTime } from "/src/view/audio-list";
  13. import { followData, toggleFollow } from "/src/view/follow-practice";
  14. import { api_back } from "/src/helpers/communication";
  15. import MusicType from "./music-type";
  16. import ModeTypeMode from "../component/mode-type-mode";
  17. import { getQuery } from "/src/utils/queryString";
  18. import { storeData } from "/src/store";
  19. import TeacherTop from "../custom-plugins/guide-page/teacher-top";
  20. import StudentTop from "../custom-plugins/guide-page/student-top";
  21. import { HANDLE_WORK_ADD } from "../custom-plugins/work-index";
  22. import { browser } from "/src/utils";
  23. import store from "store";
  24. import "../component/the-modal-tip/index.module.less";
  25. import { metronomeData } from "../../helpers/metronome";
  26. import { toggleMusicSheet } from "/src/view/plugins/toggleMusicSheet";
  27. import useDrag from "/src/view/plugins/useDrag/index";
  28. import Dragbom from "/src/view/plugins/useDrag/dragbom";
  29. import { getGuidance, setGuidance } from "../custom-plugins/guide-page/api";
  30. import ModeView from "./modeView";
  31. import { smoothAnimationState } from "../view-detail/smoothAnimation";
  32. import { isMusicList, musicListShow } from "../component/the-music-list";
  33. import { EvaluatingDriver, FollowDriver, PractiseDriver } from "../custom-plugins/guide-driver";
  34. /** 头部数据和方法 */
  35. export const headTopData = reactive({
  36. /** 模式 */
  37. modeType: "" as "init" | "show",
  38. /** 显示返回按钮 */
  39. showBack: true,
  40. /** 设置弹窗 */
  41. settingMode: false,
  42. /** 切换模式 */
  43. handleChangeModeType(value: "practise" | "follow" | "evaluating") {
  44. // 后台设置为不能评测
  45. if (value === "evaluating" && !state.enableEvaluation) return;
  46. // 打击乐&节奏练习不支持跟练模式
  47. if (value === "follow" && state.isPercussion) return;
  48. // 跟练模式,光标只有音符模式,无节拍模式
  49. if (value === "follow" && metronomeData.cursorMode === 2) {
  50. metronomeData.cursorMode = 1;
  51. }
  52. if (value === "practise") {
  53. // state.playIngSpeed = state.speed
  54. }
  55. if (value === "evaluating") {
  56. // 如果延迟检测资源还在加载中,给出提示
  57. if (!evaluatingData.jsonLoadDone) {
  58. evaluatingData.jsonLoading = true;
  59. state.audioDone && showToast("资源加载中,请稍后"); //音频资源加载完之后才提示
  60. return;
  61. }
  62. // 如果是pc端, 评测模式暂不可用
  63. if (state.platform === IPlatform.PC) {
  64. showConfirmDialog({
  65. className: "modalTip",
  66. title: "温馨提示",
  67. message: "该功能暂未开放,敬请期待!",
  68. showCancelButton: false,
  69. });
  70. return;
  71. }
  72. // 评测模式,只有一行谱模式
  73. if (!state.isSingleLine) {
  74. state.isSingleLine = true;
  75. refreshMusicSvg();
  76. }
  77. smoothAnimationState.isShow.value = false; // 隐藏旋律线
  78. state.playIngSpeed = state.originSpeed;
  79. handleStartEvaluat();
  80. // 开发模式,把此处打开
  81. // state.modeType = "evaluating";
  82. // evaluatingData.rendered = true;
  83. // evaluatingData.soundEffectMode = true;
  84. } else if (value === "follow") {
  85. // 跟练模式,只有一行谱模式
  86. if (!state.isSingleLine) {
  87. state.isSingleLine = true;
  88. refreshMusicSvg();
  89. }
  90. smoothAnimationState.isShow.value = false;
  91. toggleFollow();
  92. }
  93. headTopData.modeType = "show";
  94. },
  95. // 改变模式之前的状态
  96. oldPlayType: "play",
  97. // 记录切换模式前的状态
  98. oldModeType: "practise" as "practise" | "follow" | "evaluating",
  99. });
  100. export const headData = reactive({
  101. speedShow: false,
  102. musicTypeShow: false,
  103. });
  104. let resetBtn: ComputedRef<{
  105. display: boolean;
  106. disabled: boolean;
  107. }>;
  108. // 点击切换的时候才触发提醒
  109. let isClickMode = false;
  110. /**
  111. * 处理模式切换
  112. * @param oldPlayType 没改变之前的播放模式
  113. * @param oldPlaySource 没改变之前的播放类型
  114. * @param isforceReset 是否强制刷新播放状态 模式times时值改变时候也刷新
  115. */
  116. export function handlerModeChange(oldPlayType: "play" | "sing", oldPlaySource: IPlayState, isforceReset?: boolean) {
  117. const isModeChange = modeChangeHandleTimes(oldPlayType, oldPlaySource);
  118. // 没有切换的时候 不处理下面的
  119. if (isModeChange) {
  120. try {
  121. metronomeData.metro.calculation(state.times);
  122. } catch (error) {}
  123. console.log("重新之后的times", state.times, state.fixtime);
  124. }
  125. if (isModeChange || isforceReset) {
  126. // 重置播放状态
  127. handleRessetState();
  128. // 隐藏重播按钮
  129. resetBtn && (resetBtn.value.display = false);
  130. }
  131. // 当模式改变的时候 放在这里是因为需要等谱面加载完成之后再提示(点击按钮模式切换才提示)
  132. if (isClickMode) {
  133. showToast({
  134. message: state.playType === "play" ? "已切换为演奏场景" : "已切换为演唱场景",
  135. position: "top",
  136. className: "selectionToast",
  137. });
  138. isClickMode = false;
  139. }
  140. }
  141. // 模式切换之后重新给times赋值
  142. function modeChangeHandleTimes(oldPlayType: "play" | "sing", oldPlaySource: IPlayState) {
  143. const playType = state.playType;
  144. const playSource = state.playSource;
  145. const { notBeatFixtime, xmlMp3BeatFixTime, difftime } = state.times[0];
  146. const { isOpenMetronome, isSingOpenMetronome } = state;
  147. // 演奏向演唱切
  148. if (oldPlayType === "play" && playType === "sing") {
  149. if (playSource === "mingSong") {
  150. // 唱名文件也要加上弱起时间 他们制作曲子加了弱起时间
  151. state.fixtime = difftime;
  152. state.times.map((item) => {
  153. item.time = item.xmlNoteTime + difftime;
  154. item.endtime = item.xmlNoteEndTime + difftime;
  155. item.fixtime = difftime;
  156. });
  157. return true;
  158. } else {
  159. //演奏开了节拍器,演唱没开节拍器
  160. if (isOpenMetronome && !isSingOpenMetronome) {
  161. state.fixtime = notBeatFixtime;
  162. state.times.map((item) => {
  163. item.time = item.notBeatTime;
  164. item.endtime = item.notBeatEndTime;
  165. item.fixtime = notBeatFixtime;
  166. });
  167. return true;
  168. } else if (!isOpenMetronome && isSingOpenMetronome) {
  169. state.fixtime = notBeatFixtime + xmlMp3BeatFixTime;
  170. state.times.map((item) => {
  171. item.time = item.notBeatTime + xmlMp3BeatFixTime;
  172. item.endtime = item.notBeatEndTime + xmlMp3BeatFixTime;
  173. item.fixtime = notBeatFixtime + xmlMp3BeatFixTime;
  174. });
  175. return true;
  176. }
  177. }
  178. } else if (oldPlayType === "sing" && playType === "play") {
  179. // 演唱向演奏切
  180. if (oldPlaySource === "mingSong") {
  181. // 有节拍器
  182. if (isOpenMetronome) {
  183. state.fixtime = notBeatFixtime + xmlMp3BeatFixTime;
  184. state.times.map((item) => {
  185. item.time = item.notBeatTime + xmlMp3BeatFixTime;
  186. item.endtime = item.notBeatEndTime + xmlMp3BeatFixTime;
  187. item.fixtime = notBeatFixtime + xmlMp3BeatFixTime;
  188. });
  189. return true;
  190. } else {
  191. state.fixtime = notBeatFixtime;
  192. state.times.map((item) => {
  193. item.time = item.notBeatTime;
  194. item.endtime = item.notBeatEndTime;
  195. item.fixtime = notBeatFixtime;
  196. });
  197. return true;
  198. }
  199. }
  200. // 演奏开了节拍器,演唱没开节拍器
  201. if (isOpenMetronome && !isSingOpenMetronome) {
  202. state.fixtime = notBeatFixtime + xmlMp3BeatFixTime;
  203. state.times.map((item) => {
  204. item.time = item.notBeatTime + xmlMp3BeatFixTime;
  205. item.endtime = item.notBeatEndTime + xmlMp3BeatFixTime;
  206. item.fixtime = notBeatFixtime + xmlMp3BeatFixTime;
  207. });
  208. return true;
  209. } else if (!isOpenMetronome && isSingOpenMetronome) {
  210. state.fixtime = notBeatFixtime;
  211. state.times.map((item) => {
  212. item.time = item.notBeatTime;
  213. item.endtime = item.notBeatEndTime;
  214. item.fixtime = notBeatFixtime;
  215. });
  216. return true;
  217. }
  218. } else if (oldPlayType === "sing" && playType === "sing") {
  219. // 演唱之间切换
  220. // 切到唱名时候
  221. if (playSource === "mingSong") {
  222. // 唱名文件也要加上弱起时间 他们制作曲子加了弱起时间
  223. state.fixtime = difftime;
  224. state.times.map((item) => {
  225. item.time = item.xmlNoteTime + difftime;
  226. item.endtime = item.xmlNoteEndTime + difftime;
  227. item.fixtime = difftime;
  228. });
  229. return true;
  230. } else if (oldPlaySource === "mingSong") {
  231. // 有节拍器
  232. if (isSingOpenMetronome) {
  233. state.fixtime = notBeatFixtime + xmlMp3BeatFixTime;
  234. state.times.map((item) => {
  235. item.time = item.notBeatTime + xmlMp3BeatFixTime;
  236. item.endtime = item.notBeatEndTime + xmlMp3BeatFixTime;
  237. item.fixtime = notBeatFixtime + xmlMp3BeatFixTime;
  238. });
  239. return true;
  240. } else {
  241. state.fixtime = notBeatFixtime;
  242. state.times.map((item) => {
  243. item.time = item.notBeatTime;
  244. item.endtime = item.notBeatEndTime;
  245. item.fixtime = notBeatFixtime;
  246. });
  247. return true;
  248. }
  249. }
  250. }
  251. return false;
  252. }
  253. export default defineComponent({
  254. name: "header-top",
  255. emits: ["close"],
  256. setup(props, { emit }) {
  257. const query = getQuery();
  258. // 是否显示引导
  259. const showGuide = ref(false);
  260. const showStudentGuide = ref(false);
  261. const showWebGuide = ref(true);
  262. let displayFingeringCache = false; // 指法缓存
  263. /** 设置按钮 */
  264. const settingBtn = computed(() => {
  265. // 音频播放中 禁用
  266. if (state.playState === "play") return { display: true, disabled: true };
  267. // 评测开始 禁用, 跟练开始 禁用
  268. if (evaluatingData.startBegin || followData.start) return { display: true, disabled: true };
  269. return {
  270. display: true,
  271. disabled: false,
  272. };
  273. });
  274. /** 转谱按钮 */
  275. const converBtn = computed(() => {
  276. // 音频播放中 禁用
  277. if (state.playState === "play") return { display: true, disabled: true };
  278. // 评测开始 禁用
  279. if (evaluatingData.startBegin || followData.start) return { display: true, disabled: true };
  280. return {
  281. disabled: false,
  282. display: true,
  283. };
  284. });
  285. /** 速度按钮 */
  286. const speedBtn = computed(() => {
  287. // 选择模式, 跟练模式 不显示
  288. if (headTopData.modeType !== "show" || state.modeType === "follow") return { display: false, disabled: true };
  289. // 评测模式, 音频播放中 禁用
  290. if (state.modeType === "evaluating" || state.playState === "play") return { display: true, disabled: true };
  291. return {
  292. disabled: false,
  293. display: true,
  294. };
  295. });
  296. /** 节拍器按钮 */
  297. const metronomeBtn = computed(() => {
  298. // 选择模式 不显示
  299. if (headTopData.modeType !== "show") return { display: false, disabled: true };
  300. // 音频播放中 禁用
  301. if (state.playState === "play") return { display: true, disabled: true };
  302. return {
  303. disabled: false,
  304. display: true,
  305. };
  306. });
  307. /** 指法按钮 */
  308. const fingeringBtn = computed(() => {
  309. // 后台设置不显示指法
  310. if (!state.isShowFingering) return { display: true, disabled: true };
  311. // 没有指法 选择模式 评测模式 跟练模式 不显示
  312. if (headTopData.modeType !== "show" || !state.fingeringInfo.name || ["evaluating", "follow"].includes(state.modeType)) return { display: false, disabled: true };
  313. // 音频播放中 禁用
  314. if (state.playState === "play") return { display: true, disabled: true };
  315. return {
  316. disabled: false,
  317. display: true,
  318. };
  319. });
  320. /** 摄像头按钮 */
  321. const cameraBtn = computed(() => {
  322. // 选择模式 不显示
  323. if (headTopData.modeType !== "show" || state.modeType !== "evaluating") return { display: false, disabled: true };
  324. // 音频播放中 禁用
  325. if (state.playState === "play") return { display: true, disabled: true };
  326. return {
  327. disabled: false,
  328. display: true,
  329. };
  330. });
  331. /** 选段按钮 */
  332. const selectBtn = computed(() => {
  333. // 选择模式 不显示
  334. if (headTopData.modeType !== "show" || ["follow"].includes(state.modeType)) return { display: false, disabled: true };
  335. // 音频播放中 禁用
  336. if (state.playState === "play" || query.workRecord) return { display: true, disabled: true };
  337. return {
  338. disabled: false,
  339. display: true,
  340. };
  341. });
  342. /** 原声按钮 */
  343. const originBtn = computed(() => {
  344. // 没有音源不显示
  345. if(state.noMusicSource) return { display: false, disabled: false };
  346. // 选择模式,跟练模式 不显示
  347. if (headTopData.modeType !== "show" || state.modeType === "follow") return { display: false, disabled: false };
  348. // 评测开始 禁用
  349. if (state.modeType === "evaluating") return { display: false, disabled: true };
  350. if (!state.isAppPlay) {
  351. if (state.playType === "play") {
  352. // 原声, 伴奏 少一个,就不能切换
  353. if (state.music && state.accompany) return { display: true, disabled: false };
  354. } else {
  355. // 播放过程中不能切换
  356. if (state.playState === "play") {
  357. return { display: true, disabled: true };
  358. }
  359. // 范唱
  360. let index = 0;
  361. state.fanSong && index++;
  362. state.banSong && index++;
  363. state.mingSong && index++;
  364. if (index > 1) {
  365. return { display: true, disabled: false };
  366. }
  367. }
  368. }
  369. return {
  370. disabled: true,
  371. display: true,
  372. };
  373. });
  374. /** 播放类型按钮 */
  375. const playTypeBtn = computed(() => {
  376. // 选择模式,跟练模式,评测模式 不显示
  377. if (headTopData.modeType !== "show" || state.modeType === "follow" || state.modeType === "evaluating") return { display: false, disabled: false };
  378. if (!state.isAppPlay) {
  379. let index = 0;
  380. state.music && index++;
  381. state.accompany && index++;
  382. let songIndex = 0;
  383. state.fanSong && songIndex++;
  384. state.banSong && songIndex++;
  385. state.mingSong && songIndex++;
  386. // 演唱和演奏 都有数据的时间不禁用
  387. if (songIndex > 0 && index > 0) {
  388. // 音频播放中 禁用
  389. if (state.playState === "play") {
  390. return { display: true, disabled: true };
  391. }
  392. return { display: true, disabled: false };
  393. }
  394. }
  395. return {
  396. disabled: false,
  397. display: false,
  398. };
  399. });
  400. /** 模式切换按钮 */
  401. const toggleBtn = computed(() => {
  402. // 没有音源不显示
  403. if(state.noMusicSource) return { display: false, disabled: false };
  404. // 不是演奏模式 影藏
  405. if (state.playType !== "play") return { display: false, disabled: false };
  406. // 选择模式, url设置模式 不显示
  407. if (headTopData.modeType !== "show" || !headTopData.showBack) return { display: false, disabled: false };
  408. // 跟练开始, 评测开始 播放开始 隐藏
  409. if (state.playState == "play" || followData.start || evaluatingData.startBegin) return { display: false, disabled: false };
  410. return {
  411. display: true,
  412. disabled: false,
  413. };
  414. });
  415. /** 播放按钮 */
  416. const playBtn = computed(() => {
  417. // 没有音源不显示
  418. if(state.noMusicSource) return { display: false, disabled: false };
  419. // 选择模式 不显示
  420. if (headTopData.modeType !== "show") return { display: false, disabled: false };
  421. // 评测模式 不显示,跟练模式 不显示
  422. if (["evaluating", "follow"].includes(state.modeType)) return { display: false, disabled: true };
  423. // midi音频未初始化完成不可点击
  424. if (state.isAppPlay && state.midiPlayIniting) return { display: true, disabled: true };
  425. return {
  426. display: true,
  427. disabled: false,
  428. };
  429. });
  430. /** 重播按钮 */
  431. resetBtn = computed(() => {
  432. // 没有音源不显示
  433. if(state.noMusicSource) return { display: false, disabled: false };
  434. // 选择模式 不显示
  435. if (headTopData.modeType !== "show") return { display: false, disabled: false };
  436. // 评测模式 不显示,跟练模式 不显示
  437. if (["evaluating", "follow"].includes(state.modeType)) return { display: false, disabled: true };
  438. // 播放状态 不显示
  439. if (state.playState === "play") return { display: false, disabled: true };
  440. // 播放进度为0 不显示
  441. const currentTime = getAudioCurrentTime();
  442. // midi音频未初始化完成不可点击
  443. if (state.isAppPlay && state.midiPlayIniting) return { display: false, disabled: true };
  444. if (!currentTime) return { display: false, disabled: true };
  445. return {
  446. display: true,
  447. disabled: false,
  448. };
  449. });
  450. const isAllBtns = computed(() => {
  451. const flag = converBtn.value.display && speedBtn.value.display && selectBtn.value.display && originBtn.value.display && toggleBtn.value.display && showGuide.value;
  452. return flag;
  453. });
  454. const isAllBtnsStudent = computed(() => {
  455. const flag = converBtn.value.display && speedBtn.value.display && selectBtn.value.display && originBtn.value.display && toggleBtn.value.display && showStudentGuide.value;
  456. return flag;
  457. });
  458. const showGuideIndex = computed(() => {
  459. // 从课堂乐器学生端课件预览默认不显示会员
  460. if (storeData.user.vipMember || state.paymentType === "FREE" || query.showCourseMember === "true") {
  461. // 学生端
  462. return true;
  463. } else {
  464. // vip
  465. return false;
  466. }
  467. });
  468. const browInfo = browser();
  469. /** 返回 */
  470. const handleBack = () => {
  471. HANDLE_WORK_ADD();
  472. // 不在APP中,
  473. if (!storeData.isApp) {
  474. window.close();
  475. return;
  476. }
  477. if ((browInfo.iPhone || browInfo.ios) && query.workRecord) {
  478. setTimeout(() => {
  479. api_back();
  480. }, 550);
  481. return;
  482. }
  483. api_back();
  484. };
  485. /** 根据参数设置模式 */
  486. const getQueryModelSetModelType = () => {
  487. /** 作业模式 start, 如果为作业模式不处理,让作业模块处理 */
  488. if (query.workRecord) {
  489. return;
  490. }
  491. /** 作业模式 end */
  492. if (state.defaultModeType == 1) {
  493. headTopData.handleChangeModeType("practise");
  494. // if (state.platform === IPlatform.PC || state.isPreView) {
  495. // headTopData.showBack = false;
  496. // }
  497. if (state.isPreView) {
  498. headTopData.showBack = false;
  499. }
  500. } else {
  501. if (query.modelType) {
  502. if (query.modelType === "practise") {
  503. headTopData.handleChangeModeType("practise");
  504. } else if (query.modelType === "evaluating") {
  505. headTopData.handleChangeModeType("evaluating");
  506. }
  507. headTopData.showBack = false;
  508. } else {
  509. setTimeout(() => {
  510. headTopData.modeType = "init";
  511. }, 500);
  512. }
  513. }
  514. };
  515. /** 课件播放 */
  516. const changePlay = (res: any) => {
  517. // console.log('监听上课页面message',res)
  518. if (res?.data?.api === "setPlayState") {
  519. togglePlay("paused", "courseware");
  520. }
  521. // 上课页面,按钮方向
  522. if (res?.data?.api === "imagePos") {
  523. if (res?.data.data) {
  524. state.playBtnDirection = res.data.data === "right" ? "right" : "left";
  525. // if (state.fingeringInfo.direction === "vertical" && state.setting.displayFingering) {
  526. // state.musicScoreBtnDirection = state.playBtnDirection === 'right' ? 'left' : 'right';
  527. // } else {
  528. // state.musicScoreBtnDirection = state.playBtnDirection;
  529. // }
  530. state.musicScoreBtnDirection = state.playBtnDirection;
  531. }
  532. }
  533. };
  534. const parentClassName = "settingBoxClass_drag";
  535. const userId = storeData.user?.id ? String(storeData.user?.id) : "";
  536. const positionInfo =
  537. state.platform !== IPlatform.PC
  538. ? {
  539. styleDrag: { value: null },
  540. }
  541. : useDrag([`${parentClassName} .top_drag`, `${parentClassName} .bom_drag`], parentClassName, toRef(headTopData, "settingMode"), userId);
  542. onMounted(() => {
  543. getQueryModelSetModelType();
  544. window.addEventListener("message", changePlay);
  545. if (state.platform === IPlatform.PC) {
  546. showGuide.value = true;
  547. } else {
  548. showStudentGuide.value = true;
  549. }
  550. if (query.showWebGuide === "false") {
  551. showWebGuide.value = false;
  552. }
  553. });
  554. onUnmounted(() => {
  555. window.removeEventListener("message", changePlay);
  556. });
  557. const noticeBarWidth = ref<number>();
  558. watch(
  559. () => smoothAnimationState.isShow.value,
  560. () => {
  561. // NoticeBar能不能滚动
  562. if (smoothAnimationState.isShow.value && isMusicList.value) {
  563. nextTick(() => {
  564. const widthCon = (document.querySelector("#noticeBarRollDom .van-notice-bar__content") as any)?.offsetWidth || undefined;
  565. noticeBarWidth.value = widthCon;
  566. });
  567. }
  568. },
  569. { immediate: true }
  570. );
  571. // 设置改变触发
  572. watch(state.setting, () => {
  573. console.log(state.setting, "state.setting");
  574. store.set("musicscoresetting", state.setting);
  575. });
  576. // 获取引导页信息
  577. const getAllGuidance = async () => {
  578. let guideInfo: any = null;
  579. try {
  580. const res = await getGuidance({ guideTag: "guideInfo" });
  581. if (res.data) {
  582. guideInfo = JSON.parse(res.data?.guideValue) || null;
  583. } else {
  584. guideInfo = {};
  585. }
  586. state.guideInfo = guideInfo;
  587. } catch (e) {
  588. console.log(e);
  589. }
  590. };
  591. getAllGuidance();
  592. // 完成拖动弹窗引导页
  593. const handleGuide = async () => {
  594. state.guideInfo.teacherDrag = true;
  595. try {
  596. const res = await setGuidance({ guideTag: "guideInfo", guideValue: JSON.stringify(state.guideInfo) });
  597. } catch (e) {
  598. console.log(e);
  599. }
  600. };
  601. return () => (
  602. <>
  603. <div
  604. class={[styles.headerTop]}
  605. onClick={(e: Event) => {
  606. e.stopPropagation();
  607. if (state.platform === IPlatform.PC) {
  608. // 显示隐藏菜单
  609. window.parent.postMessage(
  610. {
  611. api: "onAttendToggleMenu",
  612. },
  613. "*"
  614. );
  615. }
  616. }}
  617. >
  618. {/* 返回和标题 */}
  619. {!(state.playState == "play" || followData.start || evaluatingData.startBegin) && (
  620. <div id="noticeBarRollDom" class={styles.headTopLeftBox}>
  621. <img src={iconBack} class={["headTopBackBtn", styles.img, !headTopData.showBack && styles.hidenBack]} onClick={handleBack} />
  622. {smoothAnimationState.isShow.value ? (
  623. <div
  624. style={
  625. noticeBarWidth.value
  626. ? {
  627. "--noticeBarWidth": noticeBarWidth.value + "px",
  628. }
  629. : {}
  630. }
  631. class={[styles.title, "headeTopTitleBtn"]}
  632. onClick={() => {
  633. isMusicList.value && (musicListShow.value = true);
  634. }}
  635. >
  636. {isMusicList.value && <div class={[styles.symbolNote, "driver-8"]}></div>}
  637. <NoticeBar text={state.examSongName} background="none" />
  638. </div>
  639. ) : (
  640. isMusicList.value && (
  641. <img
  642. src={listImg}
  643. class={[styles.img, styles.listImg, "driver-8"]}
  644. onClick={() => {
  645. musicListShow.value = true;
  646. }}
  647. />
  648. )
  649. )}
  650. </div>
  651. )}
  652. {/* 模式切换 */}
  653. {
  654. <div
  655. id={state.platform === IPlatform.PC ? "teacherTop-0" : "studnetT-0"}
  656. style={{ display: toggleBtn.value.display ? "" : "none" }}
  657. class={["driver-9", styles.modeChangeBox, toggleBtn.value.disabled && styles.disabled]}
  658. onClick={() => {
  659. headTopData.oldModeType = state.modeType;
  660. handleRessetState();
  661. headTopData.modeType = "init";
  662. }}
  663. >
  664. <img class={styles.img} src={iconMode} />
  665. <div class={styles.title}>{state.modeType === "practise" ? "练习模式" : state.modeType === "follow" ? "跟练模式" : state.modeType === "evaluating" ? "评测模式" : ""}</div>
  666. </div>
  667. }
  668. {/* 模式提醒 */}
  669. {
  670. state.modeType === "practise" &&
  671. <div class={[styles.modeWarn, "practiseModeWarn"]}>
  672. <img src={state.playType === "play" ? headImg("perform1.png") : headImg("sing1.png")} />
  673. <div>{state.playType === "play" ? "演奏场景" : "演唱场景"}</div>
  674. </div>
  675. }
  676. {/* 功能按钮 */}
  677. <div
  678. class={[styles.headRight]}
  679. onClick={(e: Event) => {
  680. e.stopPropagation();
  681. }}
  682. >
  683. {/* 一行谱模式,暂不支持节拍指针 */}
  684. {/* {!state.isSingleLine ? (
  685. <div
  686. class={[styles.btn, state.platform === IPlatform.PC ? styles.pcBtn : ""]}
  687. onClick={() => {
  688. // 切换光标模式
  689. let mode = metronomeData.cursorMode;
  690. if (["follow"].includes(state.modeType)) {
  691. mode = metronomeData.cursorMode === 1 ? 3 : 1;
  692. } else {
  693. mode = metronomeData.cursorMode === 3 ? 1 : metronomeData.cursorMode + 1;
  694. }
  695. metronomeData.cursorMode = mode;
  696. }}
  697. >
  698. <img class={styles.iconBtn} src={headImg(metronomeData.cursorMode === 1 ? "cursor-icon-1.svg" : metronomeData.cursorMode === 2 ? "cursor-icon-2.svg" : metronomeData.cursorMode === 3 ? "cursor-icon-3.svg" : "")} />
  699. <span class={styles.iconContent}>
  700. {metronomeData.cursorMode === 1 ? "音符指针" : metronomeData.cursorMode === 2 ? "节拍指针" : metronomeData.cursorMode === 3 ? "关闭指针" : ""}
  701. {metronomeData.cursorTips && (
  702. <>
  703. <i class={styles.arrowIcon}></i>
  704. <div class={[styles["botton-tips"], metronomeData.cursorMode === 3 ? styles.tipSpec : ""]}>{metronomeData.cursorTips}</div>
  705. </>
  706. )}
  707. </span>
  708. </div>
  709. ) : null} */}
  710. <div
  711. style={{ display: playTypeBtn.value.display ? "" : "none" }}
  712. class={["driver-2", styles.btn, playTypeBtn.value.disabled && styles.disabled, styles.playType]}
  713. onClick={() => {
  714. const oldPlayType = state.playType;
  715. headTopData.oldPlayType = oldPlayType;
  716. const oldPlaySource = state.playSource;
  717. if (state.playType === "play") {
  718. state.playType = "sing";
  719. state.playSource = state.fanSong ? "music" : state.banSong ? "background" : "mingSong";
  720. } else {
  721. state.playType = "play";
  722. state.playSource = state.music ? "music" : "background";
  723. }
  724. isClickMode = true;
  725. // 有指法并且显示指法的时候 切换到演唱模式 需要影藏指法
  726. let isRefresh = false;
  727. if (state.isShowFingering && state.fingeringInfo.name && (state.setting.displayFingering || displayFingeringCache)) {
  728. if (state.playType === "sing") {
  729. state.setting.displayFingering = false;
  730. displayFingeringCache = true;
  731. } else {
  732. state.setting.displayFingering = displayFingeringCache;
  733. displayFingeringCache = false;
  734. }
  735. // 如果是竖屏指法和一行谱的时候 改变指法值的时候state 会调用刷新 refreshMusicSvg 所以下面不调用
  736. if (state.fingeringInfo.direction === "vertical" && !state.isSingleLine) {
  737. isRefresh = true;
  738. }
  739. }
  740. // 有歌词的时候,切换播放模式,需要重新渲染谱面 指法不刷新谱面的时候
  741. if (state.xmlHasLyric && !isRefresh) {
  742. refreshMusicSvg();
  743. } else if (!isRefresh) {
  744. handlerModeChange(oldPlayType, oldPlaySource, true);
  745. }
  746. }}
  747. >
  748. <img style={{ display: state.playType === "play" ? "" : "none" }} class={styles.iconBtn} src={headImg(`perform.png`)} />
  749. <img style={{ display: state.playType === "play" ? "none" : "" }} class={styles.iconBtn} src={headImg(`sing.png`)} />
  750. <span>{state.playType === "play" ? "演奏" : "演唱"}</span>
  751. </div>
  752. <div
  753. id={state.platform === IPlatform.PC ? "teacherTop-1" : "studnetT-1"}
  754. style={{ display: originBtn.value.display ? "" : "none" }}
  755. class={["driver-3", styles.btn, originBtn.value.disabled && styles.disabled, state.playType === "play" ? styles.playSource : styles.songSource]}
  756. onClick={() => {
  757. const oldPlayType = state.playType;
  758. const oldPlaySource = state.playSource;
  759. if (state.playType === "play") {
  760. state.playSource = state.playSource === "music" ? "background" : "music";
  761. } else {
  762. if (state.playSource === "music") {
  763. state.playSource = state.banSong ? "background" : "mingSong";
  764. } else if (state.playSource === "background") {
  765. state.playSource = state.mingSong ? "mingSong" : "music";
  766. } else {
  767. state.playSource = state.fanSong ? "music" : "background";
  768. }
  769. }
  770. handlerModeChange(oldPlayType, oldPlaySource);
  771. showToast({
  772. message: state.playType === "play" ? (state.playSource === "music" ? "已切换为原声" : "已切换为伴奏") : state.playSource === "music" ? "已切换为范唱" : state.playSource === "background" ? "已切换为伴唱" : "已切换为唱名",
  773. position: "top",
  774. className: "selectionToast",
  775. });
  776. }}
  777. >
  778. <img style={{ display: state.playSource === "music" ? "" : "none" }} class={styles.iconBtn} src={state.playType === "play" ? headImg(`music.png`) : headImg(`music1.png`)} />
  779. <img style={{ display: state.playSource === "background" ? "" : "none" }} class={styles.iconBtn} src={state.playType === "play" ? headImg(`background.png`) : headImg(`background1.png`)} />
  780. <img style={{ display: state.playSource === "mingSong" ? "" : "none" }} class={styles.iconBtn} src={headImg(`mingsong.png`)} />
  781. <span>{state.playSource === "music" ? (state.playType === "play" ? "原声" : "范唱") : state.playSource === "background" ? (state.playType === "play" ? "伴奏" : "伴唱") : "唱名"}</span>
  782. </div>
  783. <div
  784. id={state.platform === IPlatform.PC ? "teacherTop-2" : "studnetT-2"}
  785. style={{ display: selectBtn.value.display ? "" : "none" }}
  786. class={["driver-4", styles.btn, selectBtn.value.disabled && styles.disabled, styles.section, state.sectionStatus && styles.isSection]}
  787. onClick={() => handleChangeSection()}
  788. >
  789. <img style={{ display: state.section.length === 0 ? "" : "none" }} class={styles.iconBtn} src={headImg(`section0.png`)} />
  790. <img style={{ display: state.section.length === 1 ? "" : "none" }} class={styles.iconBtn} src={headImg(`section1.png`)} />
  791. <img style={{ display: state.section.length === 2 ? "" : "none" }} class={styles.iconBtn} src={headImg(`section2.png`)} />
  792. <span>选段</span>
  793. </div>
  794. {
  795. <>
  796. <div
  797. style={{ display: metronomeBtn.value.display ? "" : "none" }}
  798. class={["driver-5", styles.btn, styles.metronomeBtn, metronomeBtn.value.disabled && styles.disabled, headData.speedShow && styles.isSpeed, styles.speed]}
  799. onClick={async () => {
  800. headData.speedShow = !headData.speedShow;
  801. }}
  802. >
  803. <img style={{ display: metronomeData.disable ? "block" : "none" }} class={styles.iconBtn} src={headImg("tickon.png")} />
  804. <img style={{ display: !metronomeData.disable ? "block" : "none" }} class={styles.iconBtn} src={headImg("tickoff.png")} />
  805. <span style={{ whiteSpace: "nowrap" }}>节拍</span>
  806. <div class={styles.speedCon}>
  807. <img src={headImg("speed.png")} />
  808. <div>{Math.floor(state.speed)}</div>
  809. </div>
  810. </div>
  811. {
  812. <Popup v-model:show={headData.speedShow} class="popup-custom van-scale center-closeBtn settingBoxClass_drag" transition="van-scale" teleport="body" style={positionInfo.styleDrag.value} overlay-style={{ background: "rgba(0, 0, 0, 0.3)" }}>
  813. <Speed />
  814. {state.platform === IPlatform.PC && <Dragbom showGuide={!state.guideInfo?.teacherDrag} onGuideDone={handleGuide} />}
  815. </Popup>
  816. }
  817. </>
  818. }
  819. {/* {state.enableNotation ? (
  820. <Popover trigger="manual" v-model:show={headData.musicTypeShow} class={state.platform === IPlatform.PC && styles.pcTransPop} placement={state.platform === IPlatform.PC ? "top-end" : "bottom-end"} overlay={false} offset={state.platform === IPlatform.PC ? [0, 40] : [0, 8]}>
  821. {{
  822. reference: () => (
  823. <div
  824. id={state.platform === IPlatform.PC ? "teacherTop-5" : "studnetT-5"}
  825. style={{ display: converBtn.value.display ? "" : "none" }}
  826. class={[styles.btn, converBtn.value.disabled && styles.disabled]}
  827. onClick={(e: Event) => {
  828. e.stopPropagation();
  829. headData.musicTypeShow = !headData.musicTypeShow;
  830. }}
  831. >
  832. <img class={styles.iconBtn} src={headImg("icon_zhuanpu.svg")} />
  833. <span>{state.musicRenderType === "staff" ? "转简谱" : "转五线谱"}</span>
  834. </div>
  835. ),
  836. default: () => <MusicType />,
  837. }}
  838. </Popover>
  839. ) : null} */}
  840. {state.musicRendered && !query.lessonTrainingId && !query.questionId && state.isConcert && (
  841. <div
  842. class={[styles.btn, state.playState === "play" && fingeringBtn.value.disabled && styles.disabled, toggleMusicSheet.show && styles.isMusicSheet, styles.musicSheet, "driver-10"]}
  843. onClick={() => {
  844. toggleMusicSheet.toggle(true);
  845. }}
  846. >
  847. <img class={styles.iconBtn} src={headImg(`shenggui.png`)} />
  848. <span>声部</span>
  849. </div>
  850. )}
  851. <div
  852. id={state.platform === IPlatform.PC ? "teacherTop-6" : "studnetT-6"}
  853. style={{ display: settingBtn.value.display ? "" : "none" }}
  854. class={["driver-6", styles.btn, settingBtn.value.disabled && styles.disabled, headTopData.settingMode && styles.isSettingMode, styles.settingMode]}
  855. onClick={() => (headTopData.settingMode = true)}
  856. >
  857. <img class={styles.iconBtn} src={headImg("icon_menu.png")} />
  858. <span>设置</span>
  859. </div>
  860. </div>
  861. </div>
  862. {/* 播放按钮 */}
  863. <div
  864. id="studnetT-7"
  865. style={{ display: playBtn.value.display ? "" : "none" }}
  866. class={[
  867. // 引导使用的类
  868. "driver-1",
  869. styles.playBtn,
  870. playBtn.value.disabled && styles.disabled,
  871. // state.platform === IPlatform.PC && state.musicScoreBtnDirection === "left" ? styles.playLeftButton : state.platform === IPlatform.PC && state.musicScoreBtnDirection === "right" ? styles.playRightButton : "",
  872. ]}
  873. onClick={() => togglePlay(state.playState === "play" ? "paused" : "play")}
  874. >
  875. <div class={styles.btnWrap}>
  876. <img style={{ display: state.playState === "play" ? "none" : "" }} class={styles.iconBtn} src={headImg("icon_play.png")} />
  877. <img style={{ display: state.playState === "play" ? "" : "none" }} class={styles.iconBtn} src={headImg("icon_pause.png")} />
  878. <Circle style={{ opacity: state.playState === "play" ? 1 : 0 }} class={styles.progress} stroke-width={60} stroke-linecap={"square"} currentRate={state.playProgress} rate={100} color="#FFED78" layer-color="rgba(0,0,0,0)" />
  879. </div>
  880. </div>
  881. {/* 重播按钮 */}
  882. <div
  883. id="tips-step-9"
  884. style={{ display: resetBtn.value.display ? "" : "none" }}
  885. class={[styles.resetBtn, resetBtn.value.disabled && styles.disabled]}
  886. onClick={() => handleResetPlay()}
  887. >
  888. <img class={styles.iconBtn} src={headImg("icon_reset.png")} />
  889. </div>
  890. <Popup v-model:show={headTopData.settingMode} class="popup-custom van-scale center-closeBtn settingBoxClass_drag" transition="van-scale" teleport="body" style={positionInfo.styleDrag.value} overlay-style={{ background: "rgba(0, 0, 0, 0.3)" }}>
  891. <Settting />
  892. {state.platform === IPlatform.PC && <Dragbom showGuide={!state.guideInfo?.teacherDrag} onGuideDone={handleGuide} />}
  893. </Popup>
  894. {/* 模式切换 */}
  895. {/* <ModeTypeMode /> */}
  896. <ModeView></ModeView>
  897. {/* isAllBtns */}
  898. {/* {isAllBtns.value && !query.isCbs && showGuideIndex.value && <TeacherTop></TeacherTop>}
  899. {isAllBtnsStudent.value && !query.isCbs && showGuideIndex.value && <StudentTop></StudentTop>} */}
  900. {/* 练习模式功能引导 加载音频完成 不是会员 */}
  901. {state.modeType === "practise" && headTopData.modeType !== "init" && !query.isCbs && state.audioDone && !state.isLoading && !state.isVip && showWebGuide.value && (
  902. <PractiseDriver
  903. statusAll={{
  904. subjectStatus: state.musicRendered && !query.lessonTrainingId && !query.questionId && state.isConcert,
  905. modelTypeStatus: toggleBtn.value.display,
  906. playType: playTypeBtn.value.display,
  907. originPlayType: state.playType === "play" ? true : false,
  908. backTitle: !(state.playState == "play" || followData.start || evaluatingData.startBegin),
  909. titleType: smoothAnimationState.isShow.value ? "TEXT" : isMusicList.value ? "IMG" : "NONE",
  910. }}
  911. />
  912. )}
  913. {/* 跟练模式功能引导 加载音频完成 不是会员 */}
  914. {state.modeType === "follow" && headTopData.modeType !== "init" && !query.isCbs && state.audioDone && !state.isLoading && !state.isVip && showWebGuide.value && (
  915. <FollowDriver
  916. statusAll={{
  917. subjectStatus: state.musicRendered && !query.lessonTrainingId && !query.questionId && state.isConcert,
  918. }}
  919. />
  920. )}
  921. {/* 评测模式功能引导 加载音频完成 不是会员 */}
  922. {state.modeType === "evaluating" && headTopData.modeType !== "init" && !evaluatingData.earphoneMode && !query.isCbs && state.audioDone && !state.isLoading && !state.isVip && evaluatingData.websocketState && !evaluatingData.startBegin && evaluatingData.checkEnd && showWebGuide.value && (
  923. <EvaluatingDriver
  924. statusAll={{
  925. subjectStatus: state.musicRendered && !query.lessonTrainingId && !query.questionId && state.isConcert,
  926. }}
  927. />
  928. )}
  929. </>
  930. );
  931. },
  932. });