index.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import {
  2. PropType,
  3. defineComponent,
  4. onMounted,
  5. onUnmounted,
  6. ref,
  7. toRefs,
  8. watch
  9. } from 'vue';
  10. import styles from './index.module.less';
  11. import { NModal } from 'naive-ui';
  12. import AttendClass from '../attend-class';
  13. export default defineComponent({
  14. name: 'preview-window',
  15. props: {
  16. show: {
  17. type: Boolean,
  18. default: false
  19. },
  20. type: {
  21. type: String,
  22. default: ''
  23. },
  24. params: {
  25. type: Object as PropType<any>,
  26. default: () => ({})
  27. }
  28. },
  29. emit: ['update:show'],
  30. setup(props, { emit }) {
  31. const { show, type, params } = toRefs(props);
  32. watch(
  33. () => props.show,
  34. () => {
  35. show.value = props.show;
  36. }
  37. );
  38. watch(
  39. () => props.type,
  40. () => {
  41. type.value = props.type;
  42. }
  43. );
  44. watch(
  45. () => props.params,
  46. () => {
  47. params.value = props.params;
  48. }
  49. );
  50. const handleOpen = (e: MessageEvent) => {
  51. if (e.data.api === 'iframe_exit') {
  52. emit('update:show', false);
  53. }
  54. };
  55. onMounted(() => {
  56. window.addEventListener('message', handleOpen);
  57. });
  58. onUnmounted(() => {
  59. window.removeEventListener('message', handleOpen);
  60. });
  61. return () => (
  62. <>
  63. <NModal
  64. v-model:show={show.value}
  65. onUpdate:show={() => {
  66. emit('update:show', show.value);
  67. }}
  68. class={styles.previewWindow}
  69. showIcon={false}
  70. displayDirective="show">
  71. <>
  72. {show.value ? (
  73. type.value == 'attend' ? (
  74. <AttendClass
  75. type={params.value.type || ''}
  76. subjectId={params.value.subjectId || ''}
  77. courseId={params.value.courseId || ''}
  78. detailId={params.value.detailId || ''}
  79. classGroupId={params.value.classGroupId || ''}
  80. lessonCourseId={params.value.lessonCourseId || ''}
  81. classId={params.value.classId || ''}
  82. preStudentNum={params.value.preStudentNum}
  83. onClose={() => emit('update:show', false)}
  84. />
  85. ) : type.value == 'notation' ? (
  86. <iframe src={params.value.src}></iframe>
  87. ) : type.value == 'music' ? (
  88. <iframe
  89. src={params.value.src}
  90. style={{ height: '100vh' }}></iframe>
  91. ) : (
  92. ''
  93. )
  94. ) : (
  95. ''
  96. )}
  97. </>
  98. </NModal>
  99. </>
  100. );
  101. }
  102. });