auth-web/src/layout/frame.vue

91 lines
1.8 KiB
Vue
Raw Normal View History

2024-10-09 15:48:26 +08:00
<script lang="ts" setup>
import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router';
import { nextTick, onMounted, ref, unref, watch } from 'vue';
2024-09-26 09:38:02 +08:00
defineOptions({
2024-10-09 15:48:26 +08:00
name: 'LayFrame',
2024-09-26 09:38:02 +08:00
});
const props = defineProps<{
2024-10-09 15:48:26 +08:00
frameInfo?: {
frameSrc?: string;
fullPath?: string;
};
2024-09-26 09:38:02 +08:00
}>();
const { t } = useI18n();
const loading = ref(true);
const currentRoute = useRoute();
2024-10-09 15:48:26 +08:00
const frameSrc = ref<string>('');
2024-09-26 09:38:02 +08:00
const frameRef = ref<HTMLElement | null>(null);
if (unref(currentRoute.meta)?.frameSrc) {
2024-10-09 15:48:26 +08:00
frameSrc.value = unref(currentRoute.meta)?.frameSrc as string;
2024-09-26 09:38:02 +08:00
}
unref(currentRoute.meta)?.frameLoading === false && hideLoading();
function hideLoading() {
2024-10-09 15:48:26 +08:00
loading.value = false;
2024-09-26 09:38:02 +08:00
}
function init() {
2024-10-09 15:48:26 +08:00
nextTick(() => {
const iframe = unref(frameRef);
if (!iframe) return;
const _frame = iframe as any;
if (_frame.attachEvent) {
_frame.attachEvent('onload', () => {
hideLoading();
});
} else {
iframe.onload = () => {
hideLoading();
};
}
});
2024-09-26 09:38:02 +08:00
}
watch(
2024-10-09 15:48:26 +08:00
() => currentRoute.fullPath,
path => {
if (currentRoute.name === 'Redirect' && path.includes(props.frameInfo?.fullPath)) {
frameSrc.value = path; // redirect时置换成任意值待重定向后 重新赋值
loading.value = true;
}
// 重新赋值
if (props.frameInfo?.fullPath === path) {
frameSrc.value = props.frameInfo?.frameSrc;
}
},
2024-09-26 09:38:02 +08:00
);
onMounted(() => {
2024-10-09 15:48:26 +08:00
init();
2024-09-26 09:38:02 +08:00
});
</script>
<template>
2024-10-09 15:48:26 +08:00
<div v-loading="loading" :element-loading-text="t('status.pureLoad')" class="frame">
<iframe ref="frameRef" :src="frameSrc" class="frame-iframe" />
</div>
2024-09-26 09:38:02 +08:00
</template>
<style lang="scss" scoped>
.frame {
2024-10-09 15:48:26 +08:00
position: absolute;
inset: 0;
2024-09-26 09:38:02 +08:00
2024-10-09 15:48:26 +08:00
.frame-iframe {
box-sizing: border-box;
width: 100%;
height: 100%;
overflow: hidden;
border: 0;
}
2024-09-26 09:38:02 +08:00
}
.main-content {
2024-10-09 15:48:26 +08:00
margin: 2px 0 0 !important;
2024-09-26 09:38:02 +08:00
}
</style>