1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
| <!--
| 描述: 自定义全局模态框
| 作者: Jack Chen
| 日期: 2020-04-18
| -->
|
| <template>
| <transition name="fade">
| <div class="modal-backdrop" v-if="visible">
| <div class="modal">
| <div class="modal-header">
| {{ title }}
| <i class="iconfont icon-close close" @click="close"></i>
| </div>
| <div class="modal-body">
| {{ content }}
| </div>
| <div class="modal-footer">
| <button type="button" class="btn-close" @click="close" v-if="showCancle">
| {{cancleText ? cancleText : '取消'}}
| </button>
| <button type="button" class="btn-confirm" @click="confirm">
| {{confirmText ? confirmText : '确定'}}
| </button>
| </div>
| </div>
| </div>
| </transition>
| </template>
|
| <script>
|
| export default {
| name: 'Modal',
| props: {
| // modal标题
| title: {
| type: String,
| default: '提示'
| },
| // modal内容
| content: {
| type: String,
| default: ''
| },
| // 是否显示
| visible: {
| type: Boolean,
| default: false
| },
| // 是否显示取消按钮
| showCancle: {
| type: Boolean,
| default: true
| },
| // 确认按钮文字
| confirmText: {
| type: String,
| default: '确认'
| },
| // 取消按钮文字
| cancleText: {
| type: String,
| default: '取消'
| }
| },
| watch: {
| visible (curVal) {
| // 监听visible值的变化
| console.log(curVal)
| }
| },
| methods: {
| // 关闭按钮事件
| close() {
| this.$emit('update:visible', false);
| },
| // 确定按钮事件
| confirm() {
| this.close();
| this.$emit('confirm');
| }
| }
| }
| </script>
|
| <style lang="scss" scoped>
| /* 动画效果 淡入淡出 */
| .fade-enter-active, .fade-leave-active{
| transition: all 0.5s ease;
| }
| .fade-enter, .fade-leave-active{
| opacity: 0;
| }
|
| .modal-backdrop {
| position: fixed;
| top: 0;
| right: 0;
| bottom: 0;
| left: 0;
| background-color: rgba(0,0,0,.5);
| width: 100%;
| height: 100%;
| display: flex;
| justify-content: center;
| align-items: center;
| z-index: 99999;
| .modal {
| position: relative;
| background-color: #fff;
| box-shadow: 2px 2px 20px 1px;
| overflow-x: auto;
| border-radius: 16px;
| width: 400px;
| }
| .modal-header {
| position: relative;
| border-bottom: 1px solid #eee;
| color: #313131;
| padding: 20px;
| font-size: 20px;
| text-align: center;
| .close {
| position: absolute;
| right: 20px;
| cursor: pointer;
| color: #909399;
| font-size: 18px;
| }
| }
| .modal-footer {
| padding: 10px 20px 20px;
| text-align: right;
| .btn-close, .btn-confirm {
| border-radius: 8px;
| cursor: pointer;
| border: none;
| font-size: 16px;
| padding: 12px 20px;
| outline: none;
| }
| .btn-close {
| color: #606266;
| background-color: #fff;
| border: 1px solid #dcdfe6;
| margin-right: 20px;
| &:hover {
| color: #409eff;
| background-color: #ecf5ff;
| }
| }
| .btn-confirm {
| color: #fff;
| background-color: #409eff;
| border-color: #409eff;
| &:hover {
| background-color: #66b1ff;
| }
| }
| }
| .modal-body {
| position: relative;
| padding: 30px 20px;
| font-size: 16px;
| line-height: 22px;
| }
| }
| </style>
|
|