mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-10-10 12:14:50 +08:00
fix: 修复在内嵌同源iframe
页面中,当其注册了beforeunload
事件时,右键标签页点击重新加载
导致浏览器弹出两次确认拦截的问题 (#1229)
This commit is contained in:
parent
5b14db8785
commit
fa606b429b
@ -19,13 +19,22 @@ const loading = ref(true);
|
|||||||
const currentRoute = useRoute();
|
const currentRoute = useRoute();
|
||||||
const frameSrc = ref<string>("");
|
const frameSrc = ref<string>("");
|
||||||
const frameRef = ref<HTMLElement | null>(null);
|
const frameRef = ref<HTMLElement | null>(null);
|
||||||
|
const fallbackTimer = ref<number | null>(null);
|
||||||
|
|
||||||
if (unref(currentRoute.meta)?.frameSrc) {
|
if (unref(currentRoute.meta)?.frameSrc) {
|
||||||
frameSrc.value = unref(currentRoute.meta)?.frameSrc as string;
|
frameSrc.value = unref(currentRoute.meta)?.frameSrc as string;
|
||||||
}
|
}
|
||||||
unref(currentRoute.meta)?.frameLoading === false && hideLoading();
|
|
||||||
|
function clearFallbackTimer() {
|
||||||
|
if (fallbackTimer.value !== null) {
|
||||||
|
clearTimeout(fallbackTimer.value);
|
||||||
|
fallbackTimer.value = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function hideLoading() {
|
function hideLoading() {
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
|
clearFallbackTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
@ -34,32 +43,42 @@ function init() {
|
|||||||
if (!iframe) return;
|
if (!iframe) return;
|
||||||
const _frame = iframe as any;
|
const _frame = iframe as any;
|
||||||
if (_frame.attachEvent) {
|
if (_frame.attachEvent) {
|
||||||
_frame.attachEvent("onload", () => {
|
_frame.attachEvent("onload", hideLoading);
|
||||||
hideLoading();
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
iframe.onload = () => {
|
iframe.onload = hideLoading;
|
||||||
hideLoading();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let isRedirect = false;
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => currentRoute.fullPath,
|
() => currentRoute.fullPath,
|
||||||
path => {
|
path => {
|
||||||
if (
|
if (
|
||||||
currentRoute.name === "Redirect" &&
|
currentRoute.name === "Redirect" &&
|
||||||
path.includes(props.frameInfo?.fullPath)
|
props.frameInfo?.fullPath &&
|
||||||
|
path.includes(props.frameInfo.fullPath)
|
||||||
) {
|
) {
|
||||||
frameSrc.value = path; // redirect时,置换成任意值,待重定向后 重新赋值
|
isRedirect = true;
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
// 重新赋值
|
if (props.frameInfo?.fullPath === path && isRedirect) {
|
||||||
if (props.frameInfo?.fullPath === path) {
|
loading.value = true;
|
||||||
frameSrc.value = props.frameInfo?.frameSrc;
|
clearFallbackTimer();
|
||||||
|
const url = new URL(props.frameInfo.frameSrc, window.location.origin);
|
||||||
|
const joinChar = url.search ? "&" : "?";
|
||||||
|
frameSrc.value = `${props.frameInfo.frameSrc}${joinChar}t=${Date.now()}`;
|
||||||
|
fallbackTimer.value = window.setTimeout(() => {
|
||||||
|
if (loading.value) {
|
||||||
|
hideLoading();
|
||||||
|
}
|
||||||
|
}, 1500);
|
||||||
|
isRedirect = false;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
{ immediate: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user