index.tsx 4.5 KB

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