index.tsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. import {
  2. defineComponent,
  3. ref,
  4. reactive,
  5. onMounted,
  6. computed,
  7. watch
  8. } from 'vue';
  9. import { useRoute } from 'vue-router';
  10. import request from '@/helpers/request';
  11. import MEmpty from '@/components/m-empty';
  12. import styles from './index.module.less';
  13. import musicBg from '../../image/music_bg.png';
  14. import pBg from '../../image/plh.png';
  15. import titleIcon1 from '../../image/title_icon1.png';
  16. import titleIcon2 from '../../image/title_icon2.png';
  17. import playIcon from '../../image/music_play_icon.png';
  18. import pauseIcon from '../../image/music_pause_icon.png';
  19. import emptyIcon from '../../image/ins-empty-icon.png';
  20. import songIcon from '../../image/song_icon.png';
  21. import { NoticeBar } from 'vant';
  22. import PlayItem from '../play-item';
  23. import PlayLoading from '../play-loading';
  24. export default defineComponent({
  25. name: 'InstrumentInfo',
  26. props: {
  27. id: {
  28. type: String,
  29. default: ''
  30. },
  31. type: {
  32. type: String,
  33. default: ''
  34. },
  35. show: {
  36. type: Boolean,
  37. default: false
  38. }
  39. },
  40. emits: ['close', 'select'],
  41. setup(props, { emit }) {
  42. const route = useRoute();
  43. const forms = reactive({
  44. detailId: route.query.detailId,
  45. loading: false,
  46. dataInfo: {} as any,
  47. musicList: [] as any,
  48. title: ' ',
  49. playState: 'pause' as 'play' | 'pause',
  50. showPlayer: false,
  51. listActive: null as any
  52. });
  53. /** 选中的item */
  54. const activeItem = computed(() => {
  55. return forms.musicList[forms.listActive] || {};
  56. });
  57. const getDetail = async () => {
  58. forms.loading = true;
  59. try {
  60. const { data } = await request.get(
  61. '/edu-app/knowledgeWiki/detail/' + props.id
  62. );
  63. data.intros = data.intros.replace(
  64. /<video/gi,
  65. '<video class="video-music" style="width: 100% !important;" controlslist="nodownload" poster="https://oss.dayaedu.com/ktqy/1701759849244.png"'
  66. );
  67. forms.dataInfo = data || {};
  68. forms.musicList = data.knowledgeWikiResources.map((item: any) => {
  69. return {
  70. id: item.id,
  71. name: item.name,
  72. url: item.url
  73. };
  74. });
  75. } catch {}
  76. forms.loading = false;
  77. };
  78. /** 播放曲目 */
  79. const handlePlay = (item: any) => {
  80. const index = forms.musicList.findIndex(
  81. (_item: any) => _item.id === item.id
  82. );
  83. if (index > -1) {
  84. if (forms.listActive === index) {
  85. forms.playState = forms.playState === 'play' ? 'pause' : 'play';
  86. } else {
  87. forms.playState = 'play';
  88. }
  89. forms.showPlayer = true;
  90. forms.listActive = index;
  91. }
  92. };
  93. /** 音频控制 */
  94. const handleChangeAudio = (
  95. type: 'play' | 'pause' | 'pre' | 'next' | 'favitor'
  96. ) => {
  97. if (type === 'play') {
  98. forms.playState = 'play';
  99. } else if (type === 'pause') {
  100. forms.playState = 'pause';
  101. } else if (type === 'pre') {
  102. if (forms.musicList[forms.listActive - 1]) {
  103. handlePlay(forms.musicList[forms.listActive - 1]);
  104. }
  105. } else if (type === 'next') {
  106. if (forms.musicList[forms.listActive + 1]) {
  107. handlePlay(forms.musicList[forms.listActive + 1]);
  108. }
  109. }
  110. };
  111. watch(
  112. () => props.show,
  113. val => {
  114. if (val) {
  115. // onToggleAudio();
  116. } else {
  117. // audioRef.value.pause();
  118. // data.playState = 'pause';
  119. handleChangeAudio('pause');
  120. try {
  121. // 暂停视频
  122. const doms = document.querySelectorAll('.video-music');
  123. if (doms && doms.length > 0) {
  124. doms.forEach((dom: any) => {
  125. dom.pause();
  126. });
  127. }
  128. } catch {
  129. //
  130. }
  131. }
  132. }
  133. );
  134. onMounted(async () => {
  135. await getDetail();
  136. });
  137. return () => (
  138. <div
  139. class={[styles.knowledgeBg, forms.showPlayer ? styles.wrapBottom : '']}>
  140. <div class={styles.left}>
  141. {props.type === 'wiki' && (
  142. <div class={styles.insTop}>
  143. <div class={styles.imgSection}>
  144. <img
  145. class={styles.img}
  146. src={forms.dataInfo.avatar || musicBg}
  147. />
  148. <div class={styles.pan}>
  149. <img src={forms.dataInfo.avatar || musicBg} />
  150. </div>
  151. </div>
  152. {/* <div class={styles.songName}>{forms.dataInfo.name || '--'}</div> */}
  153. <NoticeBar
  154. text={forms.dataInfo.name}
  155. color="#000"
  156. class={styles.songName}
  157. background="none"
  158. />
  159. <div class={styles.songWords}>
  160. {forms.dataInfo.lyricists && (
  161. <span>作词:{forms.dataInfo.lyricists}</span>
  162. )}
  163. {forms.dataInfo.composers && (
  164. <span>作曲:{forms.dataInfo.composers}</span>
  165. )}
  166. </div>
  167. </div>
  168. )}
  169. {props.type === 'instrument' && (
  170. <div class={styles.insTop}>
  171. <img src={forms.dataInfo.avatar || pBg} />
  172. <div class={styles.insName}>{forms.dataInfo.name || ''}</div>
  173. <div class={styles.insTro}>
  174. {forms.dataInfo.knowledgeWikiCategoryName || ''}
  175. </div>
  176. </div>
  177. )}
  178. {props.type === 'musician' && (
  179. <div class={styles.insTop}>
  180. <img class={styles.musician} src={forms.dataInfo.avatar || pBg} />
  181. <div class={styles.insName}>{forms.dataInfo.name || ''}</div>
  182. <div class={styles.insTro}>
  183. {forms.dataInfo.knowledgeWikiCategoryName || ''}
  184. </div>
  185. </div>
  186. )}
  187. <div class={styles.songColumn}>
  188. <img src={songIcon} />
  189. <span>{props.type === 'instrument' ? '名曲鉴赏' : '代表作'}</span>
  190. </div>
  191. <div class={styles.insList}>
  192. {forms.musicList.length > 0 && (
  193. <>
  194. {forms.musicList.map((item: any, index: number) => {
  195. return (
  196. <div
  197. class={[
  198. styles.li,
  199. forms.listActive === index ? styles.liActive : ''
  200. ]}
  201. onClick={(e: Event) => {
  202. e.stopPropagation();
  203. handlePlay(item);
  204. }}>
  205. <div class={styles.liBg}>
  206. <img src={musicBg} />
  207. <PlayLoading
  208. class={[
  209. forms.listActive === index &&
  210. forms.playState === 'play'
  211. ? ''
  212. : styles.hidePlayLoading
  213. ]}
  214. />
  215. </div>
  216. {/* <div class={styles.liName}>{item.name || '--'}</div> */}
  217. <NoticeBar
  218. text={item.name}
  219. color="#131415"
  220. class={styles.liName}
  221. background="none"
  222. />
  223. {/* <img
  224. class={styles.liPlay}
  225. src={
  226. forms.listActive === index &&
  227. forms.playState === 'play'
  228. ? pauseIcon
  229. : playIcon
  230. }
  231. /> */}
  232. </div>
  233. );
  234. })}
  235. </>
  236. )}
  237. {forms.musicList.length <= 0 && forms.loading && (
  238. <div class={styles.emptyBox}>
  239. <img src={emptyIcon} />
  240. <span>暂无曲目~</span>
  241. </div>
  242. )}
  243. </div>
  244. </div>
  245. <div class={styles.right}>
  246. <div class={styles.title}>
  247. <img
  248. class={styles.liBg}
  249. src={props.type === 'musician' ? titleIcon2 : titleIcon1}
  250. />
  251. {props.type === 'wiki'
  252. ? '乐器简介'
  253. : props.type === 'instrument'
  254. ? '名曲故事'
  255. : props.type === 'musician'
  256. ? '个人简介'
  257. : ''}
  258. </div>
  259. <div class={styles.desc} v-html={forms.dataInfo.intros}></div>
  260. {!forms.loading && !forms.dataInfo.intros && (
  261. <MEmpty description="暂无内容" />
  262. )}
  263. </div>
  264. {forms.musicList.length !== 0 && (
  265. <PlayItem
  266. show={forms.showPlayer}
  267. playState={forms.playState}
  268. item={activeItem.value}
  269. onChange={value => handleChangeAudio(value)}
  270. />
  271. )}
  272. </div>
  273. );
  274. }
  275. });