index.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. <NModal
  84. maskClosable={modalClickMask}
  85. style={
  86. props.from === 'class' ? cardPreviewBoxDragData.styleDrag.value : {}
  87. }
  88. v-model:show={show.value}
  89. onUpdate:show={() => {
  90. emit('update:show', show.value);
  91. if (!show.value) {
  92. pptLoading.value = true;
  93. }
  94. }}
  95. preset="card"
  96. showIcon={false}
  97. class={[
  98. 'modalTitle background',
  99. cardPreviewBoxClass,
  100. props.from === 'class' && styles.classCard,
  101. styles.cardPreview,
  102. item.value.type === 'PPT' && styles.maxCard,
  103. props.size === 'large' && styles.cardLarge
  104. ]}
  105. title={item.value.type === 'MUSIC' ? '曲目预览' : item.value.title}
  106. blockScroll={false}>
  107. {item.value.type === 'VIDEO' && (
  108. <VideoModal
  109. title={
  110. item.value.title +
  111. (props.item.studentName ? '-' + props.item.studentName : '')
  112. }
  113. poster={item.value.url}
  114. src={item.value.content}
  115. isDownload={props.isDownload}
  116. fullscreen={props.fullscreen}
  117. />
  118. )}
  119. {item.value.type === 'MUSIC' && (
  120. <MusicModal
  121. class={styles.musicPreview}
  122. item={item.value}
  123. from={props.from}
  124. />
  125. )}
  126. {item.value.type === 'SONG' && (
  127. <SongModal
  128. item={item.value}
  129. isDownload={props.isDownload}
  130. fullscreen={props.fullscreen}
  131. />
  132. )}
  133. {item.value.type === 'PPT' && (
  134. <NSpin show={pptLoading.value}>
  135. <iframe
  136. class={styles.pptBox}
  137. src={`https://view.officeapps.live.com/op/embed.aspx?src=${encodeURIComponent(
  138. item.value.content
  139. )}`}
  140. onLoad={() => {
  141. console.log('loading end');
  142. pptLoading.value = false;
  143. }}
  144. width="100%"
  145. height="100%"
  146. frameborder="1"></iframe>
  147. </NSpin>
  148. )}
  149. {item.value.type === 'RHYTHM' && (
  150. <RhythmModal class={styles.musicPreview} item={item.value} />
  151. )}
  152. {item.value.type === 'LISTEN' && (
  153. <ListenModal class={styles.musicPreview} item={item.value} />
  154. )}
  155. {(item.value.type === 'INSTRUMENT' ||
  156. item.value.type === 'MUSICIAN') && (
  157. <div class={styles.instrumentGroup}>
  158. <InstruemntDetail
  159. type="modal"
  160. contentType={item.value.type}
  161. id={item.value.content}
  162. />
  163. </div>
  164. )}
  165. {item.value.type === 'MUSIC_WIKI' && (
  166. <div class={styles.instrumentGroup}>
  167. <MusicDetail
  168. type="modal"
  169. contentType={item.value.type}
  170. id={item.value.content}
  171. />
  172. </div>
  173. )}
  174. {item.value.type === 'THEORY' && (
  175. <div>
  176. <TheoryDetail type="modal" id={item.value.content} />
  177. </div>
  178. )}
  179. {/* LISTEN:听音,RHYTHM:节奏,THEORY:乐理知识,MUSIC_WIKI:曲目 INSTRUMENT:乐器 MUSICIAN:音乐家) */}
  180. {/* VIDEO("视频"),
  181. MUSIC("曲目"),
  182. IMG("图片"),
  183. SONG("音频"),
  184. PPT("ppt"),
  185. LISTEN("听音练习"),
  186. RHYTHM("节奏练习"),
  187. THEORY("乐理知识"),
  188. MUSIC_WIKI("名曲鉴赏"),
  189. INSTRUMENT("乐器"),
  190. MUSICIAN("音乐家"), */}
  191. {![
  192. 'VIDEO',
  193. 'MUSIC',
  194. 'SONG',
  195. 'PPT',
  196. 'RHYTHM',
  197. 'INSTRUMENT',
  198. 'THEORY',
  199. 'MUSICIAN',
  200. 'MUSIC_WIKI',
  201. 'LISTEN'
  202. ].includes(item.value.type) && <TheEmpty />}
  203. {props.from === 'class' && <Dragbom></Dragbom>}
  204. </NModal>
  205. );
  206. }
  207. });