index.tsx 44 KB

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