mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-10-04 15:59:58 +08:00
[improvement] Dialog: support async close (#854)
This commit is contained in:
parent
4a6d3e5d37
commit
f87dd825d7
@ -13,7 +13,7 @@
|
|||||||
<van-button @click="show = true">{{ $t('advancedUsage') }}</van-button>
|
<van-button @click="show = true">{{ $t('advancedUsage') }}</van-button>
|
||||||
<van-dialog
|
<van-dialog
|
||||||
v-model="show"
|
v-model="show"
|
||||||
@confirm="show = false"
|
:asyncConfirm="onClickConfirmAsync"
|
||||||
>
|
>
|
||||||
<van-field
|
<van-field
|
||||||
v-model="username"
|
v-model="username"
|
||||||
@ -59,7 +59,7 @@ export default {
|
|||||||
Dialog.alert({
|
Dialog.alert({
|
||||||
title: this.$t('title'),
|
title: this.$t('title'),
|
||||||
message: this.$t('content')
|
message: this.$t('content')
|
||||||
});
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
onClickAlert2() {
|
onClickAlert2() {
|
||||||
@ -73,6 +73,14 @@ export default {
|
|||||||
title: this.$t('title'),
|
title: this.$t('title'),
|
||||||
message: this.$t('content')
|
message: this.$t('content')
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
onClickConfirmAsync() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve()
|
||||||
|
}, 1000)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -82,7 +82,7 @@ export default {
|
|||||||
If you need to render vue components within a dialog, you can use dialog component.
|
If you need to render vue components within a dialog, you can use dialog component.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-dialog v-model="show" @confirm="onConfirm">
|
<van-dialog v-model="show" :asyncConfirm="onClickConfirmAsync">
|
||||||
<van-field
|
<van-field
|
||||||
v-model="username"
|
v-model="username"
|
||||||
label="Username"
|
label="Username"
|
||||||
@ -110,8 +110,12 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onConfirm() {
|
onClickConfirmAsync() {
|
||||||
this.show = false;
|
return new Promise((resolve, reject) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve()
|
||||||
|
}, 1000)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,6 +128,7 @@ export default {
|
|||||||
| v-model | Whether to show dialog | `Boolean` | - | - |
|
| v-model | Whether to show dialog | `Boolean` | - | - |
|
||||||
| title | Title | `String` | - | - |
|
| title | Title | `String` | - | - |
|
||||||
| message | Message | `String` | - | - |
|
| message | Message | `String` | - | - |
|
||||||
|
| async-confirm | Whether to close async,The incoming function is triggered when you click confirm. | `Function` | - | - |
|
||||||
| show-confirm-button | Whether to show confirm button | `Boolean` | `true` | - |
|
| show-confirm-button | Whether to show confirm button | `Boolean` | `true` | - |
|
||||||
| show-cancel-button | Whether to show cancel button | `Boolean` | `false` | - |
|
| show-cancel-button | Whether to show cancel button | `Boolean` | `false` | - |
|
||||||
| confirm-button-text | Confirm button text | `String` | `Confirm` | - |
|
| confirm-button-text | Confirm button text | `String` | `Confirm` | - |
|
||||||
|
@ -84,7 +84,7 @@ export default {
|
|||||||
如果需要在弹窗内实现更复杂的交互,可以通过组件形式来调用 Dialog
|
如果需要在弹窗内实现更复杂的交互,可以通过组件形式来调用 Dialog
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<van-dialog v-model="show" @confirm="onConfirm">
|
<van-dialog v-model="show" :asyncConfirm="onClickConfirmAsync">
|
||||||
<van-field
|
<van-field
|
||||||
v-model="username"
|
v-model="username"
|
||||||
label="用户名"
|
label="用户名"
|
||||||
@ -112,8 +112,12 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onConfirm() {
|
onClickConfirmAsync() {
|
||||||
this.show = false;
|
return new Promise((resolve, reject) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve();
|
||||||
|
}, 1000)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -126,6 +130,7 @@ export default {
|
|||||||
| v-model | 是否显示弹窗 | `Boolean` | - | - |
|
| v-model | 是否显示弹窗 | `Boolean` | - | - |
|
||||||
| title | 标题 | `String` | - | - |
|
| title | 标题 | `String` | - | - |
|
||||||
| message | 内容 | `String` | - | - |
|
| message | 内容 | `String` | - | - |
|
||||||
|
| async-confirm | dialog是否异步关闭,传入一个返回Promise的函数,在点击确定时触发。 | `Function` | - | - |
|
||||||
| show-confirm-button | 是否展示确认按钮 | `Boolean` | `true` | - |
|
| show-confirm-button | 是否展示确认按钮 | `Boolean` | `true` | - |
|
||||||
| show-cancel-button | 是否展示取消按钮 | `Boolean` | `false` | - |
|
| show-cancel-button | 是否展示取消按钮 | `Boolean` | `false` | - |
|
||||||
| confirm-button-text | 确认按钮的文案 | `String` | `确认` | - |
|
| confirm-button-text | 确认按钮的文案 | `String` | `确认` | - |
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
<van-button
|
<van-button
|
||||||
size="large"
|
size="large"
|
||||||
class="van-dialog__confirm"
|
class="van-dialog__confirm"
|
||||||
|
:loading="confirmButtonLoading"
|
||||||
:class="{ 'van-hairline--left': showCancelButton && showConfirmButton }"
|
:class="{ 'van-hairline--left': showCancelButton && showConfirmButton }"
|
||||||
v-show="showConfirmButton"
|
v-show="showConfirmButton"
|
||||||
@click="handleAction('confirm')"
|
@click="handleAction('confirm')"
|
||||||
@ -38,6 +39,18 @@ import Popup from '../mixins/popup';
|
|||||||
export default create({
|
export default create({
|
||||||
name: 'dialog',
|
name: 'dialog',
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
confirmButtonLoading: false
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
watch: {
|
||||||
|
value(val) {
|
||||||
|
this.confirmButtonLoading = !val && false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
VanButton
|
VanButton
|
||||||
},
|
},
|
||||||
@ -48,6 +61,7 @@ export default create({
|
|||||||
title: String,
|
title: String,
|
||||||
message: String,
|
message: String,
|
||||||
callback: Function,
|
callback: Function,
|
||||||
|
asyncConfirm: Function,
|
||||||
confirmButtonText: String,
|
confirmButtonText: String,
|
||||||
cancelButtonText: String,
|
cancelButtonText: String,
|
||||||
showCancelButton: Boolean,
|
showCancelButton: Boolean,
|
||||||
@ -67,8 +81,17 @@ export default create({
|
|||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
handleAction(action) {
|
handleAction(action) {
|
||||||
|
if ((action === 'confirm') && this.asyncConfirm) {
|
||||||
|
this.confirmButtonLoading = true;
|
||||||
|
this.asyncConfirm(action).then(res => {
|
||||||
|
this.$emit('input', false);
|
||||||
|
}).catch(err => {
|
||||||
|
this.confirmButtonLoading = false;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
this.$emit('input', false);
|
this.$emit('input', false);
|
||||||
this.$emit(action);
|
this.$emit(action);
|
||||||
|
}
|
||||||
this.callback && this.callback(action);
|
this.callback && this.callback(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user