-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(element): add FormCollapse component (#2119)
- Loading branch information
Showing
18 changed files
with
599 additions
and
31 deletions.
There are no files selected for viewing
148 changes: 148 additions & 0 deletions
148
packages/element/docs/demos/guide/form-collapse/json-schema.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
<template> | ||
<FormProvider :form="form"> | ||
<FormLayout :label-col="6" :wrapper-col="10"> | ||
<SchemaField :schema="schema" :scope="{ formCollapse }" /> | ||
<FormButtonGroup alignFormItem> | ||
<Button | ||
@click=" | ||
() => { | ||
form.query('tab3').take((field) => { | ||
field.visible = !field.visible | ||
}) | ||
} | ||
" | ||
> | ||
显示/隐藏最后一个Tab | ||
</Button> | ||
<Button | ||
@click=" | ||
() => { | ||
formCollapse.toggleActiveKey('tab2') | ||
} | ||
" | ||
> | ||
切换第二个Tab | ||
</Button> | ||
<Submit @submit="log">提交</Submit> | ||
</FormButtonGroup> | ||
</FormLayout> | ||
</FormProvider> | ||
</template> | ||
|
||
<script> | ||
import { createForm } from '@formily/core' | ||
import { FormProvider, createSchemaField } from '@formily/vue' | ||
import { | ||
FormItem, | ||
FormCollapse, | ||
FormButtonGroup, | ||
Form, | ||
FormLayout, | ||
Submit, | ||
Input, | ||
} from '@formily/element' | ||
import { Button } from 'element-ui' | ||
const { SchemaField } = createSchemaField({ | ||
components: { | ||
FormItem, | ||
FormCollapse, | ||
Input, | ||
}, | ||
}) | ||
const schema = { | ||
type: 'object', | ||
properties: { | ||
collapse: { | ||
type: 'void', | ||
title: '折叠面板', | ||
'x-decorator': 'FormItem', | ||
'x-component': 'FormCollapse', | ||
'x-component-props': { | ||
formCollapse: '{{formCollapse}}', | ||
}, | ||
properties: { | ||
tab1: { | ||
type: 'void', | ||
'x-component': 'FormCollapse.Item', | ||
'x-component-props': { | ||
title: 'A1', | ||
}, | ||
properties: { | ||
aaa: { | ||
type: 'string', | ||
title: 'AAA', | ||
'x-decorator': 'FormItem', | ||
required: true, | ||
'x-component': 'Input', | ||
}, | ||
}, | ||
}, | ||
tab2: { | ||
type: 'void', | ||
'x-component': 'FormCollapse.Item', | ||
'x-component-props': { | ||
title: 'A2', | ||
}, | ||
properties: { | ||
bbb: { | ||
type: 'string', | ||
title: 'BBB', | ||
'x-decorator': 'FormItem', | ||
required: true, | ||
'x-component': 'Input', | ||
}, | ||
}, | ||
}, | ||
tab3: { | ||
type: 'void', | ||
'x-component': 'FormCollapse.Item', | ||
'x-component-props': { | ||
title: 'A3', | ||
}, | ||
properties: { | ||
ccc: { | ||
type: 'string', | ||
title: 'CCC', | ||
'x-decorator': 'FormItem', | ||
required: true, | ||
'x-component': 'Input', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
export default { | ||
components: { | ||
Form, | ||
FormButtonGroup, | ||
Button, | ||
Submit, | ||
SchemaField, | ||
FormProvider, | ||
FormLayout, | ||
}, | ||
data() { | ||
const form = createForm() | ||
const formCollapse = FormCollapse.createFormCollapse() | ||
return { | ||
schema, | ||
form, | ||
formCollapse, | ||
} | ||
}, | ||
methods: { | ||
log(values) { | ||
console.log(values) | ||
}, | ||
}, | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped></style> |
126 changes: 126 additions & 0 deletions
126
packages/element/docs/demos/guide/form-collapse/markup-schema.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<template> | ||
<Form :form="form" :label-col="6" :wrapper-col="10"> | ||
<SchemaField> | ||
<SchemaVoidField | ||
type="void" | ||
title="折叠面板" | ||
x-decorator="FormItem" | ||
x-component="FormCollapse" | ||
:x-component-props="{ formCollapse }" | ||
> | ||
<SchemaVoidField | ||
type="void" | ||
name="tab1" | ||
x-component="FormCollapse.Item" | ||
:x-component-props="{ title: 'A1' }" | ||
> | ||
<SchemaStringField | ||
name="aaa" | ||
x-decorator="FormItem" | ||
title="AAA" | ||
required | ||
x-component="Input" | ||
/> | ||
</SchemaVoidField> | ||
<SchemaVoidField | ||
name="tab2" | ||
x-component="FormCollapse.Item" | ||
:x-component-props="{ title: 'A2' }" | ||
> | ||
<SchemaStringField | ||
name="bbb" | ||
x-decorator="FormItem" | ||
title="BBB" | ||
required | ||
x-component="Input" | ||
/> | ||
</SchemaVoidField> | ||
<SchemaVoidField | ||
name="tab3" | ||
x-component="FormCollapse.Item" | ||
:x-component-props="{ title: 'A3' }" | ||
> | ||
<SchemaStringField | ||
name="ccc" | ||
x-decorator="FormItem" | ||
title="CCC" | ||
required | ||
x-component="Input" | ||
/> | ||
</SchemaVoidField> | ||
</SchemaVoidField> | ||
</SchemaField> | ||
<FormButtonGroup alignFormItem> | ||
<Button | ||
@click=" | ||
() => { | ||
form.query('tab3').take((field) => { | ||
field.visible = !field.visible | ||
}) | ||
} | ||
" | ||
> | ||
显示/隐藏最后一个Tab | ||
</Button> | ||
<Button | ||
@click=" | ||
() => { | ||
formCollapse.toggleActiveKey('tab2') | ||
} | ||
" | ||
> | ||
切换第二个Tab | ||
</Button> | ||
<Submit @submit="log">提交</Submit> | ||
</FormButtonGroup> | ||
</Form> | ||
</template> | ||
|
||
<script> | ||
import { createForm } from '@formily/core' | ||
import { createSchemaField } from '@formily/vue' | ||
import { | ||
FormItem, | ||
FormCollapse, | ||
FormButtonGroup, | ||
Submit, | ||
Input, | ||
Form, | ||
} from '@formily/element' | ||
import { Button } from 'element-ui' | ||
const SchemaField = createSchemaField({ | ||
components: { | ||
FormItem, | ||
FormCollapse, | ||
Input, | ||
}, | ||
}) | ||
export default { | ||
components: { | ||
Form, | ||
FormButtonGroup, | ||
Button, | ||
Submit, | ||
...SchemaField, | ||
}, | ||
data() { | ||
const form = createForm() | ||
const formCollapse = FormCollapse.createFormCollapse() | ||
return { | ||
form, | ||
formCollapse, | ||
} | ||
}, | ||
methods: { | ||
log(values) { | ||
console.log(values) | ||
}, | ||
}, | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# FormCollapse | ||
|
||
> 折叠面板,通常用在布局空间要求较高的表单场景 | ||
> | ||
> 注意:只能用在 Schema 场景 | ||
## Markup Schema 案例 | ||
|
||
<dumi-previewer demoPath="guide/form-collapse/markup-schema" /> | ||
|
||
## JSON Schema 案例 | ||
|
||
<dumi-previewer demoPath="guide/form-collapse/json-schema" /> | ||
|
||
## API | ||
|
||
### FormCollapse | ||
|
||
| 属性名 | 类型 | 描述 | 默认值 | | ||
| ------------ | ------------- | ---------------------------------------------------------- | ------ | | ||
| formCollapse | IFormCollapse | 传入通过 createFormCollapse/useFormCollapse 创建出来的模型 | | | ||
|
||
其余参考 [https://element.eleme.io/#/zh-CN/component/collapse](https://element.eleme.io/#/zh-CN/component/collapse) | ||
|
||
### FormCollapse.Item | ||
|
||
参考 [https://element.eleme.io/#/zh-CN/component/collapse](https://element.eleme.io/#/zh-CN/component/collapse) | ||
|
||
### FormCollapse.createFormCollapse | ||
|
||
```ts pure | ||
type ActiveKey = string | number | ||
type ActiveKeys = string | number | Array<string | number> | ||
|
||
interface createFormCollapse { | ||
(defaultActiveKeys?: ActiveKeys): IFormCollpase | ||
} | ||
|
||
interface IFormCollapse { | ||
//激活主键列表 | ||
activeKeys: ActiveKeys | ||
//是否存在该激活主键 | ||
hasActiveKey(key: ActiveKey): boolean | ||
//设置激活主键列表 | ||
setActiveKeys(keys: ActiveKeys): void | ||
//添加激活主键 | ||
addActiveKey(key: ActiveKey): void | ||
//删除激活主键 | ||
removeActiveKey(key: ActiveKey): void | ||
//开关切换激活主键 | ||
toggleActiveKey(key: ActiveKey): void | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './configs' | ||
export * from './shared' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.