docs(Form): add DatetimePicker demo

This commit is contained in:
陈嘉涵 2020-02-11 14:45:47 +08:00
parent 3f33b6de47
commit ed16eb7a59
8 changed files with 163 additions and 6 deletions

View File

@ -82,7 +82,6 @@ export default {
currentDate: new Date() currentDate: new Date()
}; };
}, },
methods: { methods: {
formatter(type, val) { formatter(type, val) {
if (type === 'year') { if (type === 'year') {
@ -134,7 +133,6 @@ export default {
currentTime: '12:00' currentTime: '12:00'
}; };
}, },
methods: { methods: {
filter(type, options) { filter(type, options) {
if (type === 'minute') { if (type === 'minute') {

View File

@ -84,7 +84,6 @@ export default {
currentDate: new Date() currentDate: new Date()
}; };
}, },
methods: { methods: {
formatter(type, val) { formatter(type, val) {
if (type === 'year') { if (type === 'year') {
@ -138,7 +137,6 @@ export default {
currentTime: '12:00' currentTime: '12:00'
}; };
}, },
methods: { methods: {
filter(type, options) { filter(type, options) {
if (type === 'minute') { if (type === 'minute') {

View File

@ -204,7 +204,7 @@ export default {
name="picker" name="picker"
:value="value" :value="value"
label="Picker" label="Picker"
placeholder="Picker" placeholder="Select city"
@click="showPicker = true" @click="showPicker = true"
/> />
<van-popup v-model="showPicker" position="bottom"> <van-popup v-model="showPicker" position="bottom">
@ -238,6 +238,52 @@ export default {
}; };
``` ```
### Field Type - DatetimePicker
```html
<van-field
readonly
clickable
name="picker"
:value="value"
label="DatetimePicker"
placeholder="Select time"
@click="showPicker = true"
/>
<van-popup v-model="showPicker" position="bottom">
<van-datetime-picker
v-model="currentDate"
type="date"
@confirm="onConfirm"
@cancel="onCancel"
/>
</van-popup>
```
```js
export default {
data() {
return {
value: '',
showPicker: false,
currentDate: new Date(),
};
},
methods: {
formatDate(date) {
return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
},
onConfirm(date) {
this.value = this.formatDate(date);
this.showPicker = false;
},
onCancel() {
this.showPicker = false;
},
},
};
```
## API ## API
### Props ### Props

View File

@ -244,6 +244,52 @@ export default {
}; };
``` ```
### 表单项类型 - 时间选择器
```html
<van-field
readonly
clickable
name="picker"
:value="value"
label="时间选择"
placeholder="点击选择时间"
@click="showPicker = true"
/>
<van-popup v-model="showPicker" position="bottom">
<van-datetime-picker
v-model="currentDate"
type="date"
@confirm="onConfirm"
@cancel="onCancel"
/>
</van-popup>
```
```js
export default {
data() {
return {
value: '',
showPicker: false,
currentDate: new Date(),
};
},
methods: {
formatDate(date) {
return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
},
onConfirm(date) {
this.value = this.formatDate(date);
this.showPicker = false;
},
onCancel() {
this.showPicker = false;
},
},
};
```
## API ## API
### Props ### Props

View File

@ -48,6 +48,7 @@
</van-field> </van-field>
<field-type-picker /> <field-type-picker />
<field-type-datetime-picker />
<div style="margin: 16px 16px 0;"> <div style="margin: 16px 16px 0;">
<van-button type="info" round block>{{ $t('submit') }}</van-button> <van-button type="info" round block>{{ $t('submit') }}</van-button>
@ -58,6 +59,7 @@
<script> <script>
import FieldTypePicker from './FieldTypePicker'; import FieldTypePicker from './FieldTypePicker';
import FieldTypeDatetimePicker from './FieldTypeDatetimePicker';
export default { export default {
i18n: { i18n: {
@ -93,6 +95,7 @@ export default {
components: { components: {
FieldTypePicker, FieldTypePicker,
FieldTypeDatetimePicker,
}, },
data() { data() {

View File

@ -0,0 +1,57 @@
<template>
<div>
<van-field
readonly
clickable
name="picker"
:value="value"
:label="$t('label')"
:placeholder="$t('placeholder')"
@click="showPicker = true"
/>
<van-popup v-model="showPicker" position="bottom">
<van-datetime-picker
v-model="currentDate"
type="date"
@confirm="onConfirm"
@cancel="onCancel"
/>
</van-popup>
</div>
</template>
<script>
export default {
i18n: {
'zh-CN': {
label: '时间选择',
placeholder: '点击选择时间',
},
'en-US': {
label: 'Datetime Picker',
placeholder: 'Select time',
},
},
data() {
return {
value: '',
showPicker: false,
currentDate: new Date(),
};
},
methods: {
formatDate(date) {
return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
},
onConfirm(date) {
this.value = this.formatDate(date);
this.showPicker = false;
},
onCancel() {
this.showPicker = false;
},
},
};
</script>

View File

@ -30,7 +30,7 @@ export default {
}, },
'en-US': { 'en-US': {
picker: 'Picker', picker: 'Picker',
placeholder: 'Picker', placeholder: 'Select city',
textColumns: ['Delaware', 'Florida', 'Georqia', 'Indiana', 'Maine'], textColumns: ['Delaware', 'Florida', 'Georqia', 'Indiana', 'Maine'],
}, },
}, },

View File

@ -166,6 +166,15 @@ exports[`renders demo correctly 1`] = `
</div> </div>
<!----> <!---->
</div> </div>
<div>
<div role="button" tabindex="0" class="van-cell van-cell--clickable van-field">
<div class="van-cell__title van-field__label"><span>时间选择</span></div>
<div class="van-cell__value van-field__value">
<div class="van-field__body"><input type="text" name="picker" readonly="readonly" placeholder="点击选择时间" class="van-field__control"></div>
</div>
</div>
<!---->
</div>
<div style="margin: 16px 16px 0px;"><button class="van-button van-button--info van-button--normal van-button--block van-button--round"><span class="van-button__text">提交</span></button></div> <div style="margin: 16px 16px 0px;"><button class="van-button van-button--info van-button--normal van-button--block van-button--round"><span class="van-button__text">提交</span></button></div>
</form> </form>
</div> </div>