From fa606b429b03713b16edd0ca8a2189ab0b45363d Mon Sep 17 00:00:00 2001 From: tinyThing <31398496+tinysimple@users.noreply.github.com> Date: Sun, 28 Sep 2025 15:10:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=9C=A8=E5=86=85?= =?UTF-8?q?=E5=B5=8C=E5=90=8C=E6=BA=90`iframe`=E9=A1=B5=E9=9D=A2=E4=B8=AD?= =?UTF-8?q?=EF=BC=8C=E5=BD=93=E5=85=B6=E6=B3=A8=E5=86=8C=E4=BA=86`beforeun?= =?UTF-8?q?load`=E4=BA=8B=E4=BB=B6=E6=97=B6=EF=BC=8C=E5=8F=B3=E9=94=AE?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E9=A1=B5=E7=82=B9=E5=87=BB`=E9=87=8D?= =?UTF-8?q?=E6=96=B0=E5=8A=A0=E8=BD=BD`=E5=AF=BC=E8=87=B4=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=E5=BC=B9=E5=87=BA=E4=B8=A4=E6=AC=A1=E7=A1=AE?= =?UTF-8?q?=E8=AE=A4=E6=8B=A6=E6=88=AA=E7=9A=84=E9=97=AE=E9=A2=98=20(#1229?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/frame.vue | 45 +++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/layout/frame.vue b/src/layout/frame.vue index 4243b57d5..88f2deda3 100644 --- a/src/layout/frame.vue +++ b/src/layout/frame.vue @@ -19,13 +19,22 @@ const loading = ref(true); const currentRoute = useRoute(); const frameSrc = ref(""); const frameRef = ref(null); +const fallbackTimer = ref(null); + if (unref(currentRoute.meta)?.frameSrc) { 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() { loading.value = false; + clearFallbackTimer(); } function init() { @@ -34,32 +43,42 @@ function init() { if (!iframe) return; const _frame = iframe as any; if (_frame.attachEvent) { - _frame.attachEvent("onload", () => { - hideLoading(); - }); + _frame.attachEvent("onload", hideLoading); } else { - iframe.onload = () => { - hideLoading(); - }; + iframe.onload = hideLoading; } }); } +let isRedirect = false; + watch( () => currentRoute.fullPath, path => { if ( 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; + return; } - // 重新赋值 - if (props.frameInfo?.fullPath === path) { - frameSrc.value = props.frameInfo?.frameSrc; + if (props.frameInfo?.fullPath === path && isRedirect) { + loading.value = true; + 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(() => {