index.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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') {
  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. })
  100. isInitPlyr.value = true
  101. })
  102. }
  103. expose({
  104. autoShow,
  105. })
  106. return () => {
  107. return (
  108. <header class={[styles.header, styles.className]}>
  109. <div class={styles.info}>
  110. <div class={styles.leftButton}>
  111. <Button onClick={back} class={styles.back}>
  112. <img style={{ width: '30px', height: '30px', display: 'block' }} src={BackIcon} alt="back" />
  113. </Button>
  114. <span class={styles.musicName}>{record?.value?.sysMusicScoreName}</span>
  115. </div>
  116. {record.value && record.value?.heardLevel ? (
  117. <Grid class={styles.center} columnNum={5} style={{ alignItems: 'center', 'flex-wrap': 'nowrap' }}>
  118. <GridItem
  119. class="van-hairline--right"
  120. vSlots={{
  121. icon: () => <span>{(heardLevel as any)[record.value?.heardLevel]}</span>,
  122. text: () => <span>难度</span>,
  123. }}
  124. />
  125. <GridItem
  126. class="van-hairline--right"
  127. vSlots={{
  128. icon: () => <span>{record.value?.score}分</span>,
  129. text: () => <span>评测分数</span>,
  130. }}
  131. />
  132. {detailState.isPercussion ? null : (
  133. <GridItem
  134. class="van-hairline--right"
  135. onClick={() => {
  136. active.value = 'pitch'
  137. emit('activeChange', 'pitch')
  138. }}
  139. vSlots={{
  140. icon: () => (
  141. <span style={{ color: 'var(--van-primary-color)' }}>{record.value?.intonation}分</span>
  142. ),
  143. text: () => <span class={['switch', { active: active.value === 'pitch' }]}>音准</span>,
  144. }}
  145. />
  146. )}
  147. <GridItem
  148. class="van-hairline--right"
  149. onClick={() => {
  150. active.value = 'rhythm'
  151. emit('activeChange', 'rhythm')
  152. }}
  153. vSlots={{
  154. icon: () => <span style={{ color: 'var(--van-primary-color)' }}>{record.value?.cadence}分</span>,
  155. text: () => <span class={['switch', { active: active.value === 'rhythm' }]}>节奏</span>,
  156. }}
  157. />
  158. {detailState.isPercussion ? null : (
  159. <GridItem
  160. onClick={() => {
  161. active.value = 'completion'
  162. emit('activeChange', 'completion')
  163. }}
  164. vSlots={{
  165. icon: () => <span style={{ color: '#4EA1FF' }}>{record.value?.integrity}分</span>,
  166. text: () => <span class={['switch', { active: active.value === 'completion' }]}>完成度</span>,
  167. }}
  168. />
  169. )}
  170. </Grid>
  171. ) : null}
  172. <Grid class={styles.btns} style={{ alignItems: 'center', 'flex-wrap': 'nowrap' }}>
  173. {record.value?.videoFilePath && browserInfo.isStudent ? (
  174. <GridItem
  175. onClick={openAudioAndVideo}
  176. vSlots={{
  177. icon: () => <img src={ReplayIcon} />,
  178. text: () => <span>回放</span>,
  179. }}
  180. />
  181. ) : // <PlayerPopup {...record.value} btnClass={'van-grid-item'} popupClass={detailStyles.popup}>
  182. // </PlayerPopup>
  183. null}
  184. <GridItem
  185. onClick={() => (visible.value = true)}
  186. vSlots={{
  187. icon: () => <img src={ExplainIcon} />,
  188. text: () => <span>释义</span>,
  189. }}
  190. />
  191. {browserInfo.isStudent ? (
  192. <GridItem
  193. onClick={again}
  194. vSlots={{
  195. icon: () => <img src={AgainIcon} />,
  196. text: () => <span>再来一遍</span>,
  197. }}
  198. />
  199. ) : null}
  200. </Grid>
  201. </div>
  202. {record.value ? (
  203. <div class={styles.demos}>
  204. {/* <div>
  205. <Note fill="#01C1B5" />
  206. <span>演奏正确</span>
  207. </div> */}
  208. {active.value === 'pitch' && (
  209. <>
  210. <div>
  211. <Note fill="#FFAB25" shadow x={-3} y={0} />
  212. <span>音高了</span>
  213. </div>
  214. <div>
  215. <Note fill="#FFAB25" shadow x={-1} y={-2} />
  216. <span>音低了</span>
  217. </div>
  218. </>
  219. )}
  220. {!state.isPercussion ? (
  221. <>
  222. {active.value === 'rhythm' && (
  223. <>
  224. <div>
  225. <Note fill="#FF4444" shadow x={0} />
  226. <span>节奏快了</span>
  227. </div>
  228. <div>
  229. <Note fill="#FF4444" shadow x={-3} y={-2} />
  230. <span>节奏慢了</span>
  231. </div>
  232. </>
  233. )}
  234. {active.value === 'completion' && (
  235. <div>
  236. <Note fill="#CC75FF" />
  237. <span>时值不足</span>
  238. </div>
  239. )}
  240. </>
  241. ) : null}
  242. {/* <div>
  243. <Note fill="#AEAEAE" />
  244. <span>未演奏</span>
  245. </div> */}
  246. </div>
  247. ) : null}
  248. <Popup
  249. teleport="body"
  250. show={visible.value}
  251. class={styles.pop}
  252. style={{ width: '60vw' }}
  253. onClickOverlay={() => (visible.value = false)}
  254. >
  255. <div class={styles.close} onClick={() => (visible.value = false)}>
  256. <img src={CloseIcon} />
  257. </div>
  258. <h2>图标释义</h2>
  259. <Grid columnNum={2} class={styles.btns} border={false}>
  260. <GridItem
  261. vSlots={{
  262. text: () => <span>绿色音符:演奏正确</span>,
  263. icon: () => <Note fill="#01C1B5" />,
  264. }}
  265. />
  266. <GridItem
  267. vSlots={{
  268. text: () => <span>红色音符:错音</span>,
  269. icon: () => <Note fill="#FF4444" />,
  270. }}
  271. />
  272. <GridItem
  273. vSlots={{
  274. text: () => <span>音符重影(红色在前):节奏过快</span>,
  275. icon: () => <Note fill="#FF4444" shadow x={0} />,
  276. }}
  277. />
  278. <GridItem
  279. vSlots={{
  280. text: () => <span>音符重影(红色在后):节奏慢了</span>,
  281. icon: () => <Note fill="#FF4444" shadow x={-3} y={-2} />,
  282. }}
  283. />
  284. <GridItem
  285. vSlots={{
  286. text: () => <span>音符重影(黄色在上):音高了</span>,
  287. icon: () => <Note fill="#FFAB25" shadow x={-3} y={0} />,
  288. }}
  289. />
  290. <GridItem
  291. vSlots={{
  292. text: () => <span>音符重影(黄色在下):音低了</span>,
  293. icon: () => <Note fill="#FFAB25" shadow x={-1} y={-2} />,
  294. }}
  295. />
  296. <GridItem
  297. vSlots={{
  298. text: () => <span>紫色音符:完整度不足</span>,
  299. icon: () => <Note fill="#CC75FF" />,
  300. }}
  301. />
  302. <GridItem
  303. vSlots={{
  304. text: () => <span>灰色音符:未演奏</span>,
  305. icon: () => <Note fill="#AEAEAE" />,
  306. }}
  307. />
  308. </Grid>
  309. </Popup>
  310. <Popup teleport="body" v-model:show={videoShow.value} class={styles.videoContent} onClose={() => {
  311. _plrl.value?.stop()
  312. }}>
  313. <div class={styles.close} onClick={() => (videoShow.value = false)}>
  314. <img src={CloseIcon} />
  315. </div>
  316. {mediaType.value === 'audio' && (
  317. <audio id="audioSrc" src={record.value?.videoFilePath} controls="false" preload="metadata" playsinline />
  318. )}
  319. {mediaType.value === 'video' && (
  320. <div class={styles.box}>
  321. <video
  322. id="videoSrc"
  323. class={styles.videoBox}
  324. src={record.value?.videoFilePath}
  325. data-poster={videobg}
  326. preload="metadata"
  327. playsinline
  328. />
  329. </div>
  330. )}
  331. </Popup>
  332. </header>
  333. )
  334. }
  335. },
  336. })