index.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. import useDrag from '@/hooks/useDrag';
  14. import Dragbom from '@/hooks/useDrag/dragbom';
  15. import { useUserStore } from '@/store/modules/users';
  16. import { modalClickMask } from '/src/state';
  17. export default defineComponent({
  18. name: 'card-preview',
  19. props: {
  20. show: {
  21. type: Boolean,
  22. default: false
  23. },
  24. item: {
  25. type: Object,
  26. default: () => ({})
  27. },
  28. size: {
  29. type: String,
  30. default: 'default'
  31. },
  32. /** 是否下载 只支持 video audio */
  33. isDownload: {
  34. type: Boolean,
  35. default: true
  36. },
  37. /** 是否下载 只支持 video audio */
  38. fullscreen: {
  39. type: Boolean,
  40. default: true
  41. },
  42. /** 从哪里使用 */
  43. from: {
  44. type: String,
  45. default: ''
  46. }
  47. },
  48. emit: ['update:show'],
  49. setup(props, { emit }) {
  50. const show = toRef(props.show);
  51. const item = toRef(props.item);
  52. const pptLoading = ref(true);
  53. watch(
  54. () => props.show,
  55. () => {
  56. show.value = props.show;
  57. }
  58. );
  59. watch(
  60. () => props.item,
  61. () => {
  62. item.value = props.item;
  63. console.log(item.value, 'item.value value');
  64. }
  65. );
  66. // 拖动
  67. let cardPreviewBoxDragData: any;
  68. let cardPreviewBoxClass: string;
  69. if (props.from === 'class') {
  70. const users = useUserStore();
  71. cardPreviewBoxClass = 'cardPreviewBoxClass_drag';
  72. cardPreviewBoxDragData = useDrag(
  73. [
  74. `${cardPreviewBoxClass}>.n-card-header`,
  75. `${cardPreviewBoxClass} .bom_drag`
  76. ],
  77. cardPreviewBoxClass,
  78. show,
  79. users.info.id
  80. );
  81. }
  82. return () => (
  83. <>
  84. <NModal
  85. maskClosable={modalClickMask}
  86. style={
  87. props.from === 'class' ? cardPreviewBoxDragData.styleDrag.value : {}
  88. }
  89. v-model:show={show.value}
  90. onUpdate:show={() => {
  91. emit('update:show', show.value);
  92. if (!show.value) {
  93. pptLoading.value = true;
  94. }
  95. }}
  96. preset="card"
  97. showIcon={false}
  98. class={[
  99. 'modalTitle background',
  100. cardPreviewBoxClass,
  101. props.from === 'class' && styles.classCard,
  102. styles.cardPreview,
  103. item.value.type === 'PPT' && styles.maxCard,
  104. props.size === 'large' && styles.cardLarge
  105. ]}
  106. title={item.value.type === 'MUSIC' ? '曲目预览' : item.value.title}
  107. blockScroll={false}>
  108. {item.value.type === 'VIDEO' && (
  109. <VideoModal
  110. title={
  111. item.value.title +
  112. (props.item.studentName ? '-' + props.item.studentName : '')
  113. }
  114. poster={item.value.url}
  115. src={item.value.content}
  116. isDownload={props.isDownload}
  117. fullscreen={props.fullscreen}
  118. />
  119. )}
  120. {item.value.type === 'MUSIC' && (
  121. <MusicModal
  122. class={styles.musicPreview}
  123. item={item.value}
  124. from={props.from}
  125. />
  126. )}
  127. {item.value.type === 'SONG' && (
  128. <SongModal
  129. item={item.value}
  130. isDownload={props.isDownload}
  131. fullscreen={props.fullscreen}
  132. />
  133. )}
  134. {item.value.type === 'PPT' && (
  135. <NSpin show={pptLoading.value}>
  136. <iframe
  137. class={styles.pptBox}
  138. src={`https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(
  139. item.value.content
  140. )}`}
  141. onLoad={() => {
  142. console.log('loading end');
  143. pptLoading.value = false;
  144. }}
  145. width="100%"
  146. height="100%"
  147. frameborder="1"></iframe>
  148. </NSpin>
  149. )}
  150. {item.value.type === 'RHYTHM' && (
  151. <RhythmModal class={styles.musicPreview} item={item.value} />
  152. )}
  153. {item.value.type === 'LISTEN' && (
  154. <ListenModal class={styles.musicPreview} item={item.value} />
  155. )}
  156. {(item.value.type === 'INSTRUMENT' ||
  157. item.value.type === 'MUSICIAN') && (
  158. <div class={styles.instrumentGroup}>
  159. <InstruemntDetail
  160. type="modal"
  161. contentType={item.value.type}
  162. id={item.value.content}
  163. />
  164. </div>
  165. )}
  166. {item.value.type === 'MUSIC_WIKI' && (
  167. <div class={styles.instrumentGroup}>
  168. <MusicDetail
  169. type="modal"
  170. contentType={item.value.type}
  171. id={item.value.content}
  172. />
  173. </div>
  174. )}
  175. {item.value.type === 'THEORY' && (
  176. <div>
  177. <TheoryDetail type="modal" id={item.value.content} />
  178. </div>
  179. )}
  180. {/* LISTEN:听音,RHYTHM:节奏,THEORY:乐理知识,MUSIC_WIKI:曲目 INSTRUMENT:乐器 MUSICIAN:音乐家) */}
  181. {/* VIDEO("视频"),
  182. MUSIC("曲目"),
  183. IMG("图片"),
  184. SONG("音频"),
  185. PPT("ppt"),
  186. LISTEN("听音练习"),
  187. RHYTHM("节奏练习"),
  188. THEORY("乐理知识"),
  189. MUSIC_WIKI("名曲鉴赏"),
  190. INSTRUMENT("乐器"),
  191. MUSICIAN("音乐家"), */}
  192. {![
  193. 'VIDEO',
  194. 'MUSIC',
  195. 'SONG',
  196. 'PPT',
  197. 'RHYTHM',
  198. 'INSTRUMENT',
  199. 'THEORY',
  200. 'MUSICIAN',
  201. 'MUSIC_WIKI',
  202. 'LISTEN'
  203. ].includes(item.value.type) && <TheEmpty />}
  204. {props.from === 'class' && <Dragbom></Dragbom>}
  205. </NModal>
  206. </>
  207. );
  208. }
  209. });