mirror of
https://github.com/nocobase/nocobase
synced 2024-11-16 05:35:17 +00:00
796e73ae5a
* refactor(doc): change to new structure * docs: add database docs * docs: add collection docs * docs: add db field examples * docs(api): fix filename and menu path * docs: add database docs * docs: add db operators doc * docs: add resourcer menu * docs: add resourcer docs * docs: fix api docs * docs: refactor api menu structure * feat: update docs (#830) * feat: updates * feat: update docs * chore: ignore docs from ci Co-authored-by: Junyi <mytharcher@users.noreply.github.com> Co-authored-by: mytharcher <mytharcher@gmail.com> * docs: add database methods docs * docs: add missed api * docs: fix api docs * feat: update development docs (#833) * feat: update development docs * feat: update docs * feat: update docs * docs: add first plugin example (#834) * feat: update docs * feat: update docs * docs: fix typo Co-authored-by: chenos <chenlinxh@gmail.com>
108 lines
2.6 KiB
TypeScript
108 lines
2.6 KiB
TypeScript
import { ArrayField } from '@formily/core';
|
|
import { connect, ISchema, observer, RecursionField, useField, useFieldSchema } from '@formily/react';
|
|
import { SchemaComponent, SchemaComponentProvider } from '@nocobase/client';
|
|
import { Table, TableColumnType } from 'antd';
|
|
import React from 'react';
|
|
|
|
const ArrayTable = observer((props: any) => {
|
|
const { rowKey } = props;
|
|
const field = useField<ArrayField>();
|
|
const schema = useFieldSchema();
|
|
const columnSchemas = schema.reduceProperties((buf, s) => {
|
|
if (s['x-component'] === 'ArrayTable.Column') {
|
|
buf.push(s);
|
|
}
|
|
return buf;
|
|
}, []);
|
|
|
|
const columns = columnSchemas.map((s) => {
|
|
return {
|
|
render: (value, record) => {
|
|
return <RecursionField name={record.__path} schema={s} onlyRenderProperties />;
|
|
},
|
|
} as TableColumnType<any>;
|
|
});
|
|
|
|
return <Table rowKey={rowKey} columns={columns} dataSource={field.value} />;
|
|
});
|
|
|
|
const Value = connect((props) => {
|
|
return <li>value: {props.value}</li>;
|
|
});
|
|
|
|
const schema: ISchema = {
|
|
type: 'object',
|
|
properties: {
|
|
objArr: {
|
|
type: 'array',
|
|
default: [
|
|
{ __path: '0', id: 1, value: 't1' },
|
|
{
|
|
__path: '1',
|
|
id: 2,
|
|
value: 't2',
|
|
children: [
|
|
{
|
|
__path: '1.children.0',
|
|
id: 5,
|
|
value: 't5',
|
|
parentId: 2,
|
|
},
|
|
],
|
|
},
|
|
{
|
|
__path: '2',
|
|
id: 3,
|
|
value: 't3',
|
|
children: [
|
|
{
|
|
__path: '2.children.0',
|
|
id: 4,
|
|
value: 't4',
|
|
parentId: 3,
|
|
children: [
|
|
{
|
|
__path: '2.children.0.children.0',
|
|
id: 6,
|
|
value: 't6',
|
|
parentId: 4,
|
|
},
|
|
{
|
|
__path: '2.children.0.children.1',
|
|
id: 7,
|
|
value: 't7',
|
|
parentId: 4,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
'x-component': 'ArrayTable',
|
|
'x-component-props': {
|
|
rowKey: 'id',
|
|
},
|
|
properties: {
|
|
c1: {
|
|
type: 'void',
|
|
'x-component': 'ArrayTable.Column',
|
|
properties: {
|
|
value: {
|
|
type: 'string',
|
|
'x-component': 'Value',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
export default () => {
|
|
return (
|
|
<SchemaComponentProvider components={{ ArrayTable, Value }}>
|
|
<SchemaComponent schema={schema} />
|
|
</SchemaComponentProvider>
|
|
);
|
|
};
|