index.tsx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import { NModal, NSpin } from 'naive-ui';
  2. import { defineComponent, ref, toRef, watch } from 'vue';
  3. import styles from './index.module.less';
  4. import VideoModal from './video-modal';
  5. import MusicModal from './music-modal';
  6. import SongModal from './song-modal';
  7. import TheEmpty from '../TheEmpty';
  8. import RhythmModal from './rhythm-modal';
  9. import InstruemntDetail from '/src/views/prepare-lessons/model/source-instrument/detail';
  10. import TheoryDetail from '/src/views/prepare-lessons/model/source-knowledge/detail';
  11. import MusicDetail from '/src/views/prepare-lessons/model/source-music/detail';
  12. import ListenModal from './listen-modal';
  13. export default defineComponent({
  14. name: 'card-preview',
  15. props: {
  16. show: {
  17. type: Boolean,
  18. default: false
  19. },
  20. item: {
  21. type: Object,
  22. default: () => ({})
  23. },
  24. size: {
  25. type: String,
  26. default: 'default'
  27. },
  28. /** 是否下载 只支持 video audio */
  29. isDownload: {
  30. type: Boolean,
  31. default: false
  32. }
  33. },
  34. emit: ['update:show'],
  35. setup(props, { emit }) {
  36. const show = toRef(props.show);
  37. const item = toRef(props.item);
  38. const pptLoading = ref(true);
  39. watch(
  40. () => props.show,
  41. () => {
  42. show.value = props.show;
  43. }
  44. );
  45. watch(
  46. () => props.item,
  47. () => {
  48. item.value = props.item;
  49. }
  50. );
  51. return () => (
  52. <>
  53. <NModal
  54. v-model:show={show.value}
  55. onUpdate:show={() => {
  56. emit('update:show', show.value);
  57. if (!show.value) {
  58. pptLoading.value = true;
  59. }
  60. }}
  61. preset="card"
  62. showIcon={false}
  63. class={[
  64. 'modalTitle background',
  65. styles.cardPreview,
  66. item.value.type === 'PPT' && styles.maxCard,
  67. props.size === 'large' && styles.cardLarge
  68. ]}
  69. title={item.value.title}
  70. blockScroll={false}>
  71. {item.value.type === 'VIDEO' && (
  72. <VideoModal
  73. title={item.value.title}
  74. poster={item.value.url}
  75. src={item.value.content}
  76. isDownload={props.isDownload}
  77. />
  78. )}
  79. {item.value.type === 'MUSIC' && (
  80. <MusicModal class={styles.musicPreview} item={item.value} />
  81. )}
  82. {item.value.type === 'SONG' && (
  83. <SongModal item={item.value} isDownload={props.isDownload} />
  84. )}
  85. {item.value.type === 'PPT' && (
  86. <NSpin show={pptLoading.value}>
  87. <iframe
  88. class={styles.pptBox}
  89. src={`https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(
  90. item.value.content
  91. )}`}
  92. onLoad={() => {
  93. console.log('loading end');
  94. pptLoading.value = false;
  95. }}
  96. width="100%"
  97. height="100%"
  98. frameborder="1"></iframe>
  99. </NSpin>
  100. )}
  101. {item.value.type === 'RHYTHM' && (
  102. <RhythmModal class={styles.musicPreview} item={item.value} />
  103. )}
  104. {item.value.type === 'LISTEN' && (
  105. <ListenModal class={styles.musicPreview} item={item.value} />
  106. )}
  107. {(item.value.type === 'INSTRUMENT' ||
  108. item.value.type === 'MUSICIAN') && (
  109. <div class={styles.instrumentGroup}>
  110. <InstruemntDetail
  111. type="modal"
  112. contentType={item.value.type}
  113. id={item.value.content}
  114. />
  115. </div>
  116. )}
  117. {item.value.type === 'MUSIC_WIKI' && (
  118. <div class={styles.instrumentGroup}>
  119. <MusicDetail
  120. type="modal"
  121. contentType={item.value.type}
  122. id={item.value.content}
  123. />
  124. </div>
  125. )}
  126. {item.value.type === 'THEORY' && (
  127. <div>
  128. <TheoryDetail type="modal" id={item.value.content} />
  129. </div>
  130. )}
  131. {/* LISTEN:听音,RHYTHM:节奏,THEORY:乐理知识,MUSIC_WIKI:曲目 INSTRUMENT:乐器 MUSICIAN:音乐家) */}
  132. {/* VIDEO("视频"),
  133. MUSIC("曲目"),
  134. IMG("图片"),
  135. SONG("音频"),
  136. PPT("ppt"),
  137. LISTEN("听音练习"),
  138. RHYTHM("节奏练习"),
  139. THEORY("乐理知识"),
  140. MUSIC_WIKI("名曲鉴赏"),
  141. INSTRUMENT("乐器"),
  142. MUSICIAN("音乐家"), */}
  143. {![
  144. 'VIDEO',
  145. 'MUSIC',
  146. 'SONG',
  147. 'PPT',
  148. 'RHYTHM',
  149. 'INSTRUMENT',
  150. 'THEORY',
  151. 'MUSICIAN',
  152. 'MUSIC_WIKI',
  153. 'LISTEN'
  154. ].includes(item.value.type) && <TheEmpty />}
  155. </NModal>
  156. </>
  157. );
  158. }
  159. });