为弹窗增加全屏功能

This commit is contained in:
2025-12-16 22:36:24 +08:00
parent 37760f685c
commit 5f9b684604
3 changed files with 65 additions and 19 deletions

View File

@@ -1,4 +1,5 @@
<script setup> <script setup>
import { ref } from 'vue'
const emit = defineEmits(['close']) const emit = defineEmits(['close'])
const props = defineProps({ const props = defineProps({
@@ -30,8 +31,18 @@ const props = defineProps({
}, },
}) })
const isMaximized = ref(false)
const closeModal = () => emit('close') const closeModal = () => emit('close')
const getDimensionValue = (value) => { const toggleMaximize = () => {
isMaximized.value = !isMaximized.value
emit('maximize', isMaximized.value)
}
const getDimensionValue = (value, dimension) => {
if (isMaximized.value) {
return '100%'
}
if (typeof value === 'number') { if (typeof value === 'number') {
return `${value}px`; return `${value}px`;
} }
@@ -40,9 +51,12 @@ const getDimensionValue = (value) => {
</script> </script>
<template> <template>
<div class="modal-mask"> <div class="modal-mask">
<div class="modal-container" :class="theme" :style="{width: getDimensionValue(width), height: getDimensionValue(height),}"> <div class="modal-container" :class="[theme, { 'maximized': isMaximized }]" :style="{ width: getDimensionValue(width), height: getDimensionValue(height), maxWidth: isMaximized ? '100vw' : 'none', maxHeight: isMaximized ? '100vh' : 'none'}">
<header class="modal-header"> <header class="modal-header">
<div class="modal-header-buttons">
<button class="modal-close-btn" @click="closeModal"></button> <button class="modal-close-btn" @click="closeModal"></button>
<button class="modal-maximize-btn" @click="toggleMaximize"></button>
</div>
<header class="modal-header-title">{{ title }}</header> <header class="modal-header-title">{{ title }}</header>
</header> </header>
<div class="modal-main"> <div class="modal-main">
@@ -97,36 +111,64 @@ const getDimensionValue = (value) => {
background-color: #3a3a3a; background-color: #3a3a3a;
border-bottom: 1px solid #444; border-bottom: 1px solid #444;
} }
.modal-close-btn { .modal-header-buttons {
position: absolute; position: absolute;
top: 8px;
left: 10px; left: 10px;
top: 8px;
display: flex;
gap: 8px;
height: 20px;
}
.modal-close-btn,
.modal-maximize-btn {
width: 16px; width: 16px;
height: 16px; height: 16px;
border-radius: 50%; border-radius: 50%;
border: none; border: none;
background-color: #ff5b5b;
color: #666;
font-weight: bold;
cursor: default; cursor: default;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
position: relative;
flex-shrink: 0;
}
.modal-close-btn {
background-color: #ff5b5b;
}
.modal-maximize-btn {
background-color: #37b600;
}
.modal-close-btn::before,
.modal-maximize-btn::before {
position: absolute;
font-family: "Font Awesome 7 Free";
font-weight: bolder;
font-size: 11px;
color: #555;
opacity: 0;
transition: opacity 0.2s ease;
} }
.modal-close-btn::before { .modal-close-btn::before {
content: "\f00d"; content: "\f00d";
font-family: "Font Awesome 7 Free";
font-weight: bolder;
display: none;
font-size: 11px; font-size: 11px;
color: #555;
} }
.modal-close-btn:hover::before { .modal-maximize-btn::before {
display: block; content: "\f424";
font-size: 8px;
}
.modal-container.maximized .modal-maximize-btn::before {
content: "\f422";
}
.modal-header-buttons:hover .modal-close-btn::before,
.modal-header-buttons:hover .modal-maximize-btn::before {
opacity: 1;
} }
.modal-close-btn:active { .modal-close-btn:active {
background-color: #c64848; background-color: #c64848;
} }
.modal-maximize-btn:active {
background-color: #288500;
}
.modal-header-title { .modal-header-title {
position: absolute; position: absolute;
top: 4px; top: 4px;

View File

@@ -1,19 +1,23 @@
<script setup> <script setup>
import { onMounted, onUnmounted } from 'vue' import { onMounted, onUnmounted } from 'vue'
import { useRouter } from 'vue-router' import { useRoute, useRouter } from 'vue-router'
const route = useRoute()
const router = useRouter() const router = useRouter()
let timer = null let timer = null
onMounted(() => { onMounted(() => {
if (route.path === '/') {
timer = setTimeout(() => { timer = setTimeout(() => {
router.push('/datascreen') router.push('/datascreen')
}, 3000) }, 3000)
}
}) })
onUnmounted(() => { onUnmounted(() => {
if (timer) { if (timer) {
clearTimeout(timer) clearTimeout(timer)
timer = null
} }
}) })
</script> </script>