index.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import { defineComponent, onMounted, reactive, ref } from 'vue';
  2. import { useUserStore } from '/src/store/modules/users';
  3. import styles from './index.module.less';
  4. import { state } from '/src/state';
  5. import { NButton, NModal, NSpace, NSpin } from 'naive-ui';
  6. import { exitFullscreen } from '/src/utils';
  7. export default defineComponent({
  8. name: 'notation-a',
  9. setup() {
  10. const show = ref(false);
  11. const previewModal = ref(false);
  12. const previewParams = ref({} as any);
  13. const removeVisiable = ref(false);
  14. const userStore = useUserStore();
  15. const Authorization = userStore.getToken || '';
  16. const iframeRef = ref();
  17. console.log(Authorization);
  18. const notationOpenCreate = sessionStorage.getItem('notation-open-create');
  19. const openCreateUrl = notationOpenCreate == '1' ? '&addShow=1' : '';
  20. sessionStorage.removeItem('notation-open-create');
  21. const data = reactive({
  22. src: `${
  23. /(192|localhost)/.test(location.origin)
  24. ? // ?
  25. 'https://test.lexiaoya.cn'
  26. : // 'http://localhost:3050'
  27. location.origin
  28. }/notation/#/create?Authorization=${Authorization}${openCreateUrl}`
  29. // src: `http://localhost:3050/#/create?Authorization=${Authorization}`
  30. });
  31. const fscreen = () => {
  32. const el = document.documentElement as any;
  33. //进入全屏
  34. (el.requestFullscreen && el.requestFullscreen()) ||
  35. (el.mozRequestFullScreen && el.mozRequestFullScreen()) ||
  36. (el.webkitRequestFullscreen && el.webkitRequestFullscreen()) ||
  37. (el.msRequestFullscreen && el.msRequestFullscreen());
  38. };
  39. const handleOpen = (e: MessageEvent) => {
  40. console.log(e.data, 'data');
  41. if (e.data.api === 'notation_open') {
  42. if (state.application) {
  43. show.value = true;
  44. previewModal.value = true;
  45. previewParams.value = {
  46. url: e.data.url
  47. };
  48. fscreen();
  49. } else {
  50. window.open(e.data.url);
  51. }
  52. } else if (e.data.api === 'notation_exit') {
  53. console.log('进来');
  54. removeVisiable.value = true;
  55. }
  56. };
  57. onMounted(() => {
  58. window.addEventListener('message', handleOpen);
  59. });
  60. return () => (
  61. <div class={styles.wrap}>
  62. <iframe ref={iframeRef} src={data.src}></iframe>
  63. <NModal
  64. v-model:show={previewModal.value}
  65. class={styles.previewWindow}
  66. showIcon={false}
  67. displayDirective="show">
  68. <NSpin show={show.value} style="--n-opacity-spinning: 1;">
  69. <iframe
  70. class={styles.previewIframe}
  71. onLoad={() => {
  72. show.value = false;
  73. }}
  74. frameborder="0"
  75. src={previewParams.value.url}></iframe>
  76. </NSpin>
  77. </NModal>
  78. <NModal
  79. v-model:show={removeVisiable.value}
  80. preset="card"
  81. class={['modalTitle', styles.removeVisiable]}
  82. title={'退出制谱'}>
  83. <div class={styles.studentRemove}>
  84. <p>是否退出制谱功能?</p>
  85. <NSpace class={styles.btnGroupModal} justify="center">
  86. <NButton
  87. round
  88. type="primary"
  89. onClick={() => {
  90. previewModal.value = false;
  91. previewParams.value.url = '';
  92. removeVisiable.value = false;
  93. // 给制谱发消息
  94. iframeRef.value.contentWindow.postMessage(
  95. {
  96. api: 'reload'
  97. },
  98. '*'
  99. );
  100. if (state.application) {
  101. document.exitFullscreen
  102. ? document.exitFullscreen()
  103. : document.mozCancelFullScreen
  104. ? document.mozCancelFullScreen()
  105. : document.webkitExitFullscreen
  106. ? document.webkitExitFullscreen()
  107. : '';
  108. }
  109. }}>
  110. 确定
  111. </NButton>
  112. <NButton round onClick={() => (removeVisiable.value = false)}>
  113. 取消
  114. </NButton>
  115. </NSpace>
  116. </div>
  117. </NModal>
  118. </div>
  119. );
  120. }
  121. });