index.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <LeftMenu>
  3. <VerticalFlexLayout>
  4. <template #static>
  5. <Breadcrumb />
  6. </template>
  7. <div class="frame" v-loading="loading">
  8. <iframe :src="frameSrc" class="frame-iframe" ref="frameRef" :key="frameSrc"></iframe>
  9. </div>
  10. </VerticalFlexLayout>
  11. </LeftMenu>
  12. </template>
  13. <script lang="ts" setup>
  14. import { ref, unref, onMounted, nextTick, watch } from 'vue';
  15. import { useRoute } from 'vue-router';
  16. import VerticalFlexLayout from '@/components/VerticalFlexLayout.vue';
  17. import Breadcrumb from '@/components/Breadcrumb.vue';
  18. import LeftMenu from '@/layout/components/left-menu/LeftMenu.vue';
  19. const currentRoute = useRoute();
  20. const loading = ref(false);
  21. const frameRef = ref<HTMLFrameElement | null>(null);
  22. const frameSrc = ref<string>('');
  23. watch(
  24. () => currentRoute.meta,
  25. (meta) => {
  26. frameSrc.value = unref(meta)?.frameSrc as string;
  27. },
  28. { immediate: true },
  29. );
  30. function hideLoading() {
  31. loading.value = false;
  32. }
  33. function init() {
  34. nextTick(() => {
  35. const iframe = unref(frameRef);
  36. if (!iframe) return;
  37. const _frame = iframe as any;
  38. if (_frame.attachEvent) {
  39. _frame.attachEvent('onload', () => {
  40. hideLoading();
  41. });
  42. } else {
  43. iframe.onload = () => {
  44. hideLoading();
  45. };
  46. }
  47. });
  48. }
  49. onMounted(() => {
  50. loading.value = true;
  51. init();
  52. });
  53. </script>
  54. <style lang="scss" scoped>
  55. .frame {
  56. width: 100%;
  57. height: 100%;
  58. &-iframe {
  59. width: 100%;
  60. height: 100%;
  61. overflow: hidden;
  62. border: 0;
  63. box-sizing: border-box;
  64. }
  65. }
  66. </style>