index.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. import { defineComponent, Directive, Ref, ref, Transition, Teleport, nextTick, computed, onMounted } from 'vue'
  2. import { Button, Cell, CellGroup, Dialog, Divider, Popover, Slider, Switch } from 'vant'
  3. import ButtonIcon from './icon'
  4. import runtime, * as RuntimeUtils from '/src/pages/detail/runtime'
  5. import Speed from '/src/pages/detail/speed'
  6. import detailState from '/src/pages/detail/state'
  7. import SettingState from '/src/pages/detail/setting-state'
  8. import appState from '/src/state'
  9. import FloatWraper from './float-wraper'
  10. import Evaluating, { evaluatStopPlay } from './evaluating'
  11. import iconTitle from '../popups/evaluating/icons/title.svg'
  12. import iconCancel from '../popups/evaluating/icons/cancel.svg'
  13. import iconConfirm from '../popups/evaluating/icons/confirm.svg'
  14. import { useClientType, useMenu, useOriginSearch, useReload } from '../uses'
  15. import { permissionPopup } from '../popups/permission/permission'
  16. import { open as openMusicList } from '../music-list'
  17. import { postMessage } from '/src/helpers/native-message'
  18. import Popups from '../popups'
  19. import Setting from '../popups/setting'
  20. import evastyles from '../popups/evaluating/index.module.less'
  21. import ModelWraper from './model-wraper'
  22. import Follow from '../popups/follow'
  23. import { switchProps } from '../popups/setting/evaluat'
  24. import iconBack from './icons/icon-back.png'
  25. import iconFollowEndBtn from '../popups/follow/icons/icon-followEndBtn.png'
  26. import iconEvaluatingEnd from './icons/icon-evaluatingEnd.png'
  27. import iconCameraOff from './icons/icon-camera-off.png'
  28. import iconCameraOn from './icons/icon-camera-on.png'
  29. import iconToggle from './icons/icon_toggle.png'
  30. import store from 'store'
  31. import styles from './index.module.less'
  32. import { sendBackRecordTotalTime } from '../App'
  33. import { unitTestData } from '../unitTest'
  34. import { toggleMusicSheet } from '../plugins/toggleMusicSheet'
  35. import classNames from 'classnames'
  36. import Metronome, { metronomeData } from '/src/helpers/metronome'
  37. import { getAllNodes } from '/src/pages/detail/helpers'
  38. export const confirmShow: Ref<boolean> = ref(false)
  39. /**评测开始按钮状态 */
  40. export const startButtonShow = ref(true)
  41. export const evaluatingRef: Ref<any> = ref({})
  42. export const settingPopup: Ref<any> = ref(null)
  43. export const suggestPopup: Ref<any> = ref(null)
  44. export const followRef = ref<any>(null)
  45. let openSuggestPopupFn = () => {}
  46. export const openSuggestPopup = () => {
  47. openSuggestPopupFn()
  48. }
  49. /**
  50. * 前置验证是否在APP中并且已经付费
  51. * @param cb 回调函数 {status} 验证状态
  52. * @returns
  53. */
  54. const beforeCheck = (cb: (status: boolean) => void) => {
  55. const search = useOriginSearch()
  56. const setting = (search.setting || {}) as any
  57. const chargeType = detailState.activeDetail?.paymentType
  58. const orderStatus = detailState.activeDetail?.orderStatus
  59. const play = detailState.activeDetail?.play
  60. const membershipDays = appState.user?.membershipDays || 0
  61. if (useClientType() === 'web' || play || setting.feeType === 'FREE') {
  62. return cb(true)
  63. }
  64. if (
  65. chargeType?.includes('VIP') &&
  66. chargeType?.includes('CHARGE') &&
  67. !(membershipDays > 0) &&
  68. orderStatus !== 'PAID'
  69. ) {
  70. permissionPopup.active = 'memberAndDemand'
  71. permissionPopup.show = true
  72. return cb(false)
  73. }
  74. if (chargeType === 'VIP' && !(membershipDays > 0)) {
  75. permissionPopup.active = 'member'
  76. permissionPopup.show = true
  77. return cb(false)
  78. }
  79. if (chargeType === 'CHARGE' && orderStatus !== 'PAID') {
  80. permissionPopup.active = 'demand'
  81. permissionPopup.show = true
  82. return cb(false)
  83. }
  84. cb(true)
  85. }
  86. const back: () => void = () => {
  87. sendBackRecordTotalTime()
  88. postMessage({
  89. api: 'back',
  90. })
  91. }
  92. export type IModelType = 'practice' | 'evaluation' | 'follow' | 'init'
  93. export const modelType = ref<IModelType>('init')
  94. export const onChangeModelType = (type: IModelType) => {
  95. if (type === modelType.value) return
  96. if (type === 'evaluation') {
  97. RuntimeUtils.changeSpeed(detailState.activeDetail?.originalSpeed, false)
  98. // 评测模式
  99. runtime.evaluatingStatus = true
  100. } else {
  101. const speeds = store.get('speeds') || {}
  102. const search = useOriginSearch()
  103. const speed = speeds[search.id as any]
  104. // 还原速度
  105. if (speed) {
  106. RuntimeUtils.changeSpeed(speeds[search.id as any])
  107. }
  108. }
  109. nextTick(() => {
  110. modelType.value = type
  111. })
  112. }
  113. export default defineComponent({
  114. name: 'Colexiu-Buttons',
  115. props: {
  116. onSetMusicScoreType: {
  117. type: Object,
  118. default: (n: any) => {},
  119. },
  120. },
  121. emits: ['setMusicScoreType'],
  122. setup(props, { emit }) {
  123. try {
  124. detailState.times = getAllNodes(runtime.osmd)
  125. // console.log('state.times', detailState.times)
  126. } catch (error) {
  127. console.log(error)
  128. }
  129. const search = useOriginSearch()
  130. const speedRef = ref()
  131. const [show] = useMenu()
  132. const camera = ref(false)
  133. //根据路由传参设置模式
  134. const useRouteSetModelType = () => {
  135. const modelType: IModelType = search.modelType as IModelType
  136. if (modelType && modelType != 'evaluation') {
  137. onChangeModelType(modelType)
  138. }
  139. }
  140. onMounted(() => {
  141. useRouteSetModelType()
  142. })
  143. // 固定调
  144. const musicTypeShow = ref(false)
  145. const musicAction = ref('')
  146. const onSelect = (action: any) => {
  147. musicAction.value = action.text
  148. confirmShow.value = true
  149. }
  150. const hanldeSelect = () => {
  151. if (musicAction.value === '五线谱') {
  152. // if (SettingState.sett.type == 'staff') return
  153. SettingState.sett.type = 'staff'
  154. } else if (musicAction.value === '简谱') {
  155. // if (SettingState.sett.type === 'jianpu' && !SettingState.sett.keySignature) return
  156. SettingState.sett.type = 'jianpu'
  157. SettingState.sett.keySignature = false
  158. } else if (musicAction.value === '固定调') {
  159. // if (SettingState.sett.type === 'jianpu' && SettingState.sett.keySignature) return
  160. SettingState.sett.type = 'jianpu'
  161. SettingState.sett.keySignature = true
  162. }
  163. sessionStorage.setItem('notation', SettingState.sett.type)
  164. }
  165. const musicType = (type: string) => {
  166. if (type === 'staff') {
  167. return SettingState.sett.type === type
  168. } else if (type === 'shoudiao') {
  169. return SettingState.sett.type === 'jianpu' && !SettingState.sett.keySignature
  170. } else if (type === 'guding') {
  171. return SettingState.sett.type === 'jianpu' && SettingState.sett.keySignature
  172. }
  173. }
  174. return () => {
  175. const changeModeIsDisabled =
  176. (detailState.activeDetail?.isAppPlay
  177. ? detailState.activeDetail?.midiUrl === ''
  178. : runtime.isFirstPlay || runtime.audiosInstance?.length == 1) ||
  179. runtime.evaluatingStatus ||
  180. (detailState.activeDetail?.isAppPlay && detailState.midiPlayIniting)
  181. return (
  182. <div
  183. onClick={(e: Event) => e.stopPropagation()}
  184. class={[styles.container, show.value ? '' : styles.outUp]}
  185. style={search.headerHeight ? { height: '1rem', paddingTop: '0.25rem' } : ''}
  186. >
  187. <div class={styles.leftButton}>
  188. {search?.modelType && !search.unitId ? null : <img class={styles.backbtn} src={iconBack} onClick={back} />}
  189. <div class={styles.titleWrap}>
  190. <div class={styles.title}>{detailState.activeDetail?.musicSheetName}</div>
  191. {search.albumName && <div class={styles.album}>{search.albumName}</div>}
  192. </div>
  193. </div>
  194. <div class={styles.centerButton}>
  195. <Transition name="finish">
  196. {!startButtonShow.value && (
  197. <Button
  198. class={[styles.button, styles.finish]}
  199. onClick={() => {
  200. evaluatingRef.value?.playerStop?.()
  201. }}
  202. >
  203. <img style={{ width: '100%', display: 'block' }} src={iconEvaluatingEnd} />
  204. </Button>
  205. )}
  206. </Transition>
  207. <Transition name="finish">
  208. {followRef?.value?.data.start && (
  209. <Button
  210. class={[styles.button, styles.finish, styles.followEndBtn]}
  211. onClick={() => {
  212. followRef.value?.handleEnd?.()
  213. }}
  214. >
  215. <img style={{ width: '100%', display: 'block' }} src={iconFollowEndBtn} />
  216. </Button>
  217. )}
  218. </Transition>
  219. </div>
  220. <div class={[styles.moreButton]} style={{ opacity: detailState.initRendered ? 1 : 0 }}>
  221. <>
  222. <Button
  223. class={classNames(styles.button, styles.hasText)}
  224. onClick={() => {
  225. // 切换光标模式
  226. const mode = metronomeData.cursorMode === 3 ? 1 : metronomeData.cursorMode + 1
  227. metronomeData.cursorMode = mode
  228. }}
  229. >
  230. <ButtonIcon key="modelType" name={metronomeData.cursorMode === 1 ? 'cursor-icon-1' : metronomeData.cursorMode === 2 ? 'cursor-icon-2' : metronomeData.cursorMode === 3 ? 'cursor-icon-3' : ''} />
  231. <span>{metronomeData.cursorMode === 1 ? '音符指针' : metronomeData.cursorMode === 2 ? '节拍指针' : metronomeData.cursorMode === 3 ? '关闭指针' : ''}</span>
  232. {metronomeData.cursorTips && <div class={classNames(styles['botton-tips'])}>{metronomeData.cursorTips}</div>}
  233. </Button>
  234. </>
  235. {!search?.modelType && modelType.value !== 'init' && !detailState.frozenMode && (
  236. <Button
  237. data-step="m0"
  238. class={[styles.button, styles.hasText]}
  239. disabled={(runtime.evaluatingStatus && !startButtonShow.value) || followRef.value?.data.start}
  240. onClick={() => {
  241. // 不是课后训练选段和单元测验选段,切换模式去除选段
  242. if (!unitTestData.isSelectMeasureMode && detailState.sectionStatus) {
  243. RuntimeUtils.clearSectionStatus()
  244. }
  245. if (modelType.value === 'practice') {
  246. // 当前为练习模式,需要停止播放
  247. RuntimeUtils.resetPlayStatus()
  248. RuntimeUtils.setCurrentTime(0)
  249. }
  250. if (modelType.value === 'evaluation') {
  251. runtime.evaluatingStatus = false
  252. evaluatStopPlay()
  253. }
  254. modelType.value = 'init'
  255. }}
  256. >
  257. <ButtonIcon
  258. key="modelType"
  259. name={
  260. ['init', 'practice'].includes(modelType.value)
  261. ? 'modelType'
  262. : ['follow'].includes(modelType.value)
  263. ? 'modelType1'
  264. : 'modelType2'
  265. }
  266. />
  267. <span>模式</span>
  268. </Button>
  269. )}
  270. {detailState.initRendered && !search.lessonTrainingId && !search.questionId && detailState.activeDetail?.musicSheetType == 'CONCERT' && (
  271. <Button
  272. class={[styles.button, styles.hasText]}
  273. onClick={() => {
  274. toggleMusicSheet.toggle(true)
  275. }}
  276. disabled={
  277. (runtime.evaluatingStatus && !startButtonShow.value) ||
  278. runtime.playState === 'play' ||
  279. followRef.value?.data.start
  280. }
  281. >
  282. <img src={iconToggle} />
  283. <span>声轨</span>
  284. </Button>
  285. )}
  286. {modelType.value === 'evaluation' && (
  287. <>
  288. <Popover
  289. v-model:show={camera.value}
  290. overlay={false}
  291. placement="bottom-end"
  292. class="cameraPopover"
  293. show-arrow={false}
  294. vSlots={{
  295. reference: () => (
  296. <div
  297. onClick={(e: Event) => {
  298. if (!startButtonShow.value) e.stopPropagation()
  299. }}
  300. >
  301. <Button class={[styles.button, styles.hasText]} disabled={!startButtonShow.value}>
  302. <img src={SettingState.sett.camera ? iconCameraOn : iconCameraOff} />
  303. <span>摄像头</span>
  304. </Button>
  305. </div>
  306. ),
  307. }}
  308. >
  309. <CellGroup border={false}>
  310. {
  311. <Cell center title="摄像头">
  312. <div style="display:flex;justify-content: flex-end;">
  313. <Switch v-model={SettingState.sett.camera} {...switchProps}>
  314. off
  315. </Switch>
  316. </div>
  317. </Cell>
  318. }
  319. {SettingState.sett.camera && (
  320. <Cell class="cameraOpacity" center title="透明度">
  321. <Slider
  322. style={{ width: '90%' }}
  323. min={0}
  324. max={100}
  325. v-model:modelValue={SettingState.sett.opacity}
  326. v-slots={{
  327. button: () => <div class={styles.slider}>{SettingState.sett.opacity}</div>,
  328. }}
  329. ></Slider>
  330. </Cell>
  331. )}
  332. </CellGroup>
  333. </Popover>
  334. <Evaluating ref={evaluatingRef} />
  335. </>
  336. )}
  337. {modelType.value === 'practice' && (
  338. <>
  339. <Button
  340. data-step="m1"
  341. class={[styles.button, styles.hasText]}
  342. onClick={() => RuntimeUtils.changeMode(runtime.mode === 'background' ? 'music' : 'background')}
  343. disabled={changeModeIsDisabled}
  344. >
  345. <ButtonIcon key="music" name={runtime.mode === 'music' ? 'music' : 'accompaniment'} />
  346. <span>{runtime.mode === 'background' ? '伴奏' : '原声'}</span>
  347. </Button>
  348. {/* 如果为单元测试和课后训练 */}
  349. {unitTestData.isSelectMeasureMode ? null : (
  350. <Button
  351. data-step="m2"
  352. class={[styles.button, styles.hasText]}
  353. onClick={RuntimeUtils.sectionChange}
  354. disabled={runtime.evaluatingStatus || runtime.playState === 'play'}
  355. >
  356. <ButtonIcon
  357. key="section"
  358. name={
  359. 'section' +
  360. (detailState.section.length && detailState.section.length <= 2
  361. ? detailState.section.length
  362. : '')
  363. }
  364. />
  365. <span>选段</span>
  366. </Button>
  367. )}
  368. <Button
  369. data-step="m3"
  370. class={[styles.button, styles.hasText]}
  371. disabled={runtime.playState === 'play'}
  372. onClick={() => {
  373. SettingState.sett.fingering = !SettingState.sett.fingering
  374. RuntimeUtils.event.emit('settingFingeringChange')
  375. }}
  376. >
  377. <ButtonIcon key="music" name={SettingState.sett.fingering ? 'fingeringOn' : 'fingeringOff'} />
  378. <span>指法</span>
  379. </Button>
  380. </>
  381. )}
  382. {['practice', 'evaluation'].includes(modelType.value) && !search.lessonTrainingId && (
  383. <Popover
  384. trigger="manual"
  385. overlay={false}
  386. placement="bottom"
  387. class={styles.popover}
  388. show={show.value && runtime.speedShow && !(runtime.evaluatingStatus || runtime.playState === 'play')}
  389. // @ts-ignore
  390. onUpdate:show={(show: boolean) => (runtime.speedShow = show)}
  391. vSlots={{
  392. reference: () => (
  393. <Button
  394. data-step="m4"
  395. class={[styles.button, styles.hasText, styles.speedButton]}
  396. disabled={runtime.evaluatingStatus || runtime.playState === 'play'}
  397. onClick={() => {
  398. speedRef.value?.refUpdateSpeed(runtime.speed)
  399. runtime.speedShow = !runtime.speedShow
  400. }}
  401. >
  402. <ButtonIcon name="speed" />
  403. <span>速度</span>
  404. <span class={styles.label}>{runtime.speed}</span>
  405. </Button>
  406. ),
  407. }}
  408. >
  409. <Speed
  410. ref={speedRef}
  411. updateSpeed={(speed: number) => (runtime.speed = speed)}
  412. changed={RuntimeUtils.changeSpeed}
  413. mode={runtime.mode}
  414. changeMode={RuntimeUtils.changeMode}
  415. lib={{ speed: runtime.speed }}
  416. class={styles.speed}
  417. />
  418. </Popover>
  419. )}
  420. {detailState.activeDetail?.notation ? (
  421. <Popover
  422. class={styles.toggleMusicType}
  423. placement="bottom-end"
  424. show={musicTypeShow.value}
  425. // @ts-ignore
  426. onUpdate:show={(val: boolean) => {
  427. if (
  428. runtime.playState === 'play' ||
  429. (runtime.evaluatingStatus && !startButtonShow.value) ||
  430. followRef.value?.data.start
  431. ) {
  432. } else {
  433. musicTypeShow.value = val
  434. }
  435. }}
  436. >
  437. {{
  438. reference: () => (
  439. <Button
  440. disabled={
  441. runtime.playState === 'play' ||
  442. (runtime.evaluatingStatus && !startButtonShow.value) ||
  443. followRef.value?.data.start
  444. }
  445. class={[styles.button, styles.hasText, styles.speedButton]}
  446. >
  447. <ButtonIcon name="icon-zhuanpu" />
  448. <span>{musicType('staff') ? '转简谱' : '转五线谱'}</span>
  449. </Button>
  450. ),
  451. default: () => (
  452. <>
  453. <div role="menuitem" class="van-popover__action" onClick={() => onSelect({ text: '五线谱' })}>
  454. <ButtonIcon key="type" name={musicType('staff') ? 'icon-staff-active' : 'icon-staff'} />
  455. <div class={['action-text', musicType('staff') && 'action-active']}>五线谱</div>
  456. </div>
  457. <div role="menuitem" class="van-popover__action" onClick={() => onSelect({ text: '简谱' })}>
  458. <ButtonIcon key="type" name={musicType('shoudiao') ? 'shuodiao-active' : 'shuodiao'} />
  459. <div class={['action-text', musicType('shoudiao') && 'action-active']}>首调</div>
  460. </div>
  461. <div role="menuitem" class="van-popover__action" onClick={() => onSelect({ text: '固定调' })}>
  462. <ButtonIcon key="type" name={musicType('guding') ? 'guding-active' : 'guding'} />
  463. <div class={['action-text', musicType('guding') && 'action-active']}>固定调</div>
  464. </div>
  465. </>
  466. ),
  467. }}
  468. </Popover>
  469. ) : null}
  470. {detailState.initRendered && (
  471. <>
  472. <Button
  473. class={[styles.button, styles.hasText]}
  474. onClick={() => {
  475. settingPopup.value?.onShow()
  476. }}
  477. disabled={
  478. (runtime.evaluatingStatus && !startButtonShow.value) ||
  479. runtime.playState === 'play' ||
  480. followRef.value?.data.start
  481. }
  482. >
  483. <ButtonIcon name="setting" />
  484. <span>设置1</span>
  485. </Button>
  486. <Popups
  487. ref={settingPopup}
  488. style={{
  489. borderRadius: '8px',
  490. }}
  491. >
  492. <Setting active={modelType.value == 'practice' ? '2' : modelType.value == 'evaluation' ? '3' : '1'} />
  493. </Popups>
  494. </>
  495. )}
  496. </div>
  497. <FloatWraper />
  498. <Dialog.Component
  499. teleport="body"
  500. class={evastyles.confirm}
  501. style={{
  502. overflow: 'initial',
  503. }}
  504. vSlots={{
  505. title: () => <img class={evastyles.iconTitle} src={iconTitle} />,
  506. footer: () => (
  507. <div class={evastyles.footer}>
  508. <img src={iconCancel} onClick={() => (confirmShow.value = false)} />
  509. <img
  510. src={iconConfirm}
  511. onClick={() => {
  512. hanldeSelect()
  513. useReload()
  514. }}
  515. />
  516. </div>
  517. ),
  518. }}
  519. v-model:show={confirmShow.value}
  520. message={'设置成功,是否立即重新加载?'}
  521. />
  522. </div>
  523. )
  524. }
  525. },
  526. })