mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-02-06 23:21:16 +08:00
Merge pull request #726 from WoJiaoFuXiaoYun/main
fix: 修复小窗口点击站内链接,会从小窗直接跳,预期主窗口跳转 #723
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div v-if="floatRoute" class="message-float-window" :style="{ height: floatHeight }">
|
||||
<iframe :src="iframeSrc" frameborder="0"></iframe>
|
||||
<iframe :src="iframeSrc" frameborder="0" ref="iframeRef" @load="injectBaseTag"></iframe>
|
||||
|
||||
<div class="float-actions">
|
||||
<i
|
||||
@@ -29,6 +29,7 @@ const DEFAULT_HEIGHT = '60vh'
|
||||
const MINI_HEIGHT = '45px'
|
||||
const floatHeight = ref(DEFAULT_HEIGHT)
|
||||
|
||||
const iframeRef = ref(null)
|
||||
const iframeSrc = computed(() => {
|
||||
if (!floatRoute.value) return ''
|
||||
return floatRoute.value + (floatRoute.value.includes('?') ? '&' : '?') + 'float=1'
|
||||
@@ -49,6 +50,17 @@ function expand() {
|
||||
navigateTo(target)
|
||||
}
|
||||
|
||||
function injectBaseTag() {
|
||||
if (!iframeRef.value) return
|
||||
|
||||
const iframeDoc = iframeRef.value.contentDocument || iframeRef.value.contentWindow.document
|
||||
if (iframeDoc && !iframeDoc.querySelector('base')) {
|
||||
const base = iframeDoc.createElement('base')
|
||||
base.target = '_top'
|
||||
iframeDoc.head.appendChild(base)
|
||||
}
|
||||
}
|
||||
|
||||
// 当浮窗重新出现时,恢复默认高度
|
||||
watch(
|
||||
() => floatRoute.value,
|
||||
@@ -72,7 +84,8 @@ watch(
|
||||
z-index: 2000;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
transition: height 0.25s ease; /* 平滑过渡 */
|
||||
transition: height 0.25s ease;
|
||||
/* 平滑过渡 */
|
||||
}
|
||||
|
||||
.message-float-window iframe {
|
||||
|
||||
Reference in New Issue
Block a user