<template>
<div>
<!-- 主弹窗和蒙板 -->
<div v-show="visible && !isMinimized" class="custom-dialog-mask">
<div class="custom-dialog" :style="{ width: width }">
<div class="custom-dialog-header">
<span>{{ title }}</span>
<div class="header-buttons">
<el-button type="primary" @click.stop="toggleMinimize" class="min-btn">最小化</el-button>
<el-button type="danger" class="close-btn" @click.stop="close" plain>关闭</el-button>
</div>
</div>
<div class="custom-dialog-body">
<slot></slot>
<div class="custom-dialog-body-bottom">
温馨提示:当您开启医学白板并最小化界面时,离会前先关闭白板(观看者无需操作)。
</div>
</div>
</div>
</div>
<!-- 最小化后的弹窗 -->
<div v-show="isMinimized" class="minimized-dialog" @click="restoreDialog">
<span>{{ title }}</span>
</div>
</div>
</template>
<script lang="ts">
import { ElMessageBox } from 'element-plus'
import { defineComponent, ref, watch } from 'vue'
export default defineComponent({
name: 'CustomDialog',
props: {
visible: {
type: Boolean,
default: false
},
title: {
type: String,
default: '医学白板'
},
width: {
type: String,
default: '50%'
},
confirmTxt: {
type: String,
default: '是否关闭'
}
},
emits: ['update:visible', 'open', 'close'],
setup(props, { emit }) {
watch(
() => props.visible,
() => {
if (props.visible) {
emit('open')
} else {
emit('close')
}
}
)
const isMinimized = ref(false)
const close = () => {
ElMessageBox.confirm(props.confirmTxt, '温馨提示', {
type: 'warning'
}).then(() => {
emit('update:visible', false)
isMinimized.value = false
})
}
const toggleMinimize = () => {
isMinimized.value = true
}
const restoreDialog = () => {
isMinimized.value = false
emit('update:visible', true)
}
return {
isMinimized,
close,
toggleMinimize,
restoreDialog
}
}
})
</script>
<style scoped lang="scss">
.custom-dialog-mask {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
justify-content: center;
align-items: center;
background-color: rgba(0, 0, 0, 0.5);
z-index: 2000;
}
.custom-dialog {
background: #fff;
border-radius: 4px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.custom-dialog-header {
padding: 15px;
border-bottom: 1px solid #eee;
display: flex;
justify-content: space-between;
align-items: center;
}
.custom-dialog-body {
padding: 20px;
.custom-dialog-body-bottom {
padding-top: 10px;
color: #ff9500;
}
}
.header-buttons {
display: flex;
gap: 10px;
.min-btn{
background: #fff;
color: #379583;
border-color:#379583;
}
.min-btn:hover {
color: #fff;
border-color: #c6e2ff;
background-color:#379583;
}
.close-btn:hover {
color: #fff;
border-color: #c6e2ff;
background-color:#F56C6C;
}
}
.minimized-dialog {
position: fixed;
top: 20px;
right: 20px;
padding: 10px 20px;
border-radius: 4px;
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
cursor: pointer;
display: flex;
align-items: center;
z-index: 2001;
background: #ade2d4;
}
.minimized-dialog:hover {
background: #379583;
color: white;
}
</style>
封装一个有最小化的dialog组件
嘉琪0012025-07-11 17:16
相关推荐
Z兽兽3 小时前
React@18+Vite项目配置env文件SuniaWang3 小时前
《Spring AI + 大模型全栈实战》学习手册系列 · 专题六:《Vue3 前端开发实战:打造企业级 RAG 问答界面》A_nanda4 小时前
根据AI提示排查vue前端项目happymaker06264 小时前
web前端学习日记——DAY05(定位、浮动、视频音频播放)~无忧花开~4 小时前
React状态管理完全指南LegendNoTitle5 小时前
计算机三级等级考试 网络技术 选择题考点详细梳理@大迁世界5 小时前
1.什么是 ReactJS?BJ-Giser6 小时前
Cesium 基于EZ-Tree的植被效果王码码20357 小时前
Flutter for OpenHarmony:Flutter 三方库 algoliasearch 毫秒级云端搜索体验(云原生搜索引擎)发现一只大呆瓜7 小时前
深入浅出 AST:解密 Vite、Babel编译的底层“黑盒”