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. const isPad = navigator?.userAgent?.includes("UAWEIVRD-W09") || browInfo?.iPad || browInfo.isTablet;
  621. return () => (
  622. <>
  623. <div
  624. class={[styles.headerTop, state.platform === IPlatform.PC && state.musicScoreBtnDirection === "left" ? styles.headerTopRight : ""]}
  625. onClick={(e: Event) => {
  626. e.stopPropagation();
  627. if (state.platform === IPlatform.PC) {
  628. // 显示隐藏菜单
  629. window.parent.postMessage(
  630. {
  631. api: "onAttendToggleMenu",
  632. },
  633. "*"
  634. );
  635. }
  636. }}
  637. >
  638. {/* 返回和标题 */}
  639. {
  640. <div id="noticeBarRollDom" class={[styles.headTopLeftBox, (state.playState == "play" || followData.practiceStart || evaluatingData.startBegin) && styles.headTopLeftHide]}>
  641. {
  642. !query.isMove && !query.isHideBack && <img src={iconBack} class={["headTopBackBtn", styles.img, !headTopData.showBack && styles.hidenBack]} onClick={handleBack} />
  643. }
  644. {smoothAnimationState.isShow.value || state.isCombineRender ? (
  645. <div
  646. style={
  647. noticeBarWidth.value
  648. ? {
  649. "--noticeBarWidth": noticeBarWidth.value + "px",
  650. }
  651. : {}
  652. }
  653. class={[styles.title, state.isCbsView && styles.blackTitle, "headeTopTitleBtn", isPad && styles.isIpad]}
  654. onClick={() => {
  655. isMusicList.value && !state.isHomeWork && !query.isHideMusicList && (musicListShow.value = true);
  656. }}
  657. >
  658. {isMusicList.value && !state.isHomeWork && !query.isHideMusicList && <div class={[styles.symbolNote, "driver-8"]}></div>}
  659. <NoticeBar text={state.examSongName} background="none" />
  660. </div>
  661. ) : (
  662. isMusicList.value && !state.isHomeWork && !query.isHideMusicList && (
  663. <img
  664. src={listImg}
  665. class={[styles.img, styles.listImg, "driver-8"]}
  666. onClick={() => {
  667. musicListShow.value = true;
  668. }}
  669. />
  670. )
  671. )}
  672. </div>
  673. }
  674. {/* 模式提醒 */}
  675. {/* {state.modeType === "practise" && (
  676. <div class={[styles.modeWarn, "practiseModeWarn", state.platform === IPlatform.PC && state.musicScoreBtnDirection === "left" ? styles.modeWarnRight : ""]}>
  677. <img src={state.playType === "play" ? headImg("perform1.png") : headImg("sing1.png")} />
  678. <div>{state.playType === "play" ? "演奏场景" : "演唱场景"}</div>
  679. </div>
  680. )} */}
  681. {/* 功能按钮 */}
  682. <div
  683. class={[styles.headRight]}
  684. onClick={(e: Event) => {
  685. e.stopPropagation();
  686. }}
  687. >
  688. {/* 模式切换 */}
  689. {
  690. <div
  691. id={state.platform === IPlatform.PC ? "teacherTop-0" : "studnetT-0"}
  692. style={{ display: toggleBtn.value.display ? "" : "none"}}
  693. class={["driver-9", styles.btn, toggleBtn.value.disabled && styles.disabled, styles.modeType]}
  694. onClick={() => {
  695. headTopData.oldModeType = state.modeType;
  696. handleRessetState();
  697. headTopData.modeType = "init";
  698. }}
  699. >
  700. <img class={styles.iconBtn} src={iconMode} />
  701. <span>{state.modeType === "practise" ? "练习模式" : state.modeType === "follow" ? "跟练模式" : state.modeType === "evaluating" ? "评测模式" : ""}</span>
  702. </div>
  703. }
  704. {/* 一行谱模式,暂不支持节拍指针 */}
  705. {/* {(
  706. <div
  707. class={[styles.btn, state.platform === IPlatform.PC ? styles.pcBtn : ""]}
  708. onClick={() => {
  709. // 切换光标模式
  710. let mode = metronomeData.cursorMode;
  711. if (["follow"].includes(state.modeType)) {
  712. mode = metronomeData.cursorMode === 1 ? 3 : 1;
  713. } else {
  714. mode = metronomeData.cursorMode === 1 ? 3 : metronomeData.cursorMode === 2 ? 1 : 2;
  715. }
  716. metronomeData.cursorMode = mode;
  717. }}
  718. >
  719. <img class={styles.iconBtn} src={headImg(metronomeData.cursorMode === 1 ? "cursor_icon1.png" : metronomeData.cursorMode === 2 ? "cursor_icon2.png" : metronomeData.cursorMode === 3 ? "cursor_icon3.png" : "")} />
  720. <span class={styles.iconContent}>
  721. {metronomeData.cursorMode === 1 ? "音符指针" : metronomeData.cursorMode === 2 ? "节拍指针" : metronomeData.cursorMode === 3 ? "关闭指针" : ""}
  722. {metronomeData.cursorTips && (
  723. <div class={[styles["botton-tips"], metronomeData.cursorMode === 3 ? styles.tipSpec : ""]}>{metronomeData.cursorTips}</div>
  724. )}
  725. </span>
  726. </div>
  727. )} */}
  728. <div
  729. style={{ display: playTypeBtn.value.display ? "" : "none" }}
  730. class={["driver-2", styles.btn, playTypeBtn.value.disabled && styles.disabled, styles.playType]}
  731. onClick={() => {
  732. const oldPlayType = state.playType;
  733. headTopData.oldPlayType = oldPlayType;
  734. const oldPlaySource = state.playSource;
  735. if (state.playType === "play") {
  736. state.playType = "sing";
  737. state.playSource = state.fanSong ? "music" : state.banSong ? "background" : "mingSong";
  738. } else {
  739. state.playType = "play";
  740. state.playSource = state.music ? "music" : "background";
  741. }
  742. isClickMode = true;
  743. // 有指法并且显示指法的时候 切换到演唱模式 需要影藏指法
  744. let isRefresh = false;
  745. if (state.isShowFingering && state.fingeringInfo.name && (state.setting.displayFingering || displayFingeringCache)) {
  746. if (state.playType === "sing") {
  747. state.setting.displayFingering = false;
  748. displayFingeringCache = true;
  749. } else {
  750. state.setting.displayFingering = displayFingeringCache;
  751. displayFingeringCache = false;
  752. }
  753. // 如果是竖屏指法和一行谱的时候 改变指法值的时候state 会调用刷新 refreshMusicSvg 所以下面不调用
  754. if (state.fingeringInfo.direction === "vertical" && !state.isSingleLine) {
  755. isRefresh = true;
  756. }
  757. }
  758. // 有歌词的时候,切换播放模式,需要重新渲染谱面 指法不刷新谱面的时候
  759. if (state.xmlHasLyric && !isRefresh) {
  760. refreshMusicSvg();
  761. } else if (!isRefresh) {
  762. handlerModeChange(oldPlayType, oldPlaySource, true);
  763. }
  764. }}
  765. >
  766. <img style={{ display: state.playType === "play" ? "" : "none" }} class={styles.iconBtn} src={headImg(`perform.png`)} />
  767. <img style={{ display: state.playType === "play" ? "none" : "" }} class={styles.iconBtn} src={headImg(`sing.png`)} />
  768. <span>{state.playType === "play" ? "演奏" : "演唱"}</span>
  769. </div>
  770. <div
  771. id={state.platform === IPlatform.PC ? "teacherTop-1" : "studnetT-1"}
  772. style={{ display: originBtn.value.display ? "" : "none" }}
  773. class={["driver-3", styles.btn, originBtn.value.disabled && styles.disabled, state.playType === "play" ? styles.playSource : styles.songSource]}
  774. onClick={() => {
  775. const oldPlayType = state.playType;
  776. const oldPlaySource = state.playSource;
  777. if (state.playType === "play") {
  778. state.playSource = state.playSource === "music" ? "background" : "music";
  779. } else {
  780. if (state.playSource === "music") {
  781. state.playSource = state.banSong ? "background" : "mingSong";
  782. } else if (state.playSource === "background") {
  783. state.playSource = state.mingSong ? "mingSong" : "music";
  784. } else {
  785. state.playSource = state.fanSong ? "music" : "background";
  786. }
  787. }
  788. handlerModeChange(oldPlayType, oldPlaySource);
  789. showToast({
  790. message: state.playType === "play" ? (state.playSource === "music" ? "已切换为原声" : "已切换为伴奏") : state.playSource === "music" ? "已切换为范唱" : state.playSource === "background" ? "已切换为伴唱" : "已切换为唱名",
  791. position: "top",
  792. className: "selectionToast",
  793. });
  794. }}
  795. >
  796. <img style={{ display: state.playSource === "music" ? "" : "none" }} class={styles.iconBtn} src={state.playType === "play" ? headImg(`music.png`) : headImg(`music1.png`)} />
  797. <img style={{ display: state.playSource === "background" ? "" : "none" }} class={styles.iconBtn} src={state.playType === "play" ? headImg(`background.png`) : headImg(`background1.png`)} />
  798. <img style={{ display: state.playSource === "mingSong" ? "" : "none" }} class={styles.iconBtn} src={headImg(`mingsong.png`)} />
  799. <span>{state.playSource === "music" ? (state.playType === "play" ? "原声" : "范唱") : state.playSource === "background" ? (state.playType === "play" ? "伴奏" : "伴唱") : "唱名"}</span>
  800. </div>
  801. <div
  802. id={state.platform === IPlatform.PC ? "teacherTop-2" : "studnetT-2"}
  803. style={{ display: selectBtn.value.display ? "" : "none" }}
  804. class={["driver-4", styles.btn, selectBtn.value.disabled && styles.disabled, styles.section, state.sectionStatus && styles.isSection]}
  805. onClick={() => handleChangeSection()}
  806. >
  807. <img style={{ display: state.section.length === 0 ? "" : "none" }} class={styles.iconBtn} src={headImg(`section0.png`)} />
  808. <img style={{ display: state.section.length === 1 ? "" : "none" }} class={styles.iconBtn} src={headImg(`section1.png`)} />
  809. <img style={{ display: state.section.length === 2 ? "" : "none" }} class={styles.iconBtn} src={headImg(`section2.png`)} />
  810. <span>选段</span>
  811. </div>
  812. {
  813. <>
  814. <div
  815. style={{ display: metronomeBtn.value.display ? "" : "none" }}
  816. class={["driver-5", styles.btn, styles.metronomeBtn, metronomeBtn.value.disabled && styles.disabled, headData.speedShow && styles.isSpeed, styles.speed]}
  817. onClick={async () => {
  818. headData.speedShow = !headData.speedShow;
  819. }}
  820. >
  821. <img style={{ display: metronomeData.disable ? "block" : "none" }} class={styles.iconBtn} src={headImg("tickon.png")} />
  822. <img style={{ display: !metronomeData.disable ? "block" : "none" }} class={styles.iconBtn} src={headImg("tickoff.png")} />
  823. <span style={{ whiteSpace: "nowrap" }}>节拍</span>
  824. <div class={styles.speedCon}>
  825. <img src={headImg("speed.png")} />
  826. <div>{Math.floor(state.speed)}</div>
  827. </div>
  828. </div>
  829. {
  830. <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)" }}>
  831. <Speed />
  832. {state.platform === IPlatform.PC && <Dragbom showGuide={!state.guideInfo?.teacherDrag} onGuideDone={handleGuide} />}
  833. </Popup>
  834. }
  835. </>
  836. }
  837. {/* {state.enableNotation ? (
  838. <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]}>
  839. {{
  840. reference: () => (
  841. <div
  842. id={state.platform === IPlatform.PC ? "teacherTop-5" : "studnetT-5"}
  843. style={{ display: converBtn.value.display ? "" : "none" }}
  844. class={[styles.btn, converBtn.value.disabled && styles.disabled]}
  845. onClick={(e: Event) => {
  846. e.stopPropagation();
  847. headData.musicTypeShow = !headData.musicTypeShow;
  848. }}
  849. >
  850. <img class={styles.iconBtn} src={headImg("icon_zhuanpu.svg")} />
  851. <span>{state.musicRenderType === "staff" ? "转简谱" : "转五线谱"}</span>
  852. </div>
  853. ),
  854. default: () => <MusicType />,
  855. }}
  856. </Popover>
  857. ) : null} */}
  858. {state.musicRendered && !query.lessonTrainingId && !query.questionId && state.isConcert && (
  859. <div
  860. class={[styles.btn, state.playState === "play" && fingeringBtn.value.disabled && styles.disabled, toggleMusicSheet.show && styles.isMusicSheet, styles.musicSheet, "driver-10"]}
  861. onClick={() => {
  862. toggleMusicSheet.toggle(true);
  863. }}
  864. >
  865. <img class={styles.iconBtn} src={headImg(`shenggui.png`)} />
  866. <span>声部</span>
  867. </div>
  868. )}
  869. {
  870. <div
  871. class={[styles.btn, restoreBtn.value.disabled && styles.disabled, "driver-5-1"]}
  872. onClick={() => resetSettings()}
  873. >
  874. <img class={styles.iconBtn} src={headImg("reset.png")} />
  875. <span>重置</span>
  876. </div>
  877. }
  878. <div
  879. id={state.platform === IPlatform.PC ? "teacherTop-6" : "studnetT-6"}
  880. style={{ display: settingBtn.value.display ? "" : "none" }}
  881. class={["driver-6", styles.btn, settingBtn.value.disabled && styles.disabled, headTopData.settingMode && styles.isSettingMode, styles.settingMode]}
  882. onClick={() => (headTopData.settingMode = true)}
  883. >
  884. <img class={styles.iconBtn} src={headImg("icon_menu.png")} />
  885. <span>设置</span>
  886. </div>
  887. </div>
  888. </div>
  889. {/** 指法点击区域 */}
  890. {
  891. state.fingeringInfo.direction === "transverse" && state.setting.displayFingering ?
  892. <div class={styles.headerMid} onClick={() => {
  893. fingerRef.value?.doubeClick()
  894. }}></div> : null
  895. }
  896. {/* 播放按钮 */}
  897. <div
  898. id="studnetT-7"
  899. style={{ display: playBtn.value.display ? "" : "none" }}
  900. class={[
  901. // 引导使用的类
  902. "driver-1",
  903. styles.playBtn,
  904. playBtn.value.disabled && styles.disabled,
  905. state.platform === IPlatform.PC && state.musicScoreBtnDirection === "left" ? styles.playLeftButton : state.platform === IPlatform.PC && state.musicScoreBtnDirection === "right" ? styles.playRightButton : "",
  906. ]}
  907. onClick={() => {
  908. // C调能播放唱名,非C调时,只有谱面类型是首调时,才能播放唱名
  909. if (!state.isCTone && state.playSource === 'mingSong') {
  910. const notPlayDesc = state.musicRenderType === EnumMusicRenderType.staff ? '该曲目的五线谱目前还不支持播放唱名' : state.musicRenderType === EnumMusicRenderType.fixedTone ? '该曲目的固定调目前还不支持播放唱名' : '';
  911. if (notPlayDesc) {
  912. showToast({
  913. message: notPlayDesc,
  914. position: "top",
  915. className: "selectionToast",
  916. });
  917. return
  918. }
  919. }
  920. togglePlay(state.playState === "play" ? "paused" : "play")
  921. }}
  922. >
  923. <div class={styles.btnWrap}>
  924. <img style={{ display: state.playState === "play" ? "none" : "" }} class={styles.iconBtn} src={headImg("icon_play.png")} />
  925. <img style={{ display: state.playState === "play" ? "" : "none" }} class={styles.iconBtn} src={headImg("icon_pause.png")} />
  926. <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)" />
  927. </div>
  928. </div>
  929. {/* 重播按钮 */}
  930. <div
  931. id="tips-step-9"
  932. style={{ display: resetBtn.value.display ? "" : "none" }}
  933. 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 : ""]}
  934. onClick={() => handleResetPlay()}
  935. >
  936. <img class={styles.iconBtn} src={headImg("icon_reset.png")} />
  937. </div>
  938. <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)" }}>
  939. <Settting />
  940. {state.platform === IPlatform.PC && <Dragbom showGuide={!state.guideInfo?.teacherDrag} onGuideDone={handleGuide} />}
  941. </Popup>
  942. {/* 模式切换 */}
  943. {/* <ModeTypeMode /> */}
  944. <ModeView></ModeView>
  945. {/* isAllBtns */}
  946. {/* {isAllBtns.value && !query.isCbs && showGuideIndex.value && <TeacherTop></TeacherTop>}
  947. {isAllBtnsStudent.value && !query.isCbs && showGuideIndex.value && <StudentTop></StudentTop>} */}
  948. {/* 练习模式功能引导 加载音频完成 不是会员 */}
  949. {state.modeType === "practise" && headTopData.modeType !== "init" && !query.isCbs && state.audioDone && !state.isLoading && showWebGuide.value && (
  950. <PractiseDriver
  951. statusAll={{
  952. playBtnStatus: playBtn.value.display,
  953. subjectStatus: state.musicRendered && !query.lessonTrainingId && !query.questionId && state.isConcert,
  954. modelTypeStatus: toggleBtn.value.display,
  955. playType: playTypeBtn.value.display,
  956. originPlayType: state.playType === "play" ? true : false,
  957. originBtnStatus: originBtn.value.display,
  958. backTitle: !(state.playState == "play" || followData.start || evaluatingData.startBegin) && isMusicList.value,
  959. titleType: smoothAnimationState.isShow.value ? "TEXT" : isMusicList.value ? "IMG" : "NONE",
  960. }}
  961. />
  962. )}
  963. {/* 跟练模式功能引导 加载音频完成 不是会员 */}
  964. {state.modeType === "follow" && headTopData.modeType !== "init" && !query.isCbs && state.audioDone && !state.isLoading && showWebGuide.value && (
  965. <FollowDriver
  966. statusAll={{
  967. subjectStatus: state.musicRendered && !query.lessonTrainingId && !query.questionId && state.isConcert,
  968. }}
  969. />
  970. )}
  971. {/* 评测模式功能引导 加载音频完成 不是会员 */}
  972. {state.modeType === "evaluating" && headTopData.modeType !== "init" && !evaluatingData.earphoneMode && !query.isCbs && state.audioDone && !state.isLoading && evaluatingData.websocketState && !evaluatingData.startBegin && evaluatingData.checkEnd && showWebGuide.value && (
  973. <EvaluatingDriver
  974. statusAll={{
  975. subjectStatus: state.musicRendered && !query.lessonTrainingId && !query.questionId && state.isConcert,
  976. }}
  977. />
  978. )}
  979. </>
  980. );
  981. },
  982. });