为了方便有需要弹窗确认的交互,可传入回调方法,标题,内容。可以把组件引入到公共头里,使用中央数据总线bug进行调用。
template层
<template>
<div class="notarize-window" :class="{hide: hide}" @click="hide = true">
<div class="notarize-body" @click.stop>
<div class="header" v-if="config.title">{{ config.title }}</div>
<div class="content">{{ config.content }}</div>
<div class="notarize-button-box">
<div class="list" @click.stop="hide = true">取消</div>
<div class="list" @click.stop="submit">确定</div>
</div>
</div>
</div>
</template>
script层 通过ref调用此组件的show方法 需要传入一个content为必传项 如需用到点击确认的回调要传进来一个 success 函数;用作callback回调
<script>
export default {
data() {
return {
hide: true,
success: null,
config: {
title: '',
content: ''
}
}
},
methods: {
submit() {
this.hide = true;
this.success && this.success()
},
/**
* @param {*} params
* title 可选项
* content 必选项
* success 可选性(如需用到回调)
*/
show(params = {}) {
if(!params.content) return console.error('未传入提示内容')
this.hide = false;
this.config.title = params.title;
this.config.content = params.content;
this.success = params.success || null;
}
}
}
</script>
style层
<style scoped>
.notarize-window {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.3);
z-index: 9;
text-align: center;
}
.notarize-window.hide {
display: block;
}
.notarize-body {
width: 480px;
padding-bottom: 30px;
border-radius: 10px;
display: inline-block;
background-color: #fff;
animation: EDIT_WORK_SHOW .3s forwards;
}
.notarize-button-box {
text-align: right;
margin-top: 30px;
padding: 0 50px;
}
.notarize-body>.header {
height: 48px;
line-height: 48px;
font-size: 16px;
padding: 0 30px;
box-sizing: border-box;
color: #00C479;
background-color: #EAFAF6;
border-radius: 10px 10px 0 0;
}
.notarize-body .content {
padding: 0 40px;
margin-top: 30px;
text-align: left;
color: #8b8e9d;
font-size: 16px;
line-height: 24px;
}
.notarize-button-box .list {
display: inline-block;
width: 80px;
height: 30px;
line-height: 30px;
border-radius: 6px;
background-color: #00C479;
color: #fff;
text-align: center;
cursor: pointer;
}
.notarize-button-box .list:nth-child(1) {
margin-right: 20px;
}
@keyframes EDIT_WORK_SHOW {
0% {
opacity: 0;
transform: translateY(-100px);
}
100% {
opacity: 1;
transform: translateY(150px);
}
}
</style>