vue3中,封装dialog组件,实现页面级一级弹框、二级弹框和三级弹框(三)——三级弹框

vue3中,封装dialog组件,实现页面级一级弹框、二级弹框和三级弹框(三)——三级弹框

采用element-plus中的dialog组件之嵌套的对话框

https://element-plus.gitee.io/zh-CN/component/dialog.html#%E5%B5%8C%E5%A5%97%E7%9A%84%E5%AF%B9%E8%AF%9D%E6%A1%86

效果

在这里插入图片描述

3-1一级弹框

在这里插入图片描述

3-2二级弹框

在这里插入图片描述

3-3三级弹框效果

在这里插入图片描述

代码

1、引用界面

bookNum.vue

<template>
	<div class="container-box">
       <div style="color: #fff; font-size: 24px" @click="handleNum">点击显示弹框页面</div>
		<!-- 统计列表 -->
		<BookStatistics
            :show-dec="true"
			:is-show="showBookState"
			@is-close="handleCloseBookStatistics"
		></BookStatistics>
    </div>
</template>

<script setup lang="ts" name="bookNum">
import { ref } from "vue";
import BookStatistics from "../components/bookStatistics.vue";    
    //弹框界面
const showBookState = ref(false);
    // 打开弹框
const handleNum = () => {
	showBookState.value = true;
}; 
    //关闭弹框
const handleCloseBookStatistics = () => {
	showBookState.value = false;
};
</script>

<style scoped lang="scss">
.container-box {
	max-height: 200px;
	min-height: 200px;
}
</style>

2、弹框界面

bookStatistics.vue

<template>
	<div class="root-second-box" v-if="props.isShow">
		<Handle @handle-close="handleClose"></Handle>
		<div class="table-model">
			<span @click="details()" style="color: #fff">弹框1-查看分类详情</span>
			<!-- 弹框1  分类 -->
			<el-dialog v-model="dialogVisible" width="100%" :before-close="close" :show-close="false" :fullscreen="true">
				<div class="handle-box">
					<img src="@/assets/svg/close.svg" alt="" srcset="" @click="detailsClose" />
				</div>
				<!-- 弹框2 分类 -->
				<span @click="detailed()" style="color: #fff">弹框2-查看明细详情</span>
			</el-dialog>
			<el-dialog v-model="dialogValue" width="100%" :before-close="close" :show-close="false" :fullscreen="true">
				<div class="handle-box">
					<img src="@/assets/svg/close.svg" alt="" srcset="" @click="detailedClose" />
				</div>

				<!-- 弹框3 明细 -->
				<span>弹框3</span>
			</el-dialog>
		</div>
	</div>
</template>
<script setup lang="ts" name="historyAlarmList">
import Handle from "@/components/common/handle.vue";
import { onMounted, ref } from "vue";

const props = defineProps({
	isShow: Boolean
});
onMounted(() => {
	// dateTime = new Date();
});

// 二级弹框
const dialogVisible = ref(false);
const details = (scope: any) => {
	console.log(scope);
	dialogVisible.value = true;
};
const detailsClose = () => {
	dialogVisible.value = false;
};

// 三级弹框
const dialogValue = ref(false);
const detailed = (scope: any) => {
	console.log(scope);
	dialogValue.value = true;
};
const detailedClose = () => {
	dialogValue.value = false;
};

// 关闭页面
const emit = defineEmits(["isClose"]);
const handleClose = (val: boolean) => {
	emit("isClose", val);
};
</script>
<style scoped lang="scss">
:deep(.el-dialog) {
	.el-dialog__header {
		display: none;
	}
	.dj-dialog-content {
		padding: 0;
		overflow: unset;
	}
}
:deep(.el-dialog.is-fullscreen) {
	background: linear-gradient(#121318, #121318), linear-gradient(#010a1a, #010a1a), linear-gradient(#000000, #000000), #030e1a;
}
.handle-box {
	display: flex;
	position: fixed;
	z-index: 100;
	right: 172px;
	top: 12px;
	> img {
		width: 40px;
		cursor: pointer;
		padding: 12px;
	}
	> img:hover {
		background-color: #2a2d36;
	}
}
</style>

3、公共样式

3.1、定义样式

src\styles\common.scss

// 二级页面样式
.root-second-box {
	position: fixed;
	top: 0;
	left: 0;
	z-index: 3;
	display: flex;
	align-items: center;
	width: 100%;
	height: 100%;
	background: linear-gradient(#121318, #121318), linear-gradient(#010a1a, #010a1a), linear-gradient(#000000, #000000), #030e1a;
}

// 表格公用样式
.table-model {
	box-sizing: border-box;
	width: 100%;
	max-width: 100%;
	height: auto;
	min-height: 80%;
	max-height: 100%;
	padding: 0 120px;
	
}

3.2、引入样式

src\main.ts

// CSS common style sheet (CSS通用样式表)
import "@/styles/common.scss";

4、关闭组件界面

@/components/common/handle.vue

<template>
    <!-- 关闭按钮界面 -->
	<div class="handle-box">
        <!-- <div class="close-box"> -->
		<img src="@/assets/svg/close.svg" alt="" srcset="" @click="handleClose" />
	</div>
</template>
<script setup lang="ts" name="handle">
const emit = defineEmits(["handleClose"]);
const handleClose = () => {
	emit("handleClose", false);
};
</script>
<style scoped lang="scss">
@import "./index.scss";
</style>

index.scss

.handle-box{
	display: flex;
	position: fixed;
	z-index: 99;
	right: 36px;
	top: 12px;
	> img{
		width: 40px;
		cursor: pointer;
		padding: 12px;
	}
	> img:hover{
		background-color: #2A2D36;
	}
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,你需要在父组件引入 Dialog 弹框组件,并在父组件的 template 添加一个触发显示弹框的按钮。例如: ```vue <template> <div> <button @click="showDialog">显示弹框</button> <Dialog v-model="dialogVisible"></Dialog> </div> </template> ``` 在上面的代码,我们添加了一个按钮,当用户点击该按钮时,会触发 showDialog 方法。同时,我们引入了一个名为 Dialog组件,并将它的显示与隐藏与一个名为 dialogVisible 的变量绑定了起来。 接下来,在父组件的 script ,我们需要定义 showDialog 方法以及 dialogVisible 变量。例如: ```vue <script> import Dialog from './Dialog.vue' export default { components: { Dialog }, data() { return { dialogVisible: false } }, methods: { showDialog() { this.dialogVisible = true } } } </script> ``` 在上面的代码,我们首先引入了 Dialog 组件,然后在 data 定义了 dialogVisible 变量,并将其默认值设置为 false。接着,我们定义了一个名为 showDialog 的方法,该方法将 dialogVisible 设置为 true,从而显示 Dialog 弹框组件。 最后,我们需要在 Dialog 弹框组件添加一个关闭按钮,并将其与 dialogVisible 变量绑定起来。例如: ```vue <template> <div> <div class="dialog-mask" v-if="visible" @click="close"></div> <div class="dialog-wrapper" v-if="visible"> <div class="dialog-content"> <div class="dialog-header"> <h3 class="dialog-title">Dialog 标题</h3> <button class="dialog-close-btn" @click="close">×</button> </div> <div class="dialog-body"> <p>Dialog 内容</p> </div> </div> </div> </div> </template> <script> export default { props: { visible: { type: Boolean, required: true } }, methods: { close() { this.$emit('update:visible', false) } } } </script> ``` 在上面的代码,我们添加了一个名为 close 的方法,该方法会将 dialogVisible 设置为 false,并通过 $emit 方法将更新后的值传递给父组件。同时,我们在弹框组件添加了一个关闭按钮,并在按钮的 click 事件调用 close 方法。 这样,当用户点击父组件的按钮时,就会触发 showDialog 方法,从而显示 Dialog 弹框组件。当用户点击弹框的关闭按钮时,会触发 close 方法,从而关闭弹框
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值