DatePicker
日期选择器
Markup Schema 案例
vue
<script lang="ts" setup>
import { createForm } from '@formily/core'
import { createSchemaField } from '@formily/vue'
import { DatePicker, Form, FormItem, Submit } from '@silver-formily/element-plus'
const form = createForm()
const { SchemaField, SchemaStringField, SchemaArrayField } = createSchemaField({
components: {
FormItem,
DatePicker,
},
})
async function onSubmit(value) {
console.log(value)
}
</script>
<template>
<Form :form="form">
<SchemaField>
<SchemaStringField
name="date"
title="普通日期"
x-decorator="FormItem"
x-component="DatePicker"
/>
<SchemaStringField
name="week"
title="周"
x-decorator="FormItem"
x-component="DatePicker"
:x-component-props="{
type: 'week',
}"
/>
<SchemaStringField
name="month"
title="月"
x-decorator="FormItem"
x-component="DatePicker"
:x-component-props="{
type: 'month',
}"
/>
<SchemaStringField
name="year"
title="年"
x-decorator="FormItem"
x-component="DatePicker"
:x-component-props="{
type: 'year',
}"
/>
<SchemaStringField
name="dateTime"
title="日期时间"
x-decorator="FormItem"
x-component="DatePicker"
:x-component-props="{
type: 'datetime',
}"
/>
<SchemaArrayField
name="dates"
title="多个日期"
x-decorator="FormItem"
x-component="DatePicker"
:x-component-props="{
type: 'dates',
}"
/>
<SchemaArrayField
name="dateRange"
title="日期范围"
x-decorator="FormItem"
x-component="DatePicker"
:x-component-props="{
type: 'daterange',
}"
/>
<SchemaArrayField
name="monthRange"
title="月范围"
x-decorator="FormItem"
x-component="DatePicker"
:x-component-props="{
type: 'monthrange',
}"
/>
<SchemaArrayField
name="dateTimeRange"
title="日期时间范围"
x-decorator="FormItem"
x-component="DatePicker"
:x-component-props="{
type: 'datetimerange',
}"
/>
</SchemaField>
<Submit @submit="onSubmit">
提交
</Submit>
</Form>
</template>JSON Schema 案例
vue
<script lang="ts" setup>
import { createForm } from '@formily/core'
import { createSchemaField } from '@formily/vue'
import { DatePicker, Form, FormItem, Submit } from '@silver-formily/element-plus'
const schema = {
type: 'object',
properties: {
date: {
'type': 'string',
'title': '普通日期',
'x-decorator': 'FormItem',
'x-component': 'DatePicker',
},
week: {
'type': 'string',
'title': '周',
'x-decorator': 'FormItem',
'x-component': 'DatePicker',
'x-component-props': {
type: 'week',
},
},
month: {
'type': 'string',
'title': '月',
'x-decorator': 'FormItem',
'x-component': 'DatePicker',
'x-component-props': {
type: 'month',
},
},
year: {
'type': 'string',
'title': '年',
'x-decorator': 'FormItem',
'x-component': 'DatePicker',
'x-component-props': {
type: 'year',
},
},
dateTime: {
'type': 'string',
'title': '日期时间',
'x-decorator': 'FormItem',
'x-component': 'DatePicker',
'x-component-props': {
type: 'datetime',
},
},
dates: {
'type': 'array',
'title': '多个日期',
'x-decorator': 'FormItem',
'x-component': 'DatePicker',
'x-component-props': {
type: 'dates',
},
},
dateRange: {
'type': 'string',
'title': '日期范围',
'x-decorator': 'FormItem',
'x-component': 'DatePicker',
'x-component-props': {
type: 'daterange',
},
},
monthRange: {
'type': 'string',
'title': '月范围',
'x-decorator': 'FormItem',
'x-component': 'DatePicker',
'x-component-props': {
type: 'monthrange',
},
},
dateTimeRange: {
'type': 'string',
'title': '日期时间范围',
'x-decorator': 'FormItem',
'x-component': 'DatePicker',
'x-component-props': {
type: 'datetimerange',
},
},
},
}
const form = createForm()
const { SchemaField } = createSchemaField({
components: {
FormItem,
DatePicker,
},
})
async function onSubmit(value) {
console.log(value)
}
</script>
<template>
<Form :form="form">
<SchemaField :schema="schema" />
<Submit @submit="onSubmit">
提交
</Submit>
</Form>
</template>Template 案例
vue
<script lang="ts" setup>
import { createForm } from '@formily/core'
import { ArrayField, Field } from '@formily/vue'
import { DatePicker, Form, FormItem, Submit } from '@silver-formily/element-plus'
const form = createForm()
async function onSubmit(value) {
console.log(value)
}
</script>
<template>
<Form :form="form">
<Field
name="date"
title="普通日期"
:decorator="[FormItem]"
:component="[DatePicker]"
/>
<Field
name="week"
title="周"
:decorator="[FormItem]"
:component="[
DatePicker,
{
type: 'week',
},
]"
/>
<Field
name="month"
title="月"
:decorator="[FormItem]"
:component="[
DatePicker,
{
type: 'month',
},
]"
/>
<Field
name="year"
title="年"
:decorator="[FormItem]"
:component="[
DatePicker,
{
type: 'year',
},
]"
/>
<Field
name="dateTime"
title="日期时间"
:decorator="[FormItem]"
:component="[
DatePicker,
{
type: 'datetime',
},
]"
/>
<ArrayField
name="dates"
title="多个日期"
:decorator="[FormItem]"
:component="[
DatePicker,
{
type: 'dates',
},
]"
/>
<ArrayField
name="dateRange"
title="日期范围"
:decorator="[FormItem]"
:component="[
DatePicker,
{
type: 'daterange',
},
]"
/>
<ArrayField
name="monthRange"
title="月范围"
:decorator="[FormItem]"
:component="[
DatePicker,
{
type: 'monthrange',
},
]"
/>
<ArrayField
name="dateTimeRange"
title="日期时间范围"
:decorator="[FormItem]"
:component="[
DatePicker,
{
type: 'datetimerange',
},
]"
/>
<Submit @submit="onSubmit">
提交
</Submit>
</Form>
</template>API
参考 https://cn.element-plus.org/zh-CN/component/date-picker.html