11<template >
22 <view >
3- <u-popup :zoom =" zoom" mode =" center" :z-index =" uZIndex" v-model =" value" :length =" width" :mask-close-able =" false" :border-radius =" borderRadius" >
3+ <u-popup :zoom =" zoom"
4+ mode =" center" :popup =" false"
5+ :z-index =" uZIndex" v-model =" value"
6+ :length =" width" :mask-close-able =" maskCloseAble"
7+ :border-radius =" borderRadius"
8+ @close =" popupClose"
9+ >
410 <view class =" u-model" >
511 <view v-if =" showTitle" class =" u-model-title u-line-1" :style =" [titleStyle]" >{{ title }}</view >
612 <view class =" u-model-content" >
2329 <view
2430 v-if =" showConfirmButton"
2531 :hover-stay-time =" 100"
26- hover-class =" btn-hover"
32+ : hover-class =" asyncClose ? 'none' : ' btn-hover' "
2733 class =" u-model-footer-button hairline-left"
2834 :style =" [confirmBtnStyle]"
2935 @tap =" confirm"
3036 >
31- {{confirmText}}
37+ <u-loading mode =" circle" :color =" confirmColor" v-if =" loading" ></u-loading >
38+ <block v-else >
39+ {{confirmText}}
40+ </block >
3241 </view >
3342 </view >
3443 </view >
3544 </u-popup >
3645 </view >
3746</template >
38-
47+
3948<script >
4049/**
4150 * modal 模态框
4756 * @property {String | Number} width 模态框宽度(默认600)
4857 * @property {String} content 模态框内容(默认"内容")
4958 * @property {Boolean} show -title 是否显示标题(默认true)
59+ * @property {Boolean} async -close 是否异步关闭,只对确定按钮有效(默认false)
5060 * @property {Boolean} show -confirm-button 是否显示确认按钮(默认true)
5161 * @property {Boolean} show -cancel-button 是否显示取消按钮(默认false)
62+ * @property {Boolean} mask -close-able 是否允许点击遮罩关闭modal(默认false)
5263 * @property {String} confirm -text 确认按钮的文字内容(默认"确认")
5364 * @property {String} cancel -text 取消按钮的文字内容(默认"取消")
5465 * @property {String} cancel -color 取消按钮的颜色(默认"#606266")
@@ -169,8 +180,22 @@ export default {
169180 contentSlot: {
170181 type: Boolean ,
171182 default: false
183+ },
184+ // 是否异步关闭,只对确定按钮有效
185+ asyncClose: {
186+ type: Boolean ,
187+ default: false
188+ },
189+ // 是否允许点击遮罩关闭modal
190+ maskCloseAble: {
191+ type: Boolean ,
192+ default: false
193+ }
194+ },
195+ data () {
196+ return {
197+ loading: false , // 确认按钮是否正在加载中
172198 }
173-
174199 },
175200 computed: {
176201 cancelBtnStyle () {
@@ -183,14 +208,35 @@ export default {
183208 return this .zIndex ? this .zIndex : this .$u .zIndex .popup ;
184209 }
185210 },
211+ watch: {
212+ // 如果是异步关闭时,外部修改v-model的值为false时,重置内部的loading状态
213+ // 避免下次打开的时候,状态混乱
214+ value (n ) {
215+ if (n === true ) this .loading = false ;
216+ }
217+ },
186218 methods: {
187219 confirm () {
188220 this .$emit (' confirm' );
189- this .$emit (' input' , false );
221+ // 异步关闭
222+ if (this .asyncClose ) {
223+ this .loading = true ;
224+ } else {
225+ this .$emit (' input' , false );
226+ }
190227 },
191228 cancel () {
192229 this .$emit (' cancel' );
193230 this .$emit (' input' , false );
231+ // 目前popup弹窗关闭有一个延时操作,此处做一个延时
232+ // 避免确认按钮文字变成了"确定"字样,modal还没消失,造成视觉不好的效果
233+ setTimeout (() => {
234+ this .loading = false ;
235+ }, 300 );
236+ },
237+ // 点击遮罩关闭modal,设置v-model的值为false,否则无法第二次弹起modal
238+ popupClose () {
239+ this .$emit (' input' , false );
194240 }
195241 }
196242};
0 commit comments