c7add6cf
“wangming”
初始版本开发完毕
|
1
|
<template>
|
25852764
unknown
s
|
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<view>
<u-popup :zoom="zoom" mode="center" :popup="false" :z-index="uZIndex" v-model="value" :length="width"
:mask-close-able="maskCloseAble" :border-radius="borderRadius" @close="popupClose" :negative-top="negativeTop">
<view class="u-model">
<view v-if="showTitle" class="u-model__title u-line-1" :style="[titleStyle]">{{ title }}</view>
<view class="u-model__content">
<view :style="[contentStyle]" v-if="$slots.default || $slots.$default">
<slot />
</view>
<view v-else class="u-model__content__message" :style="[contentStyle]">{{ content }}</view>
</view>
<view class="u-model__footer u-border-top" v-if="showCancelButton || showConfirmButton">
<view v-if="showCancelButton" :hover-stay-time="100" hover-class="u-model__btn--hover" class="u-model__footer__button"
:style="[cancelBtnStyle]" @tap="cancel">
{{cancelText}}
|
c7add6cf
“wangming”
初始版本开发完毕
|
17
|
</view>
|
25852764
unknown
s
|
18
19
20
21
22
23
24
25
26
|
<view v-if="showConfirmButton || $slots['confirm-button']" :hover-stay-time="100" :hover-class="asyncClose ? 'none' : 'u-model__btn--hover'"
class="u-model__footer__button hairline-left" :style="[confirmBtnStyle]" @tap="confirm">
<slot v-if="$slots['confirm-button']" name="confirm-button"></slot>
<block v-else>
<u-loading mode="circle" :color="confirmColor" v-if="loading"></u-loading>
<block v-else>
{{confirmText}}
</block>
</block>
|
c7add6cf
“wangming”
初始版本开发完毕
|
27
28
|
</view>
</view>
|
25852764
unknown
s
|
29
30
31
|
</view>
</u-popup>
</view>
|
c7add6cf
“wangming”
初始版本开发完毕
|
32
33
34
|
</template>
<script>
|
c7add6cf
“wangming”
初始版本开发完毕
|
35
|
/**
|
25852764
unknown
s
|
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
|
* modal 模态框
* @description 弹出模态框,常用于消息提示、消息确认、在当前页面内完成特定的交互操作
* @tutorial https://www.uviewui.com/components/modal.html
* @property {Boolean} value 是否显示模态框
* @property {String | Number} z-index 层级
* @property {String} title 模态框标题(默认"提示")
* @property {String | Number} width 模态框宽度(默认600)
* @property {String} content 模态框内容(默认"内容")
* @property {Boolean} show-title 是否显示标题(默认true)
* @property {Boolean} async-close 是否异步关闭,只对确定按钮有效(默认false)
* @property {Boolean} show-confirm-button 是否显示确认按钮(默认true)
* @property {Stringr | Number} negative-top modal往上偏移的值
* @property {Boolean} show-cancel-button 是否显示取消按钮(默认false)
* @property {Boolean} mask-close-able 是否允许点击遮罩关闭modal(默认false)
* @property {String} confirm-text 确认按钮的文字内容(默认"确认")
* @property {String} cancel-text 取消按钮的文字内容(默认"取消")
* @property {String} cancel-color 取消按钮的颜色(默认"#606266")
* @property {String} confirm-color 确认按钮的文字内容(默认"#2979ff")
* @property {String | Number} border-radius 模态框圆角值,单位rpx(默认16)
* @property {Object} title-style 自定义标题样式,对象形式
* @property {Object} content-style 自定义内容样式,对象形式
* @property {Object} cancel-style 自定义取消按钮样式,对象形式
* @property {Object} confirm-style 自定义确认按钮样式,对象形式
* @property {Boolean} zoom 是否开启缩放模式(默认true)
* @event {Function} confirm 确认按钮被点击
* @event {Function} cancel 取消按钮被点击
* @example <u-modal :src="title" :content="content"></u-modal>
|
c7add6cf
“wangming”
初始版本开发完毕
|
63
64
65
|
*/
export default {
name: 'u-modal',
|
25852764
unknown
s
|
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
170
171
172
173
174
175
176
177
178
179
180
|
props: {
// 是否显示Modal
value: {
type: Boolean,
default: false
},
// 层级z-index
zIndex: {
type: [Number, String],
default: ''
},
// 标题
title: {
type: [String],
default: '提示'
},
// 弹窗宽度,可以是数值(rpx),百分比,auto等
width: {
type: [Number, String],
default: 600
},
// 弹窗内容
content: {
type: String,
default: '内容'
},
// 是否显示标题
showTitle: {
type: Boolean,
default: true
},
// 是否显示确认按钮
showConfirmButton: {
type: Boolean,
default: true
},
// 是否显示取消按钮
showCancelButton: {
type: Boolean,
default: false
},
// 确认文案
confirmText: {
type: String,
default: '确认'
},
// 取消文案
cancelText: {
type: String,
default: '取消'
},
// 确认按钮颜色
confirmColor: {
type: String,
default: '#2979ff'
},
// 取消文字颜色
cancelColor: {
type: String,
default: '#606266'
},
// 圆角值
borderRadius: {
type: [Number, String],
default: 16
},
// 标题的样式
titleStyle: {
type: Object,
default () {
return {}
}
},
// 内容的样式
contentStyle: {
type: Object,
default () {
return {}
}
},
// 取消按钮的样式
cancelStyle: {
type: Object,
default () {
return {}
}
},
// 确定按钮的样式
confirmStyle: {
type: Object,
default () {
return {}
}
},
// 是否开启缩放效果
zoom: {
type: Boolean,
default: true
},
// 是否异步关闭,只对确定按钮有效
asyncClose: {
type: Boolean,
default: false
},
// 是否允许点击遮罩关闭modal
maskCloseAble: {
type: Boolean,
default: false
},
// 给一个负的margin-top,往上偏移,避免和键盘重合的情况
negativeTop: {
type: [String, Number],
default: 0
}
},
|
c7add6cf
“wangming”
初始版本开发完毕
|
181
182
|
data() {
return {
|
25852764
unknown
s
|
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
loading: false, // 确认按钮是否正在加载中
}
},
computed: {
cancelBtnStyle() {
return Object.assign({
color: this.cancelColor
}, this.cancelStyle);
},
confirmBtnStyle() {
return Object.assign({
color: this.confirmColor
}, this.confirmStyle);
},
uZIndex() {
return this.zIndex ? this.zIndex : this.$u.zIndex.popup;
|
c7add6cf
“wangming”
初始版本开发完毕
|
199
200
201
|
}
},
watch: {
|
25852764
unknown
s
|
202
203
204
205
|
// 如果是异步关闭时,外部修改v-model的值为false时,重置内部的loading状态
// 避免下次打开的时候,状态混乱
value(n) {
if (n === true) this.loading = false;
|
c7add6cf
“wangming”
初始版本开发完毕
|
206
207
208
|
}
},
methods: {
|
25852764
unknown
s
|
209
210
|
confirm() {
// 异步关闭
|
c7add6cf
“wangming”
初始版本开发完毕
|
211
212
|
if (this.asyncClose) {
this.loading = true;
|
25852764
unknown
s
|
213
214
|
} else {
this.$emit('input', false);
|
c7add6cf
“wangming”
初始版本开发完毕
|
215
|
}
|
25852764
unknown
s
|
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
this.$emit('confirm');
},
cancel() {
this.$emit('cancel');
this.$emit('input', false);
// 目前popup弹窗关闭有一个延时操作,此处做一个延时
// 避免确认按钮文字变成了"确定"字样,modal还没消失,造成视觉不好的效果
setTimeout(() => {
this.loading = false;
}, 300);
},
// 点击遮罩关闭modal,设置v-model的值为false,否则无法第二次弹起modal
popupClose() {
this.$emit('input', false);
},
// 清除加载中的状态
clearLoading() {
this.loading = false;
|
c7add6cf
“wangming”
初始版本开发完毕
|
234
235
|
}
}
|
25852764
unknown
s
|
236
|
};
|
c7add6cf
“wangming”
初始版本开发完毕
|
237
238
239
|
</script>
<style lang="scss" scoped>
|
25852764
unknown
s
|
240
|
@import "../../libs/css/style.components.scss";
|
c7add6cf
“wangming”
初始版本开发完毕
|
241
|
|
25852764
unknown
s
|
242
243
|
.u-model {
height: auto;
|
c7add6cf
“wangming”
初始版本开发完毕
|
244
|
overflow: hidden;
|
25852764
unknown
s
|
245
246
247
248
249
250
|
font-size: 32rpx;
background-color: #fff;
&__btn--hover {
background-color: rgb(230, 230, 230);
}
|
c7add6cf
“wangming”
初始版本开发完毕
|
251
252
|
&__title {
|
25852764
unknown
s
|
253
254
|
padding-top: 48rpx;
font-weight: 500;
|
c7add6cf
“wangming”
初始版本开发完毕
|
255
|
text-align: center;
|
25852764
unknown
s
|
256
|
color: $u-main-color;
|
c7add6cf
“wangming”
初始版本开发完毕
|
257
258
259
|
}
&__content {
|
25852764
unknown
s
|
260
261
262
263
|
&__message {
padding: 48rpx;
font-size: 30rpx;
text-align: center;
|
c7add6cf
“wangming”
初始版本开发完毕
|
264
|
color: $u-content-color;
|
c7add6cf
“wangming”
初始版本开发完毕
|
265
266
267
|
}
}
|
25852764
unknown
s
|
268
269
|
&__footer {
@include vue-flex;
|
c7add6cf
“wangming”
初始版本开发完毕
|
270
|
|
25852764
unknown
s
|
271
|
&__button {
|
c7add6cf
“wangming”
初始版本开发完毕
|
272
|
flex: 1;
|
25852764
unknown
s
|
273
274
275
276
277
278
279
|
height: 100rpx;
line-height: 100rpx;
font-size: 32rpx;
box-sizing: border-box;
cursor: pointer;
text-align: center;
border-radius: 4rpx;
|
c7add6cf
“wangming”
初始版本开发完毕
|
280
281
282
283
|
}
}
}
</style>
|