index.tsx 21 KB

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