index.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. import { Transition, computed, defineComponent, onMounted, onUnmounted, reactive, ref, watch } from "vue";
  2. import styles from "./index.module.less";
  3. import iconBack from "./image/icon-back.svg";
  4. import Title from "./title";
  5. import { headImg } from "./image";
  6. import { Badge, Circle, Popover, Popup, showConfirmDialog } from "vant";
  7. import Speed from "./speed";
  8. import { evaluatingData, handleStartEvaluat } from "/src/view/evaluating";
  9. import Settting from "./settting";
  10. import state, { IPlatform, handleChangeSection, handleResetPlay, handleRessetState, togglePlay } from "/src/state";
  11. import { getAudioCurrentTime } from "/src/view/audio-list";
  12. import { followData, toggleFollow } from "/src/view/follow-practice";
  13. import { api_back } from "/src/helpers/communication";
  14. import MusicType from "./music-type";
  15. import ModeTypeMode from "../component/mode-type-mode";
  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. /** 头部数据和方法 */
  27. export const headTopData = reactive({
  28. /** 模式 */
  29. modeType: "" as "init" | "show",
  30. /** 显示返回按钮 */
  31. showBack: true,
  32. /** 设置弹窗 */
  33. settingMode: false,
  34. /** 切换模式 */
  35. handleChangeModeType(value: "practise" | "follow" | "evaluating") {
  36. // 后台设置为不能评测
  37. if (value === 'evaluating' && !state.enableEvaluation) return
  38. // 打击乐&节奏练习不支持跟练模式
  39. if (value === 'follow' && state.isPercussion) return
  40. // 跟练模式,光标只有音符模式,无节拍模式
  41. if (value === 'follow' && metronomeData.cursorMode === 2) {
  42. metronomeData.cursorMode = 1
  43. }
  44. if (value === 'practise') {
  45. // state.playIngSpeed = state.speed
  46. }
  47. if (value === "evaluating") {
  48. // 如果是pc端, 评测模式暂不可用
  49. if (state.platform === IPlatform.PC) {
  50. showConfirmDialog({
  51. className: "modalTip",
  52. title: "温馨提示",
  53. message: "该功能暂未开放,敬请期待!",
  54. showCancelButton: false,
  55. });
  56. return;
  57. }
  58. state.playIngSpeed = state.originSpeed
  59. handleStartEvaluat();
  60. } else if (value === "follow") {
  61. toggleFollow();
  62. }
  63. headTopData.modeType = "show";
  64. },
  65. });
  66. export const headData = reactive({
  67. speedShow: false,
  68. musicTypeShow: false,
  69. });
  70. export default defineComponent({
  71. name: "header-top",
  72. emits: ["close"],
  73. setup(props, { emit }) {
  74. const query = getQuery();
  75. // 是否显示引导
  76. const showGuide = ref(false);
  77. const showStudentGuide = ref(false);
  78. /** 设置按钮 */
  79. const settingBtn = computed(() => {
  80. // 音频播放中 禁用
  81. if (state.playState === "play") return { display: true, disabled: true };
  82. // 评测开始 禁用, 跟练开始 禁用
  83. if (evaluatingData.startBegin || followData.start) return { display: true, disabled: true };
  84. return {
  85. display: true,
  86. disabled: false,
  87. };
  88. });
  89. /** 转谱按钮 */
  90. const converBtn = computed(() => {
  91. // 音频播放中 禁用
  92. if (state.playState === "play") return { display: true, disabled: true };
  93. // 评测开始 禁用
  94. if (evaluatingData.startBegin || followData.start) return { display: true, disabled: true };
  95. return {
  96. disabled: false,
  97. display: true,
  98. };
  99. });
  100. /** 速度按钮 */
  101. const speedBtn = computed(() => {
  102. // 选择模式, 跟练模式 不显示
  103. if (headTopData.modeType !== "show" || state.modeType === "follow") return { display: false, disabled: true };
  104. // 评测模式, 音频播放中 禁用
  105. if (state.modeType === "evaluating" || state.playState === "play") return { display: true, disabled: true };
  106. return {
  107. disabled: false,
  108. display: true,
  109. };
  110. });
  111. /** 指法按钮 */
  112. const fingeringBtn = computed(() => {
  113. // 后台设置不显示指法
  114. if (!state.isShowFingering) return { display: true, disabled: true };
  115. // 没有指法 选择模式 评测模式 跟练模式 不显示
  116. if (headTopData.modeType !== "show" || !state.fingeringInfo.name || ["evaluating", "follow"].includes(state.modeType)) return { display: false, disabled: true };
  117. // 音频播放中 禁用
  118. if (state.playState === "play") return { display: true, disabled: true };
  119. return {
  120. disabled: false,
  121. display: true,
  122. };
  123. });
  124. /** 摄像头按钮 */
  125. const cameraBtn = computed(() => {
  126. // 选择模式 不显示
  127. if (headTopData.modeType !== "show" || state.modeType !== "evaluating") return { display: false, disabled: true };
  128. // 音频播放中 禁用
  129. if (state.playState === "play") return { display: true, disabled: true };
  130. return {
  131. disabled: false,
  132. display: true,
  133. };
  134. });
  135. /** 选段按钮 */
  136. const selectBtn = computed(() => {
  137. // 选择模式 不显示
  138. if (headTopData.modeType !== "show" || ["evaluating", "follow"].includes(state.modeType)) return { display: false, disabled: true };
  139. // 音频播放中 禁用
  140. if (state.playState === "play") return { display: true, disabled: true };
  141. return {
  142. disabled: false,
  143. display: true,
  144. };
  145. });
  146. /** 原声按钮 */
  147. const originBtn = computed(() => {
  148. // 选择模式,跟练模式 不显示
  149. if (headTopData.modeType !== "show" || state.modeType === "follow") return { display: false, disabled: false };
  150. // 评测开始 禁用
  151. if (state.modeType === "evaluating") return { display: false, disabled: true };
  152. if (!state.isAppPlay) {
  153. // 原声, 伴奏 少一个,就不能切换
  154. if (!state.music || !state.accompany) return { display: true, disabled: true };
  155. }
  156. return {
  157. disabled: false,
  158. display: true,
  159. };
  160. });
  161. /** 模式切换按钮 */
  162. const toggleBtn = computed(() => {
  163. // 选择模式, url设置模式 不显示
  164. if (headTopData.modeType !== "show" || !headTopData.showBack) return { display: false, disabled: false };
  165. // 跟练开始, 评测开始 禁用
  166. if (followData.start || evaluatingData.startBegin) return { display: true, disabled: true };
  167. return {
  168. display: true,
  169. disabled: false,
  170. };
  171. });
  172. /** 播放按钮 */
  173. const playBtn = computed(() => {
  174. // 选择模式 不显示
  175. if (headTopData.modeType !== "show") return { display: false, disabled: false };
  176. // 评测模式 不显示,跟练模式 不显示
  177. if (["evaluating", "follow"].includes(state.modeType)) return { display: false, disabled: true };
  178. // midi音频未初始化完成不可点击
  179. if (state.isAppPlay && state.midiPlayIniting) return { display: true, disabled: true };
  180. return {
  181. display: true,
  182. disabled: false,
  183. };
  184. });
  185. /** 重播按钮 */
  186. const resetBtn = computed(() => {
  187. // 选择模式 不显示
  188. if (headTopData.modeType !== "show") return { display: false, disabled: false };
  189. // 评测模式 不显示,跟练模式 不显示
  190. if (["evaluating", "follow"].includes(state.modeType)) return { display: false, disabled: true };
  191. // 播放状态 不显示
  192. if (state.playState === "play") return { display: false, disabled: true };
  193. // 播放进度为0 不显示
  194. const currentTime = getAudioCurrentTime();
  195. // midi音频未初始化完成不可点击
  196. if (state.isAppPlay && state.midiPlayIniting) return { display: false, disabled: true };
  197. if (!currentTime) return { display: false, disabled: true };
  198. return {
  199. display: true,
  200. disabled: false,
  201. };
  202. });
  203. const isAllBtns = computed(() => {
  204. const flag = converBtn.value.display && speedBtn.value.display && selectBtn.value.display && originBtn.value.display && toggleBtn.value.display && showGuide.value;
  205. return flag;
  206. });
  207. const isAllBtnsStudent = computed(() => {
  208. const flag = converBtn.value.display && speedBtn.value.display && selectBtn.value.display && originBtn.value.display && toggleBtn.value.display && showStudentGuide.value;
  209. return flag;
  210. });
  211. const browInfo = browser();
  212. /** 返回 */
  213. const handleBack = () => {
  214. HANDLE_WORK_ADD();
  215. // 不在APP中,
  216. if (!storeData.isApp) {
  217. window.close();
  218. return;
  219. }
  220. if ((browInfo.iPhone || browInfo.ios) && query.workRecord) {
  221. setTimeout(() => {
  222. api_back();
  223. }, 550);
  224. return;
  225. }
  226. api_back();
  227. };
  228. /** 根据参数设置模式 */
  229. const getQueryModelSetModelType = () => {
  230. /** 作业模式 start, 如果为作业模式不处理,让作业模块处理 */
  231. if (query.workRecord) {
  232. return;
  233. }
  234. /** 作业模式 end */
  235. if (query.modelType) {
  236. if (query.modelType === "practise") {
  237. headTopData.handleChangeModeType("practise");
  238. } else if (query.modelType === "evaluating") {
  239. headTopData.handleChangeModeType("evaluating");
  240. }
  241. headTopData.showBack = false;
  242. } else {
  243. setTimeout(() => {
  244. headTopData.modeType = "init";
  245. }, 500);
  246. }
  247. };
  248. /** 课件播放 */
  249. const changePlay = (res: any) => {
  250. if (res?.data?.api === "setPlayState") {
  251. togglePlay("paused");
  252. }
  253. // 菜单状态
  254. if ((state.platform === IPlatform.PC && res?.data?.api) === "attendClassBarStatus") {
  255. state.attendHideMenu = res?.data?.hideMenu;
  256. }
  257. };
  258. onMounted(() => {
  259. getQueryModelSetModelType();
  260. window.addEventListener("message", changePlay);
  261. if (state.platform === IPlatform.PC) {
  262. showGuide.value = true;
  263. } else {
  264. showStudentGuide.value = true;
  265. }
  266. });
  267. onUnmounted(() => {
  268. window.removeEventListener("message", changePlay);
  269. });
  270. // 设置改变触发
  271. watch(state.setting, () => {
  272. console.log(state.setting, "state.setting");
  273. store.set("musicscoresetting", state.setting);
  274. });
  275. return () => (
  276. <>
  277. <div
  278. class={[styles.headerTop, state.platform === IPlatform.PC && styles.headRightTop, state.platform === IPlatform.PC && !state.attendHideMenu && styles.headRightTopHide]}
  279. onClick={(e: Event) => {
  280. e.stopPropagation();
  281. if (state.platform === IPlatform.PC) {
  282. // 显示隐藏菜单
  283. window.parent.postMessage(
  284. {
  285. api: "onAttendToggleMenu",
  286. },
  287. "*"
  288. );
  289. }
  290. }}
  291. >
  292. <div class={[styles.back, "headTopBackBtn", !headTopData.showBack && styles.hidenBack]} onClick={handleBack}>
  293. <img src={iconBack} />
  294. </div>
  295. {query.iscurseplay === "play" ? null : <Title class="pcTitle" text={state.examSongName} rightView={false} />}
  296. <div
  297. class={[styles.headRight]}
  298. onClick={(e: Event) => {
  299. e.stopPropagation();
  300. }}
  301. >
  302. <div
  303. id={state.platform === IPlatform.PC ? "teacherTop-0" : "studnetT-0"}
  304. style={{ display: toggleBtn.value.display ? "" : "none" }}
  305. class={[styles.btn, toggleBtn.value.disabled && styles.disabled]}
  306. onClick={() => {
  307. handleRessetState();
  308. headTopData.modeType = "init";
  309. }}
  310. >
  311. <img class={styles.iconBtn} src={headImg(`modeType.svg`)} />
  312. <span>模式</span>
  313. </div>
  314. <div class={[styles.btn]} onClick={() => {
  315. // 切换光标模式
  316. let mode = metronomeData.cursorMode
  317. if (['follow'].includes(state.modeType)) {
  318. mode = metronomeData.cursorMode === 1 ? 3 : 1
  319. } else {
  320. mode = metronomeData.cursorMode === 3 ? 1 : metronomeData.cursorMode + 1
  321. }
  322. metronomeData.cursorMode = mode
  323. }}>
  324. <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' : '')} />
  325. <span class={styles.iconContent}>
  326. {metronomeData.cursorMode === 1 ? '音符指针' : metronomeData.cursorMode === 2 ? '节拍指针' : metronomeData.cursorMode === 3 ? '关闭指针' : ''}
  327. {metronomeData.cursorTips && <>
  328. <i class={styles.arrowIcon}></i>
  329. <div class={[styles['botton-tips'],metronomeData.cursorMode === 3 ? styles.tipSpec : '']}>{metronomeData.cursorTips}</div>
  330. </>}
  331. </span>
  332. </div>
  333. {state.musicRendered && !query.lessonTrainingId && !query.questionId && state.isConcert && (
  334. <div class={[styles.btn, (state.playState === "play" && fingeringBtn.value.disabled) && styles.disabled]}
  335. onClick={() => {
  336. toggleMusicSheet.toggle(true)
  337. }}>
  338. <img class={styles.iconBtn} src={headImg(`shenggui.svg`)} />
  339. <span>声轨</span>
  340. </div>
  341. )}
  342. <div
  343. id={state.platform === IPlatform.PC ? "teacherTop-1" : "studnetT-1"}
  344. style={{ display: originBtn.value.display ? "" : "none" }}
  345. class={[styles.btn, originBtn.value.disabled && styles.disabled]}
  346. onClick={() => {
  347. state.playSource = state.playSource === "music" ? "background" : "music";
  348. }}
  349. >
  350. <img style={{ display: state.playSource === "music" ? "" : "none" }} class={styles.iconBtn} src={headImg(`music.svg`)} />
  351. <img style={{ display: state.playSource === "music" ? "none" : "" }} class={styles.iconBtn} src={headImg(`background.svg`)} />
  352. <span>{state.playSource === "music" ? "原声" : "伴奏"}</span>
  353. </div>
  354. {
  355. state.modeType !== "evaluating" &&
  356. <div
  357. class={[styles.btn]}
  358. onClick={async () => {
  359. metronomeData.disable = !metronomeData.disable;
  360. metronomeData.metro?.initPlayer();
  361. }}
  362. >
  363. <img style={{ display: metronomeData.disable ? "block" : "none" }} class={styles.iconBtn} src={headImg("tickoff.svg")} />
  364. <img style={{ display: !metronomeData.disable ? "block" : "none" }} class={styles.iconBtn} src={headImg("tickon.svg")} />
  365. <span style={{ whiteSpace: "nowrap" }}>节拍器</span>
  366. </div>
  367. }
  368. <div id={state.platform === IPlatform.PC ? "teacherTop-2" : "studnetT-2"} style={{ display: selectBtn.value.display ? "" : "none" }} class={[styles.btn, selectBtn.value.disabled && styles.disabled]} onClick={() => handleChangeSection()}>
  369. <img style={{ display: state.section.length === 0 ? "" : "none" }} class={styles.iconBtn} src={headImg(`section0.svg`)} />
  370. <img style={{ display: state.section.length === 1 ? "" : "none" }} class={styles.iconBtn} src={headImg(`section1.svg`)} />
  371. <img style={{ display: state.section.length === 2 ? "" : "none" }} class={styles.iconBtn} src={headImg(`section2.svg`)} />
  372. <span>选段</span>
  373. </div>
  374. <div
  375. id={state.platform === IPlatform.PC ? "teacherTop-3" : "studnetT-3"}
  376. style={{ display: fingeringBtn.value.display ? "" : "none" }}
  377. class={[styles.btn, fingeringBtn.value.disabled && styles.disabled]}
  378. onClick={() => {
  379. state.setting.displayFingering = !state.setting.displayFingering;
  380. }}
  381. >
  382. <img style={{ display: state.setting.displayFingering ? "" : "none" }} class={styles.iconBtn} src={headImg(`icon_evaluatingOn.svg`)} />
  383. <img style={{ display: state.setting.displayFingering ? "none" : "" }} class={styles.iconBtn} src={headImg(`icon_evaluatingOff.svg`)} />
  384. <span>指法</span>
  385. </div>
  386. <Popover trigger="manual" v-model:show={headData.speedShow} placement="bottom" overlay={false}>
  387. {{
  388. reference: () => (
  389. <div
  390. id={state.platform === IPlatform.PC ? "teacherTop-4" : "studnetT-4"}
  391. style={{ display: speedBtn.value.display ? "" : "none" }}
  392. class={[styles.btn, speedBtn.value.disabled && styles.disabled]}
  393. onClick={(e: Event) => {
  394. e.stopPropagation();
  395. headData.speedShow = !headData.speedShow;
  396. }}
  397. >
  398. <Badge class={styles.badge} content={state.playState === "play" ? state.playIngSpeed : state.speed}>
  399. <img class={styles.iconBtn} src={headImg("icon_speed.svg")} />
  400. </Badge>
  401. <span>速度</span>
  402. </div>
  403. ),
  404. default: () => <Speed />,
  405. }}
  406. </Popover>
  407. {
  408. state.enableNotation ?
  409. <Popover trigger="manual" v-model:show={headData.musicTypeShow} placement="bottom-end" overlay={false}>
  410. {{
  411. reference: () => (
  412. <div
  413. id={state.platform === IPlatform.PC ? "teacherTop-5" : "studnetT-5"}
  414. style={{ display: converBtn.value.display ? "" : "none" }}
  415. class={[styles.btn, converBtn.value.disabled && styles.disabled]}
  416. onClick={(e: Event) => {
  417. e.stopPropagation();
  418. headData.musicTypeShow = !headData.musicTypeShow;
  419. }}
  420. >
  421. <img class={styles.iconBtn} src={headImg("icon_zhuanpu.svg")} />
  422. <span>{state.musicRenderType === "staff" ? "转简谱" : "转五线谱"}</span>
  423. </div>
  424. ),
  425. default: () => <MusicType />,
  426. }}
  427. </Popover> : null
  428. }
  429. <div id={state.platform === IPlatform.PC ? "teacherTop-6" : "studnetT-6"} style={{ display: settingBtn.value.display ? "" : "none" }} class={[styles.btn, styles.setBtn, settingBtn.value.disabled && styles.disabled]} onClick={() => (headTopData.settingMode = true)}>
  430. <img class={styles.iconBtn} src={headImg("icon_menu.svg")} />
  431. <span>设置</span>
  432. </div>
  433. </div>
  434. </div>
  435. {/* 播放按钮 */}
  436. <div
  437. id="studnetT-7"
  438. style={{ display: playBtn.value.display ? "" : "none" }}
  439. class={[styles.btn, styles.playBtn, playBtn.value.disabled && styles.disabled, state.platform === IPlatform.PC && styles.playButton, state.platform === IPlatform.PC && !state.attendHideMenu && styles.playButtonHide]}
  440. onClick={() => togglePlay()}
  441. >
  442. <div class={styles.btnWrap}>
  443. <img style={{ display: state.playState === "play" ? "none" : "" }} class={styles.iconBtn} src={headImg("icon_play.svg")} />
  444. <img style={{ display: state.playState === "play" ? "" : "none" }} class={styles.iconBtn} src={headImg("icon_pause.svg")} />
  445. <Circle style={{ opacity: state.playState === "play" ? 1 : 0 }} class={styles.progress} stroke-width={80} currentRate={state.playProgress} rate={100} color="#FFC830" />
  446. </div>
  447. </div>
  448. {/* 重播按钮 */}
  449. <div
  450. id="tips-step-9"
  451. style={{ display: resetBtn.value.display ? "" : "none" }}
  452. class={[styles.btn, styles.resetBtn, resetBtn.value.disabled && styles.disabled, state.platform === IPlatform.PC && styles.pauseButton, state.platform === IPlatform.PC && !state.attendHideMenu && styles.playButtonHide]}
  453. onClick={() => handleResetPlay()}
  454. >
  455. <img class={styles.iconBtn} src={headImg("icon_resetbtn.svg")} />
  456. </div>
  457. <Popup v-model:show={headTopData.settingMode} class="popup-custom van-scale center-closeBtn" transition="van-scale" teleport="body" closeable>
  458. <Settting />
  459. </Popup>
  460. {/* 模式切换 */}
  461. <ModeTypeMode />
  462. {/* isAllBtns */}
  463. {isAllBtns.value && !query.isCbs && <TeacherTop></TeacherTop>}
  464. {isAllBtnsStudent.value && !query.isCbs && <StudentTop></StudentTop>}
  465. </>
  466. );
  467. },
  468. });