<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
相关推荐
炫饭第一名1 天前
速通Canvas指北🦮——基础入门篇王晓枫1 天前
flutter接入三方库运行报错:Error running pod install符方昊1 天前
React 19 对比 React 16 新特性解析ssshooter1 天前
又被 Safari 差异坑了:textContent 拿到的值居然没换行?曲折1 天前
Cesium-气象要素PNG色斑图叠加Forever7_1 天前
Electron 淘汰!新的桌面端框架 更强大、更轻量化不会敲代码11 天前
前端组件化样式隔离实战:React CSS Modules、styled-components 与 Vue scoped 对比Angelial1 天前
Vue3 嵌套路由 KeepAlive:动态缓存与反向配置方案jiayu1 天前
Angular学习笔记24:Angular 响应式表单 FormArray 与 FormGroup 相互嵌套jiayu1 天前
Angular6学习笔记13:HTTP(3)