index.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. import { defineComponent, toRefs, PropType, ref, Transition, onMounted, computed, nextTick } from 'vue'
  2. import { Button, Grid, GridItem, Popup } from 'vant'
  3. import qs from 'query-string'
  4. import { MusicSheelDetail, ShaeetStatusType } from '../../colexiu/index.d'
  5. import BackIcon from '../../colexiu/buttons/icons/icon-back.png'
  6. import { heardLevel } from '/src/constant/formats'
  7. import Note from '/src/pages/report/note'
  8. import PlayerPopup from '/src/pages/report/player'
  9. import styles from './index.module.less'
  10. import state from '/src/pages/state'
  11. import detailState from '/src/pages/detail/state'
  12. import AgainIcon from '../again.svg'
  13. import ExplainIcon from '../icon-explain.png'
  14. import ReplayIcon from '../icon-replay.png'
  15. import CloseIcon from './close.png'
  16. import detailStyles from './index.module.less'
  17. import { postMessage } from '/src/helpers/native-message'
  18. import { useOriginSearch } from '../../colexiu/uses'
  19. import { browser } from '/src/helpers/utils'
  20. import videobg from './videobg.png'
  21. import 'plyr/dist/plyr.css'
  22. import Plyr from 'plyr'
  23. export const active = ref<'pitch' | 'rhythm' | 'completion'>('pitch')
  24. const visible = ref(false)
  25. export default defineComponent({
  26. name: 'ColexiuReportHeader',
  27. props: {
  28. detail: {
  29. type: Object as PropType<MusicSheelDetail | null>,
  30. },
  31. record: {
  32. type: Object,
  33. },
  34. className: {
  35. type: String,
  36. },
  37. },
  38. emits: ['activeChange'],
  39. setup(props, { emit, expose }) {
  40. const browserInfo = browser()
  41. const search = useOriginSearch()
  42. const { detail, record } = toRefs(props)
  43. const videoShow = ref(false)
  44. const isInitPlyr = ref(false)
  45. const back = () => {
  46. postMessage({
  47. api: 'back',
  48. })
  49. }
  50. const _plrl = ref()
  51. const autoShow = () => {
  52. if (localStorage.getItem('explain-view') != '1') {
  53. visible.value = true
  54. setTimeout(() => {
  55. visible.value = false
  56. localStorage.setItem('explain-view', '1')
  57. }, 5000)
  58. }
  59. }
  60. const again = () => {
  61. if (search.source == 'evaluation') {
  62. back()
  63. return
  64. }
  65. const behaviorId = sessionStorage.getItem('behaviorId') || '' + new Date().valueOf()
  66. const url = qs.stringifyUrl({
  67. url: location.origin + '/orchestra-music-score',
  68. query: {
  69. id: detail.value?.id,
  70. behaviorId,
  71. client: browserInfo.isTeacher ? 'teacher' : 'student',
  72. },
  73. })
  74. postMessage({
  75. api: 'openAccompanyWebView',
  76. content: {
  77. url,
  78. orientation: 0,
  79. isHideTitle: true,
  80. statusBarTextColor: false,
  81. isOpenLight: true,
  82. },
  83. })
  84. }
  85. const mediaType = computed(() => {
  86. const subfix = (record.value?.videoFilePath || '').split('.').pop()
  87. if (subfix === 'wav' || subfix === 'mp3'|| subfix === 'm4a') {
  88. return 'audio'
  89. }
  90. return 'video'
  91. })
  92. const openAudioAndVideo = () => {
  93. videoShow.value = true
  94. if (isInitPlyr.value) return
  95. nextTick(() => {
  96. const id = mediaType.value === 'audio' ? '#audioSrc' : '#videoSrc'
  97. _plrl.value = new Plyr(id, {
  98. controls: ['play-large', 'play', 'progress'],
  99. fullscreen: { enabled: false },
  100. })
  101. isInitPlyr.value = true
  102. })
  103. }
  104. expose({
  105. autoShow,
  106. })
  107. return () => {
  108. return (
  109. <header class={[styles.header, styles.className]}>
  110. <div class={styles.info}>
  111. <div class={styles.leftButton}>
  112. <Button onClick={back} class={styles.back}>
  113. <img style={{ width: '30px', height: '30px', display: 'block' }} src={BackIcon} alt="back" />
  114. </Button>
  115. <span class={styles.musicName}>{record?.value?.sysMusicScoreName}</span>
  116. </div>
  117. {record.value && record.value?.heardLevel ? (
  118. <Grid class={styles.center} columnNum={5} style={{ alignItems: 'center', 'flex-wrap': 'nowrap' }}>
  119. <GridItem
  120. class="van-hairline--right"
  121. vSlots={{
  122. icon: () => <span>{(heardLevel as any)[record.value?.heardLevel]}</span>,
  123. text: () => <span>难度</span>,
  124. }}
  125. />
  126. <GridItem
  127. class="van-hairline--right"
  128. vSlots={{
  129. icon: () => <span>{record.value?.score}分</span>,
  130. text: () => <span>评测分数</span>,
  131. }}
  132. />
  133. {detailState.isPercussion ? null : (
  134. <GridItem
  135. class="van-hairline--right"
  136. onClick={() => {
  137. active.value = 'pitch'
  138. emit('activeChange', 'pitch')
  139. }}
  140. vSlots={{
  141. icon: () => (
  142. <span style={{ color: 'var(--van-primary-color)' }}>{record.value?.intonation}分</span>
  143. ),
  144. text: () => <span class={['switch', { active: active.value === 'pitch' }]}>音准</span>,
  145. }}
  146. />
  147. )}
  148. <GridItem
  149. class="van-hairline--right"
  150. onClick={() => {
  151. active.value = 'rhythm'
  152. emit('activeChange', 'rhythm')
  153. }}
  154. vSlots={{
  155. icon: () => <span style={{ color: 'var(--van-primary-color)' }}>{record.value?.cadence}分</span>,
  156. text: () => <span class={['switch', { active: active.value === 'rhythm' }]}>节奏</span>,
  157. }}
  158. />
  159. {detailState.isPercussion ? null : (
  160. <GridItem
  161. onClick={() => {
  162. active.value = 'completion'
  163. emit('activeChange', 'completion')
  164. }}
  165. vSlots={{
  166. icon: () => <span style={{ color: '#4EA1FF' }}>{record.value?.integrity}分</span>,
  167. text: () => <span class={['switch', { active: active.value === 'completion' }]}>完成度</span>,
  168. }}
  169. />
  170. )}
  171. </Grid>
  172. ) : null}
  173. <Grid class={styles.btns} style={{ alignItems: 'center', 'flex-wrap': 'nowrap' }}>
  174. {record.value?.videoFilePath ? (
  175. <GridItem
  176. onClick={openAudioAndVideo}
  177. vSlots={{
  178. icon: () => <img src={ReplayIcon} />,
  179. text: () => <span>回放</span>,
  180. }}
  181. />
  182. ) : null}
  183. <GridItem
  184. onClick={() => (visible.value = true)}
  185. vSlots={{
  186. icon: () => <img src={ExplainIcon} />,
  187. text: () => <span>释义</span>,
  188. }}
  189. />
  190. {browserInfo.isStudent ? (
  191. <GridItem
  192. onClick={again}
  193. vSlots={{
  194. icon: () => <img src={AgainIcon} />,
  195. text: () => <span>再来一遍</span>,
  196. }}
  197. />
  198. ) : null}
  199. </Grid>
  200. </div>
  201. {record.value ? (
  202. <div class={styles.demos}>
  203. {/* <div>
  204. <Note fill="#01C1B5" />
  205. <span>演奏正确</span>
  206. </div> */}
  207. {active.value === 'pitch' && (
  208. <>
  209. <div>
  210. <Note fill="#FFAB25" shadow x={-3} y={0} />
  211. <span>音高了</span>
  212. </div>
  213. <div>
  214. <Note fill="#FFAB25" shadow x={-1} y={-2} />
  215. <span>音低了</span>
  216. </div>
  217. </>
  218. )}
  219. {!state.isPercussion ? (
  220. <>
  221. {active.value === 'rhythm' && (
  222. <>
  223. <div>
  224. <Note fill="#FF4444" shadow x={0} />
  225. <span>节奏快了</span>
  226. </div>
  227. <div>
  228. <Note fill="#FF4444" shadow x={-3} y={-2} />
  229. <span>节奏慢了</span>
  230. </div>
  231. </>
  232. )}
  233. {active.value === 'completion' && (
  234. <div>
  235. <Note fill="#CC75FF" />
  236. <span>时值不足</span>
  237. </div>
  238. )}
  239. </>
  240. ) : null}
  241. {/* <div>
  242. <Note fill="#AEAEAE" />
  243. <span>未演奏</span>
  244. </div> */}
  245. </div>
  246. ) : null}
  247. <Popup
  248. teleport="body"
  249. show={visible.value}
  250. class={styles.pop}
  251. style={{ width: '60vw' }}
  252. onClickOverlay={() => (visible.value = false)}
  253. >
  254. <div class={styles.close} onClick={() => (visible.value = false)}>
  255. <img src={CloseIcon} />
  256. </div>
  257. <h2>图标释义</h2>
  258. <Grid columnNum={2} class={styles.btns} border={false}>
  259. <GridItem
  260. vSlots={{
  261. text: () => <span>绿色音符:演奏正确</span>,
  262. icon: () => <Note fill="#01C1B5" />,
  263. }}
  264. />
  265. <GridItem
  266. vSlots={{
  267. text: () => <span>红色音符:错音</span>,
  268. icon: () => <Note fill="#FF4444" />,
  269. }}
  270. />
  271. <GridItem
  272. vSlots={{
  273. text: () => <span>音符重影(红色在前):节奏过快</span>,
  274. icon: () => <Note fill="#FF4444" shadow x={0} />,
  275. }}
  276. />
  277. <GridItem
  278. vSlots={{
  279. text: () => <span>音符重影(红色在后):节奏慢了</span>,
  280. icon: () => <Note fill="#FF4444" shadow x={-3} y={-2} />,
  281. }}
  282. />
  283. <GridItem
  284. vSlots={{
  285. text: () => <span>音符重影(黄色在上):音高了</span>,
  286. icon: () => <Note fill="#FFAB25" shadow x={-3} y={0} />,
  287. }}
  288. />
  289. <GridItem
  290. vSlots={{
  291. text: () => <span>音符重影(黄色在下):音低了</span>,
  292. icon: () => <Note fill="#FFAB25" shadow x={-1} y={-2} />,
  293. }}
  294. />
  295. <GridItem
  296. vSlots={{
  297. text: () => <span>紫色音符:完整度不足</span>,
  298. icon: () => <Note fill="#CC75FF" />,
  299. }}
  300. />
  301. <GridItem
  302. vSlots={{
  303. text: () => <span>灰色音符:未演奏</span>,
  304. icon: () => <Note fill="#AEAEAE" />,
  305. }}
  306. />
  307. </Grid>
  308. </Popup>
  309. <Popup
  310. teleport="body"
  311. v-model:show={videoShow.value}
  312. class={styles.videoContent}
  313. onClose={() => {
  314. _plrl.value?.pause()
  315. }}
  316. >
  317. <div class={styles.close} onClick={() => (videoShow.value = false)}>
  318. <img src={CloseIcon} />
  319. </div>
  320. {mediaType.value === 'audio' && (
  321. <audio id="audioSrc" src={record.value?.videoFilePath} controls="false" preload="metadata" playsinline />
  322. )}
  323. {mediaType.value === 'video' && (
  324. <div class={styles.box}>
  325. <video
  326. id="videoSrc"
  327. class={styles.videoBox}
  328. src={record.value?.videoFilePath}
  329. data-poster={videobg}
  330. preload="metadata"
  331. playsinline
  332. />
  333. </div>
  334. )}
  335. </Popup>
  336. </header>
  337. )
  338. }
  339. },
  340. })