tachybase_todo/packages/client/src/blocks/form/index.md

238 lines
5.1 KiB
Markdown
Raw Normal View History

2021-05-23 08:38:08 +08:00
---
title: Form - 表单
nav:
2021-06-27 15:41:40 +08:00
title: 组件
path: /client
2021-05-23 08:38:08 +08:00
group:
2021-06-27 15:41:40 +08:00
order: 1
2021-07-04 00:19:26 +08:00
title: Components - 组件
path: /client/components
2021-05-23 08:38:08 +08:00
---
# Form - 表单
2021-06-27 15:41:40 +08:00
## 代码演示
2021-05-23 08:38:08 +08:00
2021-06-27 15:41:40 +08:00
### 常规表单
2021-05-23 08:38:08 +08:00
2021-06-27 15:41:40 +08:00
```tsx
import React from 'react';
2021-07-04 00:19:26 +08:00
import { SchemaRenderer } from '../';
2021-05-23 08:38:08 +08:00
2021-06-27 15:41:40 +08:00
const schema = {
2021-07-06 00:15:19 +08:00
name: 'form',
2021-06-27 15:41:40 +08:00
type: 'object',
2021-07-06 00:15:19 +08:00
'x-component': 'Form',
2021-06-27 15:41:40 +08:00
properties: {
2021-07-06 00:15:19 +08:00
username: {
type: 'string',
title: '用户名',
required: true,
'x-decorator': 'FormItem',
'x-component': 'Input',
},
password: {
type: 'string',
title: '密码',
required: true,
'x-decorator': 'FormItem',
'x-component': 'Password',
},
}
};
2021-06-27 15:41:40 +08:00
export default () => {
return (
2021-07-04 00:19:26 +08:00
<SchemaRenderer schema={schema} />
2021-06-27 15:41:40 +08:00
);
};
2021-05-23 08:38:08 +08:00
```
2021-06-27 15:41:40 +08:00
### 栅格布局表单
2021-05-23 08:38:08 +08:00
2021-06-27 15:41:40 +08:00
```tsx
import React from 'react';
2021-07-04 00:19:26 +08:00
import { SchemaRenderer } from '../';
2021-07-04 22:04:15 +08:00
import { uid } from '@formily/shared';
2021-05-23 08:38:08 +08:00
2021-06-27 15:41:40 +08:00
const schema = {
type: 'void',
2021-07-04 22:04:15 +08:00
name: uid(),
2021-06-27 15:41:40 +08:00
'x-decorator': 'Card',
'x-component': 'Form',
properties: {
2021-07-04 22:04:15 +08:00
[uid()]: {
2021-06-27 15:41:40 +08:00
type: 'void',
'x-component': 'Grid',
properties: {
2021-07-04 22:04:15 +08:00
[`row_${uid()}`]: {
2021-06-27 15:41:40 +08:00
type: 'void',
'x-component': 'Grid.Row',
properties: {
2021-07-04 22:04:15 +08:00
[`col_${uid()}`]: {
2021-06-27 15:41:40 +08:00
type: 'void',
'x-component': 'Grid.Col',
properties: {
2021-07-04 22:04:15 +08:00
[`block_${uid()}`]: {
type: 'string',
required: true,
title: '字段1',
'x-decorator': 'FormItem',
'x-component': 'Input',
2021-06-27 15:41:40 +08:00
},
},
},
2021-07-04 22:04:15 +08:00
[`col_${uid()}`]: {
2021-06-27 15:41:40 +08:00
type: 'void',
'x-component': 'Grid.Col',
properties: {
2021-07-04 22:04:15 +08:00
[`block_${uid()}`]: {
type: 'string',
required: true,
title: '字段2',
'x-decorator': 'FormItem',
'x-component': 'Input',
2021-06-27 15:41:40 +08:00
},
},
},
},
},
},
},
actions: {
type: 'void',
// 'x-decorator': 'Div',
'x-component': 'Space',
properties: {
submit: {
type: 'void',
'x-component': 'Action',
'x-component-props': {
// block: true,
type: 'primary',
useAction: '{{ useLogin }}',
style: {
// width: '100%',
},
},
title: '提交',
},
reset: {
type: 'void',
'x-component': 'Action',
'x-component-props': {
// block: true,
useAction: '{{ useLogin }}',
style: {
// width: '100%',
},
},
title: '重置',
},
},
},
2021-05-23 08:38:08 +08:00
},
}
2021-06-27 15:41:40 +08:00
export default () => {
return (
2021-07-04 00:19:26 +08:00
<SchemaRenderer schema={schema} />
2021-06-27 15:41:40 +08:00
);
};
```
2021-05-23 08:38:08 +08:00
2021-06-27 15:41:40 +08:00
### 表单设计器
2021-05-23 08:38:08 +08:00
2021-06-27 15:41:40 +08:00
```tsx
import React from 'react';
2021-07-04 00:19:26 +08:00
import { SchemaRenderer } from '../';
2021-06-27 15:41:40 +08:00
import { uid } from '@formily/shared';
2021-05-23 08:38:08 +08:00
2021-06-27 15:41:40 +08:00
const schema = {
type: 'void',
2021-07-04 22:04:15 +08:00
name: uid(),
2021-06-27 15:41:40 +08:00
'x-decorator': 'Card',
'x-component': 'Form',
2021-07-04 22:04:15 +08:00
'x-designable-bar': 'Form.DesignableBar',
2021-06-27 15:41:40 +08:00
properties: {
2021-07-04 22:04:15 +08:00
[uid()]: {
2021-06-27 15:41:40 +08:00
type: 'void',
'x-component': 'Grid',
properties: {
2021-07-04 22:04:15 +08:00
[`row_${uid()}`]: {
2021-06-27 15:41:40 +08:00
type: 'void',
'x-component': 'Grid.Row',
properties: {
2021-07-04 22:04:15 +08:00
[`col_${uid()}`]: {
2021-06-27 15:41:40 +08:00
type: 'void',
'x-component': 'Grid.Col',
properties: {
2021-07-04 22:04:15 +08:00
[`block_${uid()}`]: {
type: 'string',
required: true,
title: '字段1',
'x-decorator': 'FormItem',
'x-designable-bar': 'FormItem.DesignableBar',
'x-component': 'Input',
2021-06-27 15:41:40 +08:00
},
},
},
2021-07-04 22:04:15 +08:00
[`col_${uid()}`]: {
2021-06-27 15:41:40 +08:00
type: 'void',
'x-component': 'Grid.Col',
properties: {
2021-07-04 22:04:15 +08:00
[`block_${uid()}`]: {
type: 'string',
required: true,
title: '字段2',
'x-decorator': 'FormItem',
'x-designable-bar': 'FormItem.DesignableBar',
'x-component': 'Input',
2021-06-27 15:41:40 +08:00
},
},
},
},
},
},
},
actions: {
type: 'void',
// 'x-decorator': 'Div',
'x-component': 'Space',
properties: {
submit: {
type: 'void',
'x-component': 'Action',
'x-component-props': {
// block: true,
type: 'primary',
useAction: '{{ useLogin }}',
style: {
// width: '100%',
},
},
title: '提交',
},
reset: {
type: 'void',
'x-component': 'Action',
'x-component-props': {
// block: true,
useAction: '{{ useLogin }}',
style: {
// width: '100%',
},
},
title: '重置',
},
},
},
},
2021-07-04 22:04:15 +08:00
}
2021-05-23 08:38:08 +08:00
2021-06-27 15:41:40 +08:00
export default () => {
return (
2021-07-04 00:19:26 +08:00
<SchemaRenderer schema={schema} />
2021-06-27 15:41:40 +08:00
);
};
```