index.tsx 44 KB

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