[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 Page from '../../common/page';
import Dialog from '../../dist/dialog/dialog'; import Dialog from '../../dist/dialog/dialog';
const message = '有赞是一家零售科技公司,致力于成为商家服务领域里最被信任的引领者'; const message = '代码是写出来给人看的,附带能在机器上运行';
Page({ Page({
data: { data: {
show: false, show: false
username: '',
password: ''
}, },
showCustomDialog() { showCustomDialog() {
@ -38,17 +36,25 @@ Page({
}); });
}, },
onClose(event) { onClickAsyncClose() {
if (event.detail === 'confirm') { Dialog.confirm({
setTimeout(() => { title: '标题',
this.setData({ message,
show: false asyncClose: true
}); })
}, 1000); .then(() => {
} else { setTimeout(() => {
this.setData({ Dialog.close();
show: false }, 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 <van-button
plain plain
type="primary" type="primary"
class="demo-margin-right" class="demo-margin-right"
bind:click="onClickAlert" bind:click="onClickAlert"
> >
消息提示 提示弹窗
</van-button> </van-button>
<van-button <van-button
plain plain
type="primary" type="primary"
bind:click="onClickAlert2" bind:click="onClickAlert2"
> >
无标题提示 提示弹窗(无标题)
</van-button> </van-button>
</demo-block> </demo-block>
<demo-block title="消息确认" padding> <demo-block title="确认弹窗" padding>
<van-button <van-button
plain plain
type="primary" type="primary"
bind:click="onClickConfirm" bind:click="onClickConfirm"
> >
消息确认 确认弹窗
</van-button>
</demo-block>
<demo-block title="异步关闭" padding>
<van-button
plain
type="primary"
bind:click="onClickAsyncClose"
>
异步关闭
</van-button> </van-button>
</demo-block> </demo-block>
@ -36,25 +46,15 @@
</van-button> </van-button>
<van-dialog <van-dialog
use-slot use-slot
async-close
show="{{ show }}" show="{{ show }}"
show-cancel-button show-cancel-button
transition="fade"
bind:close="onClose" bind:close="onClose"
confirm-button-open-type="getUserInfo" confirm-button-open-type="getUserInfo"
bind:getuserinfo="getUserInfo" bind:getuserinfo="getUserInfo"
> >
<van-field <image
value="{{ username }}" class="demo-image"
label="用户名" src="https://img.yzcdn.cn/public_files/2017/09/05/4e3ea0898b1c2c416eec8c11c5360833.jpg"
placeholder="请输入用户名"
/>
<van-field
value="{{ password }}"
type="password"
label="密码"
border="{{ false }}"
placeholder="请输入密码"
/> />
</van-dialog> </van-dialog>
</demo-block> </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 ```html
<van-dialog <van-dialog
use-slot use-slot
async-close
show="{{ show }}" show="{{ show }}"
show-cancel-button show-cancel-button
confirm-button-open-type="getUserInfo" confirm-button-open-type="getUserInfo"
bind:close="onClose" bind:close="onClose"
bind:getuserinfo="getUserInfo" bind:getuserinfo="getUserInfo"
> >
<van-field <image src="https://img.yzcdn.cn/1.jpg" />
value="{{ username }}"
label="用户名"
placeholder="请输入用户名"
/>
<van-field
value="{{ password }}"
type="password"
label="密码"
:border="false"
placeholder="请输入密码"
/>
</van-dialog> </van-dialog>
``` ```
```js ```js
Page({ Page({
data: { data: {
show: true, show: true
username: '',
password: ''
}, },
onClose(event) { getUserInfo(event) {
if (event.detail === 'confirm') { console.log(event.detail);
// 异步关闭弹窗 },
setTimeout(() => {
this.setData({ onClose() {
show: false this.setData({ close: false });
});
}, 1000);
} else {
this.setData({
show: false
});
}
} }
}); });
``` ```

View File

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