[Doc] Dialog: update demo (#1579)

This commit is contained in:
neverland 2019-04-28 15:25:20 +08:00 committed by GitHub
parent 0d09d168c8
commit 567c843d17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 74 additions and 64 deletions

View File

@ -1,13 +1,11 @@
import Page from '../../common/page';
import Dialog from '../../dist/dialog/dialog';
const message = '有赞是一家零售科技公司,致力于成为商家服务领域里最被信任的引领者';
const message = '代码是写出来给人看的,附带能在机器上运行';
Page({
data: {
show: false,
username: '',
password: ''
show: false
},
showCustomDialog() {
@ -38,17 +36,25 @@ Page({
});
},
onClose(event) {
if (event.detail === 'confirm') {
setTimeout(() => {
this.setData({
show: false
});
}, 1000);
} else {
this.setData({
show: false
onClickAsyncClose() {
Dialog.confirm({
title: '标题',
message,
asyncClose: true
})
.then(() => {
setTimeout(() => {
Dialog.close();
}, 1000);
})
.catch(() => {
Dialog.close();
});
}
},
onClose(event) {
this.setData({
show: false
});
}
});

View File

@ -1,28 +1,38 @@
<demo-block title="消息提示" padding>
<demo-block title="提示弹窗" padding>
<van-button
plain
type="primary"
class="demo-margin-right"
bind:click="onClickAlert"
>
消息提示
提示弹窗
</van-button>
<van-button
plain
type="primary"
bind:click="onClickAlert2"
>
无标题提示
提示弹窗(无标题)
</van-button>
</demo-block>
<demo-block title="消息确认" padding>
<demo-block title="确认弹窗" padding>
<van-button
plain
type="primary"
bind:click="onClickConfirm"
>
消息确认
确认弹窗
</van-button>
</demo-block>
<demo-block title="异步关闭" padding>
<van-button
plain
type="primary"
bind:click="onClickAsyncClose"
>
异步关闭
</van-button>
</demo-block>
@ -36,25 +46,15 @@
</van-button>
<van-dialog
use-slot
async-close
show="{{ show }}"
show-cancel-button
transition="fade"
bind:close="onClose"
confirm-button-open-type="getUserInfo"
bind:getuserinfo="getUserInfo"
>
<van-field
value="{{ username }}"
label="用户名"
placeholder="请输入用户名"
/>
<van-field
value="{{ password }}"
type="password"
label="密码"
border="{{ false }}"
placeholder="请输入密码"
<image
class="demo-image"
src="https://img.yzcdn.cn/public_files/2017/09/05/4e3ea0898b1c2c416eec8c11c5360833.jpg"
/>
</van-dialog>
</demo-block>

View File

@ -0,0 +1,5 @@
.demo-image {
width: 100%;
padding: 25px 20px 0;
box-sizing: border-box;
}

View File

@ -64,56 +64,55 @@ Dialog.confirm({
});
```
#### 异步关闭
设置`asyncClose`属性开启异步关闭,开启后可以手动调用`Dialog.close`方法关闭弹窗
```javascript
Dialog.confirm({
title: '标题',
message: '弹窗内容'
asyncClose: true
})
.then(() => {
setTimeout(() => {
Dialog.close();
}, 1000);
})
.catch(() => {
Dialog.close();
});
```
#### 组件调用
通过组件调用 Dialog 时,可以实现自定义弹窗内容、异步关闭、监听微信开放能力回调事件,具体可以参考下面的示例
通过组件调用 Dialog 时,可以实现自定义弹窗内容、监听微信开放能力回调事件等功能,具体参考下例
```html
<van-dialog
use-slot
async-close
show="{{ show }}"
show-cancel-button
confirm-button-open-type="getUserInfo"
bind:close="onClose"
bind:getuserinfo="getUserInfo"
>
<van-field
value="{{ username }}"
label="用户名"
placeholder="请输入用户名"
/>
<van-field
value="{{ password }}"
type="password"
label="密码"
:border="false"
placeholder="请输入密码"
/>
<image src="https://img.yzcdn.cn/1.jpg" />
</van-dialog>
```
```js
Page({
data: {
show: true,
username: '',
password: ''
show: true
},
onClose(event) {
if (event.detail === 'confirm') {
// 异步关闭弹窗
setTimeout(() => {
this.setData({
show: false
});
}, 1000);
} else {
this.setData({
show: false
});
}
getUserInfo(event) {
console.log(event.detail);
},
onClose() {
this.setData({ close: false });
}
});
```

View File

@ -100,7 +100,7 @@ VantComponent({
}
this.$emit('close', action);
//把 dialog 实例传递出去,可以通过 stopLoading() 在外部关闭按钮的 loading
// 把 dialog 实例传递出去,可以通过 stopLoading() 在外部关闭按钮的 loading
this.$emit(action, { dialog: this });
const callback = this.data[action === 'confirm' ? 'onConfirm' : 'onCancel'];