index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div :class="prefixCls" :style="getWrapStyle">
  3. <Spin :spinning="loading" size="large" :style="getWrapStyle">
  4. <iframe :src="frameSrc" :class="`${prefixCls}__main`" ref="frameRef" @load="hideLoading"></iframe>
  5. </Spin>
  6. </div>
  7. </template>
  8. <script lang="ts" setup>
  9. import type { CSSProperties } from 'vue';
  10. import { ref, unref, computed } from 'vue';
  11. import { Spin } from 'ant-design-vue';
  12. import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn';
  13. import { propTypes } from '/@/utils/propTypes';
  14. import { useDesign } from '/@/hooks/web/useDesign';
  15. import { useLayoutHeight } from '/@/layouts/default/content/useContentViewHeight';
  16. import { useAppStore } from '/@/store/modules/app';
  17. defineProps({
  18. frameSrc: propTypes.string.def(''),
  19. });
  20. const appStore = useAppStore();
  21. const loading = ref(true);
  22. const topRef = ref(50);
  23. // debugger;
  24. const heightRef = ref(window.innerHeight / appStore.getHeightScale);
  25. const frameRef = ref<HTMLFrameElement>();
  26. const { headerHeightRef } = useLayoutHeight();
  27. const { prefixCls } = useDesign('iframe-page');
  28. useWindowSizeFn(calcHeight, 150, { immediate: true });
  29. const getWrapStyle = computed((): CSSProperties => {
  30. return {
  31. height: `${unref(heightRef)}px`,
  32. };
  33. });
  34. function calcHeight() {
  35. const iframe = unref(frameRef);
  36. if (!iframe) {
  37. return;
  38. }
  39. const top = headerHeightRef.value;
  40. topRef.value = top;
  41. heightRef.value = window.innerHeight / appStore.getHeightScale - top;
  42. const clientHeight = document.documentElement.clientHeight / appStore.getHeightScale - top;
  43. const clientWidth = document.documentElement.clientWidth / appStore.getWidthScale;
  44. iframe.style.height = `${clientHeight}px`;
  45. iframe.style.width = `${clientWidth}px`;
  46. }
  47. function hideLoading() {
  48. loading.value = false;
  49. calcHeight();
  50. }
  51. </script>
  52. <style lang="less" scoped>
  53. @prefix-cls: ~'@{namespace}-iframe-page';
  54. @ventSpace: zxm;
  55. .@{prefix-cls} {
  56. .@{ventSpace}-spin-nested-loading {
  57. position: relative;
  58. height: 100%;
  59. .@{ventSpace}-spin-container {
  60. width: 100%;
  61. height: 100%;
  62. padding: 10px;
  63. }
  64. }
  65. &__mask {
  66. position: absolute;
  67. top: 0;
  68. left: 0;
  69. width: 100%;
  70. height: 100%;
  71. }
  72. &__main {
  73. width: 100%;
  74. height: 100%;
  75. overflow: hidden;
  76. background-color: @component-background;
  77. border: 0;
  78. box-sizing: border-box;
  79. }
  80. }
  81. </style>