<template>
<!-- 公用弹窗封装 -->
<div class="popupOuter">
<transition name="leave">
<div class="popup" v-if="show"></div>
</transition>
<transition name="bounce">
<div class="popupMain" v-if="show">
<!-- <div class="popupMain"> -->
<!-- 弹窗主要内容 -->
<slot></slot>
<div
class="popupClose"
@click="closePopup"
v-if="isShowCloseIcon"
></div>
</div>
</transition>
</div>
</template>
<script>
export default {
name: "Popup",
props: {
// 控制弹窗显隐
parPopup: {
type: Boolean,
default: false,
},
// 是否显示底部关闭按钮
isShowCloseIcon: {
type: Boolean,
default: true,
},
},
data() {
return {
show: false,
};
},
created() {},
methods: {
// 关闭弹窗
closePopup() {
this.$emit("update:parPopup", false);
},
},
watch: {
parPopup(newVal) {
this.show = newVal;
if (newVal === true) {
// 弹窗打开时给body添加类名阻止穿透滑动底部页面
document.body.classList.add("modal-open");
} else {
document.body.classList.remove("modal-open");
}
},
},
};
</script>
<style lang="less" scoped>
.popup {
width: 100vw;
height: 100vh;
background: rgba(0, 0, 0, 0.7);
position: fixed;
top: 0;
left: 0;
z-index: 2000;
}
// vant toast组件z-inde未2002
.popupMain {
position: relative;
z-index: 2001;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 6rem;
height: 6rem;
background: #fff;
.popupClose {
width: 0.75rem;
height: 0.75rem;
background: url(https://vncdn.mobi88.cn/fjjh_lkxrl/images/ct0804/popupClose.png)
no-repeat;
background-size: contain;
margin: 0.63rem auto 0;
}
}
// 弹窗动画封装
.bounce-enter-active {
-webkit-animation: bounce-in 0.3s cubic-bezier(0, 0, 0.65, 1.75) 1;
}
.bounce-leave-active {
-webkit-animation: bounce-in 0.3s cubic-bezier(0, 0, 0.65, 1.75) reverse;
}
@-webkit-keyframes bounce-in {
0% {
transform: scale(0);
// 开启硬件加速
opacity: 0;
}
100% {
transform: scale(1);
opacity: 1;
}
}
// 给最外朦层做一个延迟.3s退出的动画。
.leave-enter-active {
-webkit-animation: bounce-out 0.2s cubic-bezier(0, 0, 0.65, 1.75) reverse;
}
.leave-leave-active {
-webkit-animation: bounce-out 0.2s cubic-bezier(0, 0, 0.65, 1.75) 0.2s;
}
@-webkit-keyframes bounce-out {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}
</style>
使用方式:
<popup :parPopup.sync="popup" />