index.tsx 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025
  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. // 课件播放,上课页面潜入云教练,不显示模式切换
  423. if (query.hideMode == 1) return { display: false, disabled: false };
  424. return {
  425. display: true,
  426. disabled: false,
  427. };
  428. });
  429. /** 播放按钮 */
  430. const playBtn = computed(() => {
  431. // 没有音源不显示
  432. if (state.noMusicSource) return { display: false, disabled: false };
  433. // 选择模式 不显示
  434. if (headTopData.modeType !== "show") return { display: false, disabled: false };
  435. // 评测模式 不显示,跟练模式 不显示
  436. if (["evaluating", "follow"].includes(state.modeType)) return { display: false, disabled: true };
  437. // midi音频未初始化完成不可点击
  438. if (state.isAppPlay && state.midiPlayIniting) return { display: true, disabled: true };
  439. return {
  440. display: true,
  441. disabled: false,
  442. };
  443. });
  444. /** 重播按钮 */
  445. resetBtn = computed(() => {
  446. // 没有音源不显示
  447. if (state.noMusicSource) return { display: false, disabled: false };
  448. // 选择模式 不显示
  449. if (headTopData.modeType !== "show") return { display: false, disabled: false };
  450. // 评测模式 不显示,跟练模式 不显示
  451. if (["evaluating", "follow"].includes(state.modeType)) return { display: false, disabled: true };
  452. // 播放状态 不显示
  453. if (state.playState === "play") return { display: false, disabled: true };
  454. // 播放进度为0 不显示
  455. const currentTime = getAudioCurrentTime();
  456. // midi音频未初始化完成不可点击
  457. if (state.isAppPlay && state.midiPlayIniting) return { display: false, disabled: true };
  458. if (!currentTime) return { display: false, disabled: true };
  459. return {
  460. display: true,
  461. disabled: false,
  462. };
  463. });
  464. /** 重置按钮 */
  465. const restoreBtn = computed(() => {
  466. // 播放中 禁用
  467. if (state.playState === "play" || evaluatingData.startBegin || followData.start || state.isHomeWork) return { display: true, disabled: true };
  468. return {
  469. disabled: false,
  470. display: true,
  471. };
  472. });
  473. const browInfo = browser();
  474. /** 返回 */
  475. const handleBack = () => {
  476. // 如果是乐教通,点击返回按钮,需要关闭当前窗口
  477. if (query["isYjt"] == "1") {
  478. window.parent.postMessage(
  479. {
  480. api: "api_YjtClose"
  481. },
  482. "*"
  483. );
  484. return
  485. }
  486. // 练习作业,完整练习才记录练习次数
  487. // HANDLE_WORK_ADD();
  488. // 不在APP中,
  489. if (!storeData.isApp) {
  490. window.parent.postMessage(
  491. {
  492. api: "back",
  493. },
  494. "*"
  495. );
  496. window.close();
  497. return;
  498. }
  499. if ((browInfo.iPhone || browInfo.ios) && state.isHomeWork) {
  500. setTimeout(() => {
  501. api_back();
  502. }, 550);
  503. return;
  504. }
  505. api_back();
  506. };
  507. /** 根据参数设置模式 */
  508. const getQueryModelSetModelType = () => {
  509. /** 作业模式 start, 如果为作业模式不处理,让作业模块处理 */
  510. if (state.isHomeWork) {
  511. return;
  512. }
  513. /** 作业模式 end */
  514. if (state.defaultModeType == 1) {
  515. headTopData.handleChangeModeType("practise");
  516. // if (state.platform === IPlatform.PC || state.isPreView) {
  517. // headTopData.showBack = false;
  518. // }
  519. if (state.isPreView) {
  520. headTopData.showBack = false;
  521. }
  522. } else {
  523. if (query.modelType) {
  524. if (query.modelType === "practise") {
  525. headTopData.handleChangeModeType("practise");
  526. } else if (query.modelType === "evaluating") {
  527. headTopData.handleChangeModeType("evaluating");
  528. }
  529. headTopData.showBack = false;
  530. } else {
  531. setTimeout(() => {
  532. headTopData.modeType = "init";
  533. }, 500);
  534. }
  535. }
  536. };
  537. /** 课件播放 */
  538. const changePlay = (res: any) => {
  539. // console.log('监听上课页面message',res)
  540. if (res?.data?.api === "setPlayState") {
  541. togglePlay("paused", true);
  542. }
  543. if(res?.data?.api === 'togglePlayState') {
  544. // if(state.playState === "play") {
  545. // togglePlay("paused");
  546. // }
  547. // if(state.playState === 'paused') {
  548. // togglePlay("play");
  549. // }
  550. console.log('togglePlayState', state.playState)
  551. togglePlay(state.playState === "play" ? "paused" : "play");
  552. }
  553. // 上课页面,按钮方向
  554. if (res?.data?.api === "imagePos") {
  555. if (res?.data.data) {
  556. state.playBtnDirection = res.data.data === "right" ? "right" : "left";
  557. // if (state.fingeringInfo.direction === "vertical" && state.setting.displayFingering) {
  558. // state.musicScoreBtnDirection = state.playBtnDirection === 'right' ? 'left' : 'right';
  559. // } else {
  560. // state.musicScoreBtnDirection = state.playBtnDirection;
  561. // }
  562. state.musicScoreBtnDirection = state.playBtnDirection;
  563. }
  564. }
  565. };
  566. const parentClassName = "settingBoxClass_drag";
  567. const userId = storeData.user?.id ? String(storeData.user?.id) : "";
  568. const positionInfo =
  569. state.platform !== IPlatform.PC
  570. ? {
  571. styleDrag: { value: null },
  572. }
  573. : useDrag([`${parentClassName} .top_draging`, `${parentClassName} .bom_drag`], parentClassName, toRef(headTopData, "settingMode"), userId);
  574. const speedClassName = "speedBoxClass_drag";
  575. const speedInfo =
  576. state.platform !== IPlatform.PC
  577. ? {
  578. styleDrag: { value: null },
  579. }
  580. : useDrag([`${speedClassName} .top_draging`, `${speedClassName} .bom_drag`], speedClassName, toRef(headData, "speedShow"), userId);
  581. onMounted(() => {
  582. getQueryModelSetModelType();
  583. window.addEventListener("message", changePlay);
  584. if (state.platform === IPlatform.PC) {
  585. showGuide.value = true;
  586. } else {
  587. showStudentGuide.value = true;
  588. }
  589. if (query.showWebGuide === "false") {
  590. showWebGuide.value = false;
  591. }
  592. document.addEventListener("keydown", (e: KeyboardEvent) => {
  593. if (e.code === "Tab") {
  594. e.stopPropagation();
  595. e.preventDefault();
  596. // onStartPlayState();
  597. togglePlay(state.playState === "play" ? "paused" : "play");
  598. }
  599. });
  600. });
  601. onUnmounted(() => {
  602. window.removeEventListener("message", changePlay);
  603. });
  604. const noticeBarWidth = ref<number>();
  605. watch(
  606. () => smoothAnimationState.isShow.value,
  607. () => {
  608. // NoticeBar能不能滚动
  609. if ((smoothAnimationState.isShow.value || state.isCombineRender) && isMusicList.value) {
  610. nextTick(() => {
  611. const widthCon = (document.querySelector("#noticeBarRollDom .van-notice-bar__content") as any)?.offsetWidth || undefined;
  612. noticeBarWidth.value = widthCon;
  613. });
  614. }
  615. },
  616. { immediate: true }
  617. );
  618. // 设置改变触发
  619. watch(state.setting, () => {
  620. console.log(state.setting, "state.setting");
  621. store.set("musicscoresetting", state.setting);
  622. });
  623. const isPad = navigator?.userAgent?.includes("UAWEIVRD-W09") || browInfo?.iPad || browInfo.isTablet;
  624. return () => (
  625. <>
  626. <div
  627. class={[styles.headerTop, state.platform === IPlatform.PC && state.musicScoreBtnDirection === "left" ? styles.headerTopRight : ""]}
  628. onClick={(e: Event) => {
  629. e.stopPropagation();
  630. if (state.platform === IPlatform.PC) {
  631. // 显示隐藏菜单
  632. window.parent.postMessage(
  633. {
  634. api: "onAttendToggleMenu",
  635. },
  636. "*"
  637. );
  638. }
  639. }}
  640. >
  641. {/* 返回和标题 */}
  642. {
  643. <div id="noticeBarRollDom" class={[styles.headTopLeftBox, (state.playState == "play" || followData.practiceStart || evaluatingData.startBegin) && styles.headTopLeftHide]}>
  644. {
  645. !query.isMove && !query.isHideBack && <img src={iconBack} class={["headTopBackBtn", styles.img, !headTopData.showBack && styles.hidenBack]} onClick={handleBack} />
  646. }
  647. {smoothAnimationState.isShow.value || state.isCombineRender ? (
  648. <div
  649. style={
  650. noticeBarWidth.value
  651. ? {
  652. "--noticeBarWidth": noticeBarWidth.value + "px",
  653. }
  654. : {}
  655. }
  656. class={[styles.title, state.isCbsView && styles.blackTitle, "headeTopTitleBtn", isPad && styles.isIpad]}
  657. onClick={() => {
  658. isMusicList.value && (musicListShow.value = true);
  659. }}
  660. >
  661. {isMusicList.value && <div class={[styles.symbolNote, "driver-8"]}></div>}
  662. <NoticeBar text={state.examSongName} background="none" />
  663. </div>
  664. ) : (
  665. isMusicList.value && (
  666. <img
  667. src={listImg}
  668. class={[styles.img, styles.listImg, "driver-8"]}
  669. onClick={() => {
  670. musicListShow.value = true;
  671. }}
  672. />
  673. )
  674. )}
  675. </div>
  676. }
  677. {/* 模式提醒 */}
  678. {/* {state.modeType === "practise" && (
  679. <div class={[styles.modeWarn, "practiseModeWarn", state.platform === IPlatform.PC && state.musicScoreBtnDirection === "left" ? styles.modeWarnRight : ""]}>
  680. <img src={state.playType === "play" ? headImg("perform1.png") : headImg("sing1.png")} />
  681. <div>{state.playType === "play" ? "演奏场景" : "演唱场景"}</div>
  682. </div>
  683. )} */}
  684. {/* 功能按钮 */}
  685. <div
  686. class={[styles.headRight]}
  687. onClick={(e: Event) => {
  688. e.stopPropagation();
  689. }}
  690. >
  691. {/* 模式切换 */}
  692. {
  693. <div
  694. id={state.platform === IPlatform.PC ? "teacherTop-0" : "studnetT-0"}
  695. style={{ display: toggleBtn.value.display ? "" : "none"}}
  696. class={["driver-9", styles.modeChangeBox, toggleBtn.value.disabled && styles.disabled, styles.modeType]}
  697. onClick={() => {
  698. headTopData.oldModeType = state.modeType;
  699. handleRessetState();
  700. headTopData.modeType = "init";
  701. }}
  702. >
  703. <img class={styles.img} src={iconMode} />
  704. <div class={styles.title}>{state.modeType === "practise" ? "练习模式" : state.modeType === "follow" ? "跟练模式" : state.modeType === "evaluating" ? "评测模式" : ""}</div>
  705. </div>
  706. }
  707. {/* 一行谱模式,暂不支持节拍指针 */}
  708. {/* {(
  709. <div
  710. class={[styles.btn, state.platform === IPlatform.PC ? styles.pcBtn : ""]}
  711. onClick={() => {
  712. // 切换光标模式
  713. let mode = metronomeData.cursorMode;
  714. if (["follow"].includes(state.modeType)) {
  715. mode = metronomeData.cursorMode === 1 ? 3 : 1;
  716. } else {
  717. mode = metronomeData.cursorMode === 1 ? 3 : metronomeData.cursorMode === 2 ? 1 : 2;
  718. }
  719. metronomeData.cursorMode = mode;
  720. }}
  721. >
  722. <img class={styles.iconBtn} src={headImg(metronomeData.cursorMode === 1 ? "cursor_icon1.png" : metronomeData.cursorMode === 2 ? "cursor_icon2.png" : metronomeData.cursorMode === 3 ? "cursor_icon3.png" : "")} />
  723. <span class={styles.iconContent}>
  724. {metronomeData.cursorMode === 1 ? "音符指针" : metronomeData.cursorMode === 2 ? "节拍指针" : metronomeData.cursorMode === 3 ? "关闭指针" : ""}
  725. {metronomeData.cursorTips && (
  726. <div class={[styles["botton-tips"], metronomeData.cursorMode === 3 ? styles.tipSpec : ""]}>{metronomeData.cursorTips}</div>
  727. )}
  728. </span>
  729. </div>
  730. )} */}
  731. <div
  732. style={{ display: playTypeBtn.value.display ? "" : "none" }}
  733. class={["driver-2", styles.btn, playTypeBtn.value.disabled && styles.disabled, styles.playType]}
  734. onClick={() => {
  735. const oldPlayType = state.playType;
  736. headTopData.oldPlayType = oldPlayType;
  737. const oldPlaySource = state.playSource;
  738. if (state.playType === "play") {
  739. state.playType = "sing";
  740. state.playSource = state.fanSong ? "music" : state.banSong ? "background" : "mingSong";
  741. } else {
  742. state.playType = "play";
  743. state.playSource = state.music ? "music" : "background";
  744. }
  745. isClickMode = true;
  746. // 有指法并且显示指法的时候 切换到演唱模式 需要影藏指法
  747. let isRefresh = false;
  748. if (state.isShowFingering && state.fingeringInfo.name && (state.setting.displayFingering || displayFingeringCache)) {
  749. if (state.playType === "sing") {
  750. state.setting.displayFingering = false;
  751. displayFingeringCache = true;
  752. } else {
  753. state.setting.displayFingering = displayFingeringCache;
  754. displayFingeringCache = false;
  755. }
  756. // 如果是竖屏指法和一行谱的时候 改变指法值的时候state 会调用刷新 refreshMusicSvg 所以下面不调用
  757. if (state.fingeringInfo.direction === "vertical" && !state.isSingleLine) {
  758. isRefresh = true;
  759. }
  760. }
  761. // 有歌词的时候,切换播放模式,需要重新渲染谱面 指法不刷新谱面的时候
  762. if (state.xmlHasLyric && !isRefresh) {
  763. refreshMusicSvg();
  764. } else if (!isRefresh) {
  765. handlerModeChange(oldPlayType, oldPlaySource, true);
  766. }
  767. }}
  768. >
  769. <img style={{ display: state.playType === "play" ? "" : "none" }} class={styles.iconBtn} src={headImg(`perform.png`)} />
  770. <img style={{ display: state.playType === "play" ? "none" : "" }} class={styles.iconBtn} src={headImg(`sing.png`)} />
  771. <span>{state.playType === "play" ? "演奏" : "演唱"}</span>
  772. </div>
  773. <div
  774. id={state.platform === IPlatform.PC ? "teacherTop-1" : "studnetT-1"}
  775. style={{ display: originBtn.value.display ? "" : "none" }}
  776. class={["driver-3", styles.btn, originBtn.value.disabled && styles.disabled, state.playType === "play" ? styles.playSource : styles.songSource]}
  777. onClick={() => {
  778. const oldPlayType = state.playType;
  779. const oldPlaySource = state.playSource;
  780. if (state.playType === "play") {
  781. state.playSource = state.playSource === "music" ? "background" : "music";
  782. } else {
  783. if (state.playSource === "music") {
  784. state.playSource = state.banSong ? "background" : "mingSong";
  785. } else if (state.playSource === "background") {
  786. state.playSource = state.mingSong ? "mingSong" : "music";
  787. } else {
  788. state.playSource = state.fanSong ? "music" : "background";
  789. }
  790. }
  791. handlerModeChange(oldPlayType, oldPlaySource);
  792. showToast({
  793. message: state.playType === "play" ? (state.playSource === "music" ? "已切换为原声" : "已切换为伴奏") : state.playSource === "music" ? "已切换为范唱" : state.playSource === "background" ? "已切换为伴唱" : "已切换为唱名",
  794. position: "top",
  795. className: "selectionToast",
  796. });
  797. }}
  798. >
  799. <img style={{ display: state.playSource === "music" ? "" : "none" }} class={styles.iconBtn} src={state.playType === "play" ? headImg(`music.png`) : headImg(`music1.png`)} />
  800. <img style={{ display: state.playSource === "background" ? "" : "none" }} class={styles.iconBtn} src={state.playType === "play" ? headImg(`background.png`) : headImg(`background1.png`)} />
  801. <img style={{ display: state.playSource === "mingSong" ? "" : "none" }} class={styles.iconBtn} src={headImg(`mingsong.png`)} />
  802. <span>{state.playSource === "music" ? (state.playType === "play" ? "原声" : "范唱") : state.playSource === "background" ? (state.playType === "play" ? "伴奏" : "伴唱") : "唱名"}</span>
  803. </div>
  804. <div
  805. id={state.platform === IPlatform.PC ? "teacherTop-2" : "studnetT-2"}
  806. style={{ display: selectBtn.value.display ? "" : "none" }}
  807. class={["driver-4", styles.btn, selectBtn.value.disabled && styles.disabled, styles.section, state.sectionStatus && styles.isSection]}
  808. onClick={() => handleChangeSection()}
  809. >
  810. <img style={{ display: state.section.length === 0 ? "" : "none" }} class={styles.iconBtn} src={headImg(`section0.png`)} />
  811. <img style={{ display: state.section.length === 1 ? "" : "none" }} class={styles.iconBtn} src={headImg(`section1.png`)} />
  812. <img style={{ display: state.section.length === 2 ? "" : "none" }} class={styles.iconBtn} src={headImg(`section2.png`)} />
  813. <span>选段</span>
  814. </div>
  815. {
  816. <>
  817. <div
  818. style={{ display: metronomeBtn.value.display ? "" : "none" }}
  819. class={["driver-5", styles.btn, styles.metronomeBtn, metronomeBtn.value.disabled && styles.disabled, headData.speedShow && styles.isSpeed, styles.speed]}
  820. onClick={async () => {
  821. headData.speedShow = !headData.speedShow;
  822. }}
  823. >
  824. <img style={{ display: metronomeData.disable ? "block" : "none" }} class={styles.iconBtn} src={headImg("tickon.png")} />
  825. <img style={{ display: !metronomeData.disable ? "block" : "none" }} class={styles.iconBtn} src={headImg("tickoff.png")} />
  826. <span style={{ whiteSpace: "nowrap" }}>节拍</span>
  827. <div class={styles.speedCon}>
  828. <img src={headImg(`${state.speedIcon}.png`)} />
  829. <div>{Math.floor(state.speed)}</div>
  830. </div>
  831. </div>
  832. {
  833. <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)" }}>
  834. <Speed />
  835. {state.platform === IPlatform.PC && <Dragbom showGuide={!state.guideInfo?.teacherDrag} onGuideDone={handleGuide} />}
  836. </Popup>
  837. }
  838. </>
  839. }
  840. {/* {state.enableNotation ? (
  841. <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]}>
  842. {{
  843. reference: () => (
  844. <div
  845. id={state.platform === IPlatform.PC ? "teacherTop-5" : "studnetT-5"}
  846. style={{ display: converBtn.value.display ? "" : "none" }}
  847. class={[styles.btn, converBtn.value.disabled && styles.disabled]}
  848. onClick={(e: Event) => {
  849. e.stopPropagation();
  850. headData.musicTypeShow = !headData.musicTypeShow;
  851. }}
  852. >
  853. <img class={styles.iconBtn} src={headImg("icon_zhuanpu.svg")} />
  854. <span>{state.musicRenderType === "staff" ? "转简谱" : "转五线谱"}</span>
  855. </div>
  856. ),
  857. default: () => <MusicType />,
  858. }}
  859. </Popover>
  860. ) : null} */}
  861. {state.musicRendered && !query.lessonTrainingId && !query.questionId && state.isConcert && (
  862. <div
  863. class={[styles.btn, state.playState === "play" && fingeringBtn.value.disabled && styles.disabled, toggleMusicSheet.show && styles.isMusicSheet, styles.musicSheet, "driver-10"]}
  864. onClick={() => {
  865. toggleMusicSheet.toggle(true);
  866. }}
  867. >
  868. <img class={styles.iconBtn} src={headImg(`shenggui.png`)} />
  869. <span>声部</span>
  870. </div>
  871. )}
  872. {
  873. <div
  874. class={[styles.btn, restoreBtn.value.disabled && styles.disabled, styles.cxSetBtn, "driver-5-1"]}
  875. onClick={() => resetSettings()}
  876. >
  877. <img class={styles.iconBtn} src={headImg("reset.png")} />
  878. <span>重置</span>
  879. </div>
  880. }
  881. <div
  882. id={state.platform === IPlatform.PC ? "teacherTop-6" : "studnetT-6"}
  883. style={{ display: settingBtn.value.display ? "" : "none" }}
  884. class={["driver-6", styles.btn, settingBtn.value.disabled && styles.disabled, headTopData.settingMode && styles.isSettingMode, styles.settingMode]}
  885. onClick={() => (headTopData.settingMode = true)}
  886. >
  887. <img class={styles.iconBtn} src={headImg("icon_menu.png")} />
  888. <span>设置</span>
  889. </div>
  890. </div>
  891. </div>
  892. {/** 指法点击区域 */}
  893. {
  894. state.fingeringInfo.direction === "transverse" && state.setting.displayFingering ?
  895. <div class={styles.headerMid} onClick={() => {
  896. fingerRef.value?.doubeClick()
  897. }}></div> : null
  898. }
  899. {/* 播放按钮 */}
  900. <div
  901. id="studnetT-7"
  902. style={{ display: playBtn.value.display ? "" : "none" }}
  903. class={[
  904. // 引导使用的类
  905. "driver-1",
  906. styles.playBtn,
  907. playBtn.value.disabled && styles.disabled,
  908. state.platform === IPlatform.PC && state.musicScoreBtnDirection === "left" ? styles.playLeftButton : state.platform === IPlatform.PC && state.musicScoreBtnDirection === "right" ? styles.playRightButton : "",
  909. ]}
  910. onClick={() => {
  911. // C调能播放唱名,非C调时,只有谱面类型是首调时,才能播放唱名
  912. if (!state.isCTone && state.playSource === 'mingSong') {
  913. const notPlayDesc = state.musicRenderType === EnumMusicRenderType.staff ? '该曲目的五线谱目前还不支持播放唱名' : state.musicRenderType === EnumMusicRenderType.fixedTone ? '该曲目的固定调目前还不支持播放唱名' : '';
  914. if (notPlayDesc) {
  915. showToast({
  916. message: notPlayDesc,
  917. position: "top",
  918. className: "selectionToast",
  919. });
  920. return
  921. }
  922. }
  923. togglePlay(state.playState === "play" ? "paused" : "play")
  924. }}
  925. >
  926. <div class={styles.btnWrap}>
  927. <img style={{ display: state.playState === "play" ? "none" : "" }} class={styles.iconBtn} src={headImg("icon_play.png")} />
  928. <img style={{ display: state.playState === "play" ? "" : "none" }} class={styles.iconBtn} src={headImg("icon_pause.png")} />
  929. <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)" />
  930. </div>
  931. </div>
  932. {/* 重播按钮 */}
  933. <div
  934. id="tips-step-9"
  935. style={{ display: resetBtn.value.display ? "" : "none" }}
  936. 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 : ""]}
  937. onClick={() => handleResetPlay()}
  938. >
  939. <img class={styles.iconBtn} src={headImg("icon_reset.png")} />
  940. </div>
  941. <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)" }}>
  942. <Settting />
  943. {state.platform === IPlatform.PC && <Dragbom showGuide={!state.guideInfo?.teacherDrag} onGuideDone={handleGuide} />}
  944. </Popup>
  945. {/* 模式切换 */}
  946. {/* <ModeTypeMode /> */}
  947. <ModeView></ModeView>
  948. {/* isAllBtns */}
  949. {/* {isAllBtns.value && !query.isCbs && showGuideIndex.value && <TeacherTop></TeacherTop>}
  950. {isAllBtnsStudent.value && !query.isCbs && showGuideIndex.value && <StudentTop></StudentTop>} */}
  951. {/* 练习模式功能引导 加载音频完成 不是会员 */}
  952. {state.modeType === "practise" && headTopData.modeType !== "init" && !query.isCbs && state.audioDone && !state.isLoading && showWebGuide.value && (
  953. <PractiseDriver
  954. statusAll={{
  955. playBtnStatus: playBtn.value.display,
  956. subjectStatus: state.musicRendered && !query.lessonTrainingId && !query.questionId && state.isConcert,
  957. modelTypeStatus: toggleBtn.value.display,
  958. playType: playTypeBtn.value.display,
  959. originPlayType: state.playType === "play" ? true : false,
  960. originBtnStatus: originBtn.value.display,
  961. backTitle: !(state.playState == "play" || followData.start || evaluatingData.startBegin) && isMusicList.value,
  962. titleType: smoothAnimationState.isShow.value ? "TEXT" : isMusicList.value ? "IMG" : "NONE",
  963. showSwitchList: isMusicList.value && !state.isHomeWork && !query.isHideMusicList,
  964. }}
  965. />
  966. )}
  967. {/* 跟练模式功能引导 加载音频完成 不是会员 */}
  968. {state.modeType === "follow" && headTopData.modeType !== "init" && !query.isCbs && state.audioDone && !state.isLoading && showWebGuide.value && (
  969. <FollowDriver
  970. statusAll={{
  971. subjectStatus: state.musicRendered && !query.lessonTrainingId && !query.questionId && state.isConcert,
  972. }}
  973. />
  974. )}
  975. {/* 评测模式功能引导 加载音频完成 不是会员 */}
  976. {state.modeType === "evaluating" && headTopData.modeType !== "init" && !evaluatingData.earphoneMode && !query.isCbs && state.audioDone && !state.isLoading && evaluatingData.websocketState && !evaluatingData.startBegin && evaluatingData.checkEnd && showWebGuide.value && (
  977. <EvaluatingDriver
  978. statusAll={{
  979. subjectStatus: state.musicRendered && !query.lessonTrainingId && !query.questionId && state.isConcert,
  980. }}
  981. />
  982. )}
  983. </>
  984. );
  985. },
  986. });