mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-04 21:19:27 +08:00
* refactor: 表格拆分模块化 * refactor: 表格拆分模块化 * refactor: code splitting of the table component (#120) * missing TableIndex * refactor: 表格拆分模块化 * code format Co-authored-by: chenos <chenlinxh@gmail.com>
55 lines
1.9 KiB
TypeScript
55 lines
1.9 KiB
TypeScript
import React, { useContext } from 'react';
|
|
import { observer, RecursionField, Schema } from '@formily/react';
|
|
import { cloneDeepWith, set } from 'lodash';
|
|
import { uid, merge } from '@formily/shared';
|
|
import { CollectionFieldContext, TableRowContext } from './context';
|
|
import { Table } from './Table';
|
|
|
|
export const TableCell = observer((props: any) => {
|
|
const ctx = useContext(TableRowContext);
|
|
const schema = props.schema;
|
|
const collectionField = useContext(CollectionFieldContext);
|
|
if (schema['x-component'] === 'Table.Operation') {
|
|
return <Table.Operation.Cell {...props} />;
|
|
}
|
|
let uiSchema = collectionField?.uiSchema as Schema;
|
|
if (uiSchema?.['x-component'] === 'Upload.Attachment') {
|
|
uiSchema = cloneDeepWith(uiSchema);
|
|
set(uiSchema, 'x-component-props.size', 'small');
|
|
}
|
|
const componentProps = merge(uiSchema?.['x-component-props'] || {}, schema?.['x-component-props'] || {}, {
|
|
arrayMerge: (t, s) => s,
|
|
});
|
|
console.log('Table.Cell', collectionField?.interface, componentProps);
|
|
return (
|
|
<div className={`field-interface-${collectionField?.interface}`}>
|
|
<RecursionField
|
|
schema={
|
|
!collectionField
|
|
? schema
|
|
: new Schema({
|
|
type: 'void',
|
|
properties: {
|
|
[collectionField.name]: {
|
|
...uiSchema,
|
|
title: undefined,
|
|
'x-read-pretty': true,
|
|
'x-decorator-props': {
|
|
feedbackLayout: 'popover',
|
|
},
|
|
'x-decorator': 'FormilyFormItem',
|
|
'x-component-props': componentProps,
|
|
properties: {
|
|
...schema?.properties,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
}
|
|
name={ctx.index}
|
|
onlyRenderProperties
|
|
/>
|
|
</div>
|
|
);
|
|
});
|