ArrayListTabs
带有侧边栏标签列表的表单容器
注意
该组件仅适用于Schema场景
MarkupSchema 示例
vue
<script lang="ts" setup>
import { Close } from '@element-plus/icons-vue'
import { createForm } from '@formily/core'
import { createSchemaField, FormProvider } from '@formily/vue'
import {
ArrayListTabs,
FormItem,
Input,
Submit,
} from '@silver-formily/element-plus'
const {
SchemaField,
SchemaArrayField,
SchemaObjectField,
SchemaStringField,
SchemaVoidField,
} = createSchemaField({
components: {
FormItem,
Input,
ArrayListTabs,
},
})
const form = createForm()
async function log(values) {
console.log(values)
}
</script>
<template>
<FormProvider :form="form">
<SchemaField>
<SchemaArrayField
name="array"
x-decorator="FormItem"
x-component="ArrayListTabs"
:x-component-props="{
tabTitleField: 'input',
}"
:x-validator="{
max: 5,
}"
>
<SchemaObjectField>
<SchemaStringField
name="input"
x-decorator="FormItem"
title="input"
x-component="Input"
:x-component-props="{
placeholder: '请输入Input',
}"
:x-validator="[{ required: true }]"
/>
<SchemaStringField
name="input2"
x-decorator="FormItem"
title="input2"
x-component="Input"
/>
<SchemaVoidField
x-component="ArrayListTabs.Remove"
:x-component-props="{
icon: Close,
}"
/>
</SchemaObjectField>
<SchemaVoidField
x-component="ArrayListTabs.Addition"
title="添加条目"
/>
</SchemaArrayField>
</SchemaField>
<Submit style="margin-top: 30px;" @submit="log">
提交
</Submit>
</FormProvider>
</template>MarkupSchema 作为Tab标题渲染示例
提示
推荐使用Editable包裹作为标题的field,当其作为标题渲染时其报错不会被统计入panel的错误。
vue
<script lang="ts" setup>
import { Close } from '@element-plus/icons-vue'
import { createForm } from '@formily/core'
import { createSchemaField, FormProvider } from '@formily/vue'
import {
ArrayListTabs,
Editable,
FormItem,
Input,
PreviewText,
Submit,
} from '@silver-formily/element-plus'
const {
SchemaField,
SchemaArrayField,
SchemaObjectField,
SchemaStringField,
SchemaVoidField,
} = createSchemaField({
components: {
FormItem,
Input,
ArrayListTabs,
Editable,
PreviewText,
},
})
const form = createForm()
async function log(values) {
console.log(values)
}
</script>
<template>
<FormProvider :form="form">
<SchemaField>
<SchemaArrayField
name="array"
x-decorator="FormItem"
x-component="ArrayListTabs"
:x-component-props="{
tabTitleField: 'input',
showTitleFieldInTab: true,
}"
:x-validator="{
max: 5,
}"
>
<SchemaObjectField>
<SchemaVoidField
x-component="PreviewText"
:x-component-props="{
placeholder: '未命名条目',
}"
>
<SchemaStringField
name="input"
x-decorator="Editable"
:x-decorator-props="{
layout: 'inline',
size: 'small',
editProps: {
style: {
width: '120px',
},
},
}"
title="input"
x-component="Input"
:x-component-props="{
placeholder: '请输入Input',
}"
:x-validator="[{ required: true }]"
/>
</SchemaVoidField>
<SchemaStringField
name="input2"
x-decorator="FormItem"
title="input2"
x-component="Input"
:x-validator="[{ required: true }]"
/>
<SchemaStringField
name="input3"
x-decorator="FormItem"
title="input3"
x-component="Input"
/>
<SchemaVoidField
x-component="ArrayListTabs.Remove"
:x-component-props="{
icon: Close,
}"
/>
</SchemaObjectField>
<SchemaVoidField
x-component="ArrayListTabs.Addition"
title="添加条目"
/>
</SchemaArrayField>
</SchemaField>
<Submit style="margin-top: 30px;" @submit="log">
提交
</Submit>
</FormProvider>
</template>API
ArrayListTabs Props
| 属性名 | 类型 | 描述 | 默认值 |
|---|---|---|---|
| tabTitleField | string | 必填,作为标签页标题的field的name。对应的field有值时会作为标签页标题渲染 | - |
| showTitleFieldInTab | boolean | 是否将tabTitleField作为标签页标题。 | false |