index.tsx 44 KB

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