Skip to content

Commit fcef456

Browse files
committed
feat(IframeDrawer): 抽屉模式下添加对网页全屏模式的支持 #182
1 parent 3b31f04 commit fcef456

1 file changed

Lines changed: 34 additions & 12 deletions

File tree

src/components/IframeDrawer.vue

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,31 @@ const showIframe = ref<boolean>(false)
2727
const delayCloseTimer = ref<NodeJS.Timeout | null>(null)
2828
const removeTopBarClassInjected = ref<boolean>(false)
2929
const originUrl = ref<string>()
30+
const isPageFullscreen = ref<boolean>(false)
31+
32+
// 计算iframe容器的样式
33+
const iframeContainerClasses = computed(() => {
34+
if (isPageFullscreen.value) {
35+
return 'pos-fixed top-0 left-0 w-full h-full z-999999'
36+
}
37+
else {
38+
const topPosition = headerShow.value ? 'top-$bew-top-bar-height' : 'top-0'
39+
return `pos-absolute ${topPosition} left-0 of-hidden bg-$bew-bg rounded-t-$bew-radius w-full h-full`
40+
}
41+
})
42+
43+
const iframeStyles = computed(() => {
44+
if (isPageFullscreen.value) {
45+
return {}
46+
}
47+
else {
48+
return {
49+
// Prevent top bar shaking when before the remove-top-bar-without-placeholder class is injected
50+
// When in fullscreen mode (headerShow is false), remove the top offset
51+
top: headerShow.value && !removeTopBarClassInjected.value ? `calc(-1 * var(--bew-top-bar-height))` : '0',
52+
}
53+
}
54+
})
3055
3156
useEventListener(window, 'popstate', updateIframeUrl)
3257
@@ -225,10 +250,12 @@ watchEffect(() => {
225250
case DRAWER_VIDEO_ENTER_PAGE_FULL:
226251
headerShow.value = false
227252
disableEscPress.value = true
253+
isPageFullscreen.value = true
228254
break
229255
case DRAWER_VIDEO_EXIT_PAGE_FULL:
230256
headerShow.value = true
231257
disableEscPress.value = false
258+
isPageFullscreen.value = false
232259
break
233260
}
234261
})
@@ -240,10 +267,10 @@ watchEffect(() => {
240267
pos="absolute top-0 left-0" of-hidden w-full h-full
241268
z-999999
242269
>
243-
<!-- Mask -->
270+
<!-- Mask (only show in drawer mode, not in fullscreen) -->
244271
<Transition name="fade">
245272
<div
246-
v-if="show"
273+
v-if="show && !isPageFullscreen"
247274
pos="absolute bottom-0 left-0" w-full h-full bg="black opacity-60"
248275
@click="handleClose"
249276
/>
@@ -302,27 +329,22 @@ watchEffect(() => {
302329
</div>
303330
</Transition>
304331

305-
<!-- Iframe -->
306-
<Transition name="drawer">
332+
<!-- Iframe Container -->
333+
<Transition :name="isPageFullscreen ? 'fade' : 'drawer'">
307334
<div
308335
v-if="show"
309-
:pos="`absolute ${headerShow ? 'top-$bew-top-bar-height' : 'top-0'} left-0`" of-hidden bg="$bew-bg"
310-
rounded="t-$bew-radius" w-full h-full
336+
:class="iframeContainerClasses"
311337
>
312338
<Transition name="fade">
313339
<iframe
314340
v-show="showIframe"
315341
ref="iframeRef"
316342
:src="props.url"
317343
sandbox="allow-same-origin allow-scripts allow-popups allow-forms allow-modals"
318-
:style="{
319-
// Prevent top bar shaking when before the remove-top-bar-without-placeholder class is injected
320-
// When in fullscreen mode (headerShow is false), remove the top offset
321-
top: headerShow && !removeTopBarClassInjected ? `calc(-1 * var(--bew-top-bar-height))` : '0',
322-
}"
344+
:style="iframeStyles"
323345
frameborder="0"
324346
pointer-events-auto
325-
pos="relative left-0"
347+
:pos="isPageFullscreen ? undefined : 'relative left-0'"
326348
allow="fullscreen"
327349
w-full
328350
h-full

0 commit comments

Comments
 (0)