index.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. import { iframeDislableKeyboard } from '/src/utils';
  14. import { modalClickMask } from '/src/state';
  15. export default defineComponent({
  16. name: 'preview-window',
  17. props: {
  18. show: {
  19. type: Boolean,
  20. default: false
  21. },
  22. type: {
  23. type: String,
  24. default: ''
  25. },
  26. params: {
  27. type: Object as PropType<any>,
  28. default: () => ({})
  29. }
  30. },
  31. emit: ['update:show'],
  32. setup(props, { emit }) {
  33. const { show, type, params } = toRefs(props);
  34. watch(
  35. () => props.show,
  36. () => {
  37. show.value = props.show;
  38. }
  39. );
  40. watch(
  41. () => props.type,
  42. () => {
  43. type.value = props.type;
  44. }
  45. );
  46. watch(
  47. () => props.params,
  48. () => {
  49. params.value = props.params;
  50. }
  51. );
  52. const handleOpen = (e: MessageEvent) => {
  53. if (e.data.api === 'iframe_exit') {
  54. emit('update:show', false);
  55. }
  56. };
  57. onMounted(() => {
  58. window.addEventListener('message', handleOpen);
  59. });
  60. onUnmounted(() => {
  61. window.removeEventListener('message', handleOpen);
  62. });
  63. return () => (
  64. <>
  65. <NModal
  66. maskClosable={modalClickMask}
  67. v-model:show={show.value}
  68. onUpdate:show={() => {
  69. emit('update:show', show.value);
  70. }}
  71. class={styles.previewWindow}
  72. showIcon={false}
  73. displayDirective="show">
  74. <>
  75. {show.value ? (
  76. type.value == 'attend' ? (
  77. <AttendClass
  78. type={params.value.type || ''}
  79. instrumentId={params.value.instrumentId || ''}
  80. courseId={params.value.courseId || ''}
  81. detailId={params.value.detailId || ''}
  82. classGroupId={params.value.classGroupId || ''}
  83. lessonCourseId={params.value.lessonCourseId || ''}
  84. classId={params.value.classId || ''}
  85. preStudentNum={params.value.preStudentNum}
  86. onClose={() => emit('update:show', false)}
  87. />
  88. ) : type.value == 'notation' ? (
  89. <iframe
  90. src={params.value.src}
  91. onLoad={(val: any) => {
  92. iframeDislableKeyboard(val.target);
  93. }}></iframe>
  94. ) : type.value == 'music' ? (
  95. <iframe
  96. src={params.value.src}
  97. onLoad={(val: any) => {
  98. iframeDislableKeyboard(val.target);
  99. }}
  100. style={{ height: '100vh' }}></iframe>
  101. ) : (
  102. ''
  103. )
  104. ) : (
  105. ''
  106. )}
  107. </>
  108. </NModal>
  109. </>
  110. );
  111. }
  112. });