index.tsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. import { Transition, computed, defineComponent, onMounted, onUnmounted, reactive, ref } 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. /** 头部数据和方法 */
  18. export const headTopData = reactive({
  19. /** 模式 */
  20. modeType: "" as "init" | "show",
  21. /** 显示返回按钮 */
  22. showBack: true,
  23. /** 设置弹窗 */
  24. settingMode: false,
  25. /** 切换模式 */
  26. handleChangeModeType(value: "practise" | "follow" | "evaluating") {
  27. if (value === "evaluating") {
  28. console.log(state.platform)
  29. if (state.platform === IPlatform.PC){
  30. showConfirmDialog({
  31. title: '温馨提示',
  32. message: '该功能暂未开发,敬请期待',
  33. showCancelButton: false,
  34. })
  35. return
  36. }
  37. handleStartEvaluat();
  38. } else if (value === "follow") {
  39. toggleFollow();
  40. }
  41. headTopData.modeType = "show";
  42. },
  43. });
  44. export const headData = reactive({
  45. speedShow: false,
  46. musicTypeShow: false,
  47. });
  48. export default defineComponent({
  49. name: "header-top",
  50. setup() {
  51. /** 设置按钮 */
  52. const settingBtn = computed(() => {
  53. // 音频播放中 禁用
  54. if (state.playState === "play") return { display: true, disabled: true };
  55. // 评测开始 禁用, 跟练开始 禁用
  56. if (evaluatingData.startBegin || followData.start) return { display: true, disabled: true };
  57. return {
  58. display: true,
  59. disabled: false,
  60. };
  61. });
  62. /** 转谱按钮 */
  63. const converBtn = computed(() => {
  64. // 音频播放中 禁用
  65. if (state.playState === "play") return { display: true, disabled: true };
  66. // 评测开始 禁用
  67. if (evaluatingData.startBegin || followData.start) return { display: true, disabled: true };
  68. return {
  69. disabled: false,
  70. display: true,
  71. };
  72. });
  73. /** 速度按钮 */
  74. const speedBtn = computed(() => {
  75. // 选择模式, 跟练模式 不显示
  76. if (headTopData.modeType !== "show" || state.modeType === "follow")
  77. return { display: false, disabled: true };
  78. // 评测模式, 音频播放中 禁用
  79. if (state.modeType === "evaluating" || state.playState === "play")
  80. return { display: true, disabled: true };
  81. return {
  82. disabled: false,
  83. display: true,
  84. };
  85. });
  86. /** 指法按钮 */
  87. const fingeringBtn = computed(() => {
  88. // 没有指法 选择模式 评测模式 跟练模式 不显示
  89. if (
  90. headTopData.modeType !== "show" ||
  91. !state.fingeringInfo.name ||
  92. ["evaluating", "follow"].includes(state.modeType)
  93. )
  94. return { display: false, disabled: true };
  95. // 音频播放中 禁用
  96. if (state.playState === "play") return { display: true, disabled: true };
  97. return {
  98. disabled: false,
  99. display: true,
  100. };
  101. });
  102. /** 摄像头按钮 */
  103. const cameraBtn = computed(() => {
  104. // 选择模式 不显示
  105. if (headTopData.modeType !== "show" || state.modeType !== "evaluating")
  106. return { display: false, disabled: true };
  107. // 音频播放中 禁用
  108. if (state.playState === "play") return { display: true, disabled: true };
  109. return {
  110. disabled: false,
  111. display: true,
  112. };
  113. });
  114. /** 选段按钮 */
  115. const selectBtn = computed(() => {
  116. // 选择模式 不显示
  117. if (headTopData.modeType !== "show" || ["evaluating", "follow"].includes(state.modeType))
  118. return { display: false, disabled: true };
  119. // 音频播放中 禁用
  120. if (state.playState === "play") return { display: true, disabled: true };
  121. return {
  122. disabled: false,
  123. display: true,
  124. };
  125. });
  126. /** 原声按钮 */
  127. const originBtn = computed(() => {
  128. // 选择模式,跟练模式 不显示
  129. if (headTopData.modeType !== "show" || state.modeType === "follow")
  130. return { display: false, disabled: false };
  131. // 评测开始 禁用
  132. if (state.modeType === "evaluating") return { display: false, disabled: true };
  133. // 原声, 伴奏 少一个,就不能切换
  134. if (!state.music || !state.accompany) return { display: true, disabled: true };
  135. return {
  136. disabled: false,
  137. display: true,
  138. };
  139. });
  140. /** 模式切换按钮 */
  141. const toggleBtn = computed(() => {
  142. // 选择模式, url设置模式 不显示
  143. if (headTopData.modeType !== "show" || !headTopData.showBack)
  144. return { display: false, disabled: false };
  145. // 跟练开始, 评测开始 禁用
  146. if (followData.start || evaluatingData.startBegin) return { display: true, disabled: true };
  147. return {
  148. display: true,
  149. disabled: false,
  150. };
  151. });
  152. /** 播放按钮 */
  153. const playBtn = computed(() => {
  154. // 选择模式 不显示
  155. if (headTopData.modeType !== "show") return { display: false, disabled: false };
  156. // 评测模式 不显示,跟练模式 不显示
  157. if (["evaluating", "follow"].includes(state.modeType)) return { display: false, disabled: true };
  158. return {
  159. display: true,
  160. disabled: false,
  161. };
  162. });
  163. /** 重播按钮 */
  164. const resetBtn = computed(() => {
  165. // 选择模式 不显示
  166. if (headTopData.modeType !== "show") return { display: false, disabled: false };
  167. // 评测模式 不显示,跟练模式 不显示
  168. if (["evaluating", "follow"].includes(state.modeType)) return { display: false, disabled: true };
  169. // 播放状态 不显示
  170. if (state.playState === "play") return { display: false, disabled: true };
  171. // 播放进度为0 不显示
  172. const currentTime = getAudioCurrentTime();
  173. if (!currentTime) return { display: false, disabled: true };
  174. return {
  175. display: true,
  176. disabled: false,
  177. };
  178. });
  179. /** 返回 */
  180. const handleBack = () => {
  181. api_back();
  182. };
  183. /** 根据参数设置模式 */
  184. const getQueryModelSetModelType = () => {
  185. const query: any = getQuery();
  186. if (query.modelType) {
  187. if (query.modelType === "practise") {
  188. headTopData.handleChangeModeType("practise");
  189. } else if (query.modelType === "evaluating") {
  190. headTopData.handleChangeModeType("evaluating");
  191. }
  192. headTopData.showBack = false;
  193. } else {
  194. setTimeout(() => {
  195. headTopData.modeType = "init";
  196. }, 500);
  197. }
  198. };
  199. /** 课件播放 */
  200. const changePlay = (res: any) => {
  201. if (res?.data?.api === "setPlayState") {
  202. togglePlay("paused");
  203. }
  204. };
  205. onMounted(() => {
  206. getQueryModelSetModelType();
  207. window.addEventListener("message", changePlay);
  208. });
  209. onUnmounted(() => {
  210. window.removeEventListener("message", changePlay);
  211. });
  212. return () => (
  213. <>
  214. <div class={[styles.headerTop]}>
  215. {headTopData.showBack && (
  216. <div class={styles.back} onClick={handleBack}>
  217. <img src={iconBack} />
  218. </div>
  219. )}
  220. <Title text={state.examSongName} rightView={false} />
  221. <div
  222. class={styles.headRight}
  223. >
  224. <div
  225. style={{ display: toggleBtn.value.display ? "" : "none" }}
  226. class={[styles.btn, toggleBtn.value.disabled && styles.disabled]}
  227. onClick={() => {
  228. handleRessetState();
  229. headTopData.modeType = "init";
  230. }}
  231. >
  232. <img class={styles.iconBtn} src={headImg(`modeType.svg`)} />
  233. <span>模式</span>
  234. </div>
  235. <div
  236. style={{ display: originBtn.value.display ? "" : "none" }}
  237. class={[styles.btn, originBtn.value.disabled && styles.disabled]}
  238. id="tips-step-6"
  239. onClick={() => {
  240. state.playSource = state.playSource === "music" ? "background" : "music";
  241. }}
  242. >
  243. <img
  244. style={{ display: state.playSource === "music" ? "" : "none" }}
  245. class={styles.iconBtn}
  246. src={headImg(`music.svg`)}
  247. />
  248. <img
  249. style={{ display: state.playSource === "music" ? "none" : "" }}
  250. class={styles.iconBtn}
  251. src={headImg(`background.svg`)}
  252. />
  253. <span>{state.playSource === "music" ? "原声" : "伴奏"}</span>
  254. </div>
  255. <div
  256. style={{ display: selectBtn.value.display ? "" : "none" }}
  257. class={[styles.btn, selectBtn.value.disabled && styles.disabled]}
  258. id="tips-step-4"
  259. onClick={() => handleChangeSection()}
  260. >
  261. <img
  262. style={{ display: state.section.length === 0 ? "" : "none" }}
  263. class={styles.iconBtn}
  264. src={headImg(`section0.svg`)}
  265. />
  266. <img
  267. style={{ display: state.section.length === 1 ? "" : "none" }}
  268. class={styles.iconBtn}
  269. src={headImg(`section1.svg`)}
  270. />
  271. <img
  272. style={{ display: state.section.length === 2 ? "" : "none" }}
  273. class={styles.iconBtn}
  274. src={headImg(`section2.svg`)}
  275. />
  276. <span>选段</span>
  277. </div>
  278. <div
  279. style={{ display: fingeringBtn.value.display ? "" : "none" }}
  280. class={[styles.btn, fingeringBtn.value.disabled && styles.disabled]}
  281. onClick={() => {
  282. state.setting.displayFingering = !state.setting.displayFingering;
  283. }}
  284. >
  285. <img
  286. style={{ display: state.setting.displayFingering ? "" : "none" }}
  287. class={styles.iconBtn}
  288. src={headImg(`icon_evaluatingOn.svg`)}
  289. />
  290. <img
  291. style={{ display: state.setting.displayFingering ? "none" : "" }}
  292. class={styles.iconBtn}
  293. src={headImg(`icon_evaluatingOff.svg`)}
  294. />
  295. <span>指法</span>
  296. </div>
  297. <Popover
  298. trigger="manual"
  299. v-model:show={headData.speedShow}
  300. placement="bottom"
  301. overlay={false}
  302. >
  303. {{
  304. reference: () => (
  305. <div
  306. id="tips-step-8"
  307. style={{ display: speedBtn.value.display ? "" : "none" }}
  308. class={[styles.btn, speedBtn.value.disabled && styles.disabled]}
  309. onClick={(e: Event) => {
  310. e.stopPropagation();
  311. headData.speedShow = !headData.speedShow;
  312. }}
  313. >
  314. <Badge class={styles.badge} content={state.speed}>
  315. <img class={styles.iconBtn} src={headImg("icon_speed.svg")} />
  316. </Badge>
  317. <span>速度</span>
  318. </div>
  319. ),
  320. default: () => <Speed />,
  321. }}
  322. </Popover>
  323. <Popover
  324. trigger="manual"
  325. v-model:show={headData.musicTypeShow}
  326. placement="bottom-end"
  327. overlay={false}
  328. >
  329. {{
  330. reference: () => (
  331. <div
  332. style={{ display: converBtn.value.display ? "" : "none" }}
  333. class={[styles.btn, converBtn.value.disabled && styles.disabled]}
  334. onClick={(e: Event) => {
  335. e.stopPropagation();
  336. headData.musicTypeShow = !headData.musicTypeShow;
  337. }}
  338. >
  339. <img class={styles.iconBtn} src={headImg("icon_zhuanpu.svg")} />
  340. <span>{state.musicRenderType === "staff" ? "转简谱" : "转五线谱"}</span>
  341. </div>
  342. ),
  343. default: () => <MusicType />,
  344. }}
  345. </Popover>
  346. <div
  347. style={{ display: settingBtn.value.display ? "" : "none" }}
  348. class={[styles.btn, settingBtn.value.disabled && styles.disabled]}
  349. onClick={() => (headTopData.settingMode = true)}
  350. >
  351. <img class={styles.iconBtn} src={headImg("icon_menu.svg")} />
  352. <span>设置</span>
  353. </div>
  354. </div>
  355. </div>
  356. {/* 播放按钮 */}
  357. <div
  358. style={{ display: playBtn.value.display ? "" : "none" }}
  359. class={[styles.btn, styles.playBtn, playBtn.value.disabled && styles.disabled]}
  360. id="tips-step-5"
  361. onClick={() => togglePlay()}
  362. >
  363. <div class={styles.btnWrap}>
  364. <img
  365. style={{ display: state.playState === "play" ? "none" : "" }}
  366. class={styles.iconBtn}
  367. src={headImg("icon_play.svg")}
  368. />
  369. <img
  370. style={{ display: state.playState === "play" ? "" : "none" }}
  371. class={styles.iconBtn}
  372. src={headImg("icon_pause.svg")}
  373. />
  374. <Circle
  375. style={{ opacity: state.playState === "play" ? 1 : 0 }}
  376. class={styles.progress}
  377. stroke-width={80}
  378. currentRate={state.playProgress}
  379. rate={100}
  380. color="#FFC830"
  381. />
  382. </div>
  383. </div>
  384. {/* 重播按钮 */}
  385. <div
  386. style={{ display: resetBtn.value.display ? "" : "none" }}
  387. class={[styles.btn, styles.resetBtn, resetBtn.value.disabled && styles.disabled]}
  388. id="tips-step-7"
  389. onClick={() => handleResetPlay()}
  390. >
  391. <img class={styles.iconBtn} src={headImg("icon_resetbtn.svg")} />
  392. </div>
  393. <Popup
  394. v-model:show={headTopData.settingMode}
  395. class="popup-custom van-scale center-closeBtn"
  396. transition="van-scale"
  397. teleport="body"
  398. closeable
  399. >
  400. <Settting />
  401. </Popup>
  402. {/* 模式切换 */}
  403. <ModeTypeMode />
  404. </>
  405. );
  406. },
  407. });