# Editable
局部编辑器,对于一些空间要求较高的表单区域可以使用该组件
Editable 组件相当于是 FormItem 组件的变体,所以通常放在 decorator 中
# Markup Schema 案例
N/A
N/A
虚拟节点容器
对象节点容器
<template>
<FormProvider :form="form">
<SchemaField>
<SchemaStringField
name="date"
title="日期"
x-decorator="Editable"
x-component="DatePicker"
/>
<SchemaStringField
name="input"
title="输入框"
x-decorator="Editable"
x-component="Input"
/>
<SchemaVoidField
name="void"
title="虚拟节点容器"
x-component="Editable.Popover"
:x-reactions="
(field) => {
field.title = field.query('.void.date2').get('value') || field.title
}
"
>
<SchemaStringField
name="date2"
title="日期"
x-decorator="FormItem"
x-component="DatePicker"
/>
<SchemaStringField
name="input2"
title="输入框"
x-decorator="FormItem"
x-component="Input"
/>
</SchemaVoidField>
<SchemaObjectField
name="object"
title="对象节点容器"
x-component="Editable.Popover"
:x-reactions="
(field) => {
field.title = (field.value && field.value.date) || field.title
}
"
>
<SchemaStringField
name="date"
title="日期"
x-decorator="FormItem"
x-component="DatePicker"
/>
<SchemaStringField
name="input"
title="输入框"
x-decorator="FormItem"
x-component="Input"
/>
</SchemaObjectField>
</SchemaField>
<FormButtonGroup>
<Submit @submit="log">提交</Submit>
</FormButtonGroup>
</FormProvider>
</template>
<script>
import { createForm } from '@formily/core'
import { FormProvider, createSchemaField } from '@formily/vue'
import {
FormButtonGroup,
FormItem,
Submit,
Input,
DatePicker,
Editable,
} from '@formily/antdv'
import { Button } from 'ant-design-vue'
const SchemaField = createSchemaField({
components: {
FormItem,
Input,
DatePicker,
Editable,
},
})
export default {
components: {
FormButtonGroup,
FormProvider,
Button,
Submit,
...SchemaField,
},
data() {
const form = createForm()
return {
form,
}
},
methods: {
log(values) {
console.log(values)
},
},
}
</script>
<style lang="scss" scoped></style>
# JSON Schema 案例
N/A
N/A
虚拟节点容器
对象节点容器
<template>
<FormProvider :form="form">
<SchemaField :schema="schema" />
<FormButtonGroup>
<Submit @submit="log">提交</Submit>
</FormButtonGroup>
</FormProvider>
</template>
<script>
import { createForm } from '@formily/core'
import { FormProvider, createSchemaField } from '@formily/vue'
import {
FormButtonGroup,
FormItem,
Submit,
Input,
DatePicker,
Editable,
} from '@formily/antdv'
const { SchemaField } = createSchemaField({
components: {
FormItem,
Input,
DatePicker,
Editable,
},
})
const schema = {
type: 'object',
properties: {
date: {
type: 'string',
title: '日期',
'x-decorator': 'Editable',
'x-component': 'DatePicker',
},
input: {
type: 'string',
title: '输入框',
'x-decorator': 'Editable',
'x-component': 'Input',
},
void: {
type: 'void',
title: '虚拟节点容器',
'x-component': 'Editable.Popover',
'x-reactions':
"{{(field) => field.title = field.query('.void.date2').get('value') || field.title}}",
properties: {
date2: {
type: 'string',
title: '日期',
'x-decorator': 'FormItem',
'x-component': 'DatePicker',
},
input2: {
type: 'string',
title: '输入框',
'x-decorator': 'FormItem',
'x-component': 'Input',
},
},
},
iobject: {
type: 'object',
title: '对象节点容器',
'x-component': 'Editable.Popover',
'x-reactions':
'{{(field) => field.title = field.value && field.value.date || field.title}}',
properties: {
date: {
type: 'string',
title: '日期',
'x-decorator': 'FormItem',
'x-component': 'DatePicker',
},
input: {
type: 'string',
title: '输入框',
'x-decorator': 'FormItem',
'x-component': 'Input',
},
},
},
},
}
export default {
components: {
FormButtonGroup,
FormProvider,
Submit,
SchemaField,
},
data() {
const form = createForm()
return {
schema,
form,
}
},
methods: {
log(values) {
console.log(values)
},
},
}
</script>
<style lang="scss" scoped></style>
# Template 案例
N/A
N/A
虚拟节点容器
对象节点容器
<template>
<FormProvider :form="form">
<Field
name="date"
title="日期"
:decorator="[Editable]"
:component="[DatePicker]"
/>
<Field
name="input"
title="输入框"
:decorator="[Editable]"
:component="[Input]"
/>
<VoidField
name="void"
title="虚拟节点容器"
:component="[Editable.Popover]"
:reactions="
(field) => {
field.title = field.query('.void.date2').get('value') || field.title
}
"
>
<Field
name="date2"
title="日期"
:decorator="[FormItem]"
:component="[DatePicker]"
/>
<Field
name="input2"
title="输入框"
:decorator="[FormItem]"
:component="[Input]"
/>
</VoidField>
<ObjectField
name="iobject"
title="对象节点容器"
:component="[Editable.Popover]"
:reactions="
(field) => {
field.title = (field.value && field.value.date) || field.title
}
"
>
<Field
name="date"
title="日期"
:decorator="[FormItem]"
:component="[DatePicker]"
/>
<Field
name="input"
title="输入框"
:decorator="[FormItem]"
:component="[Input]"
/>
</ObjectField>
<FormButtonGroup>
<Submit @submit="log">提交</Submit>
</FormButtonGroup>
</FormProvider>
</template>
<script>
import { createForm } from '@formily/core'
import { FormProvider, Field, VoidField, ObjectField } from '@formily/vue'
import {
FormButtonGroup,
FormItem,
Submit,
Input,
DatePicker,
Editable,
} from '@formily/antdv'
export default {
components: {
FormButtonGroup,
FormProvider,
Submit,
Field,
VoidField,
ObjectField,
},
data() {
const form = createForm()
return {
FormItem,
Input,
DatePicker,
Editable,
form,
}
},
methods: {
log(values) {
console.log(values)
},
},
}
</script>
<style lang="scss" scoped></style>
# API
# Editable
内联编辑
参考 https://antdv.com/components/form-cn/#Form.Item (opens new window)
# Editable.Popover
浮层编辑
参考 https://antdv.com/components/popover-cn/ (opens new window)