mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
fix: block model
This commit is contained in:
parent
881fcd86a3
commit
0f5952a6e1
@ -8,8 +8,21 @@
|
||||
*/
|
||||
|
||||
import { APIResource, BaseRecordResource, Collection, DefaultStructure, FlowModel } from '@nocobase/flow-engine';
|
||||
import { Card } from 'antd';
|
||||
import React from 'react';
|
||||
|
||||
export class BlockModel<T = DefaultStructure> extends FlowModel<T> {}
|
||||
export class BlockModel<T = DefaultStructure> extends FlowModel<T> {
|
||||
decoratorProps: Record<string, any> = {};
|
||||
|
||||
renderComponent() {
|
||||
throw new Error('renderComponent method must be implemented in subclasses of BlockModel');
|
||||
return null;
|
||||
}
|
||||
|
||||
render() {
|
||||
return <Card {...this.decoratorProps}>{this.renderComponent()}</Card>;
|
||||
}
|
||||
}
|
||||
|
||||
export class DataBlockModel<T = DefaultStructure> extends BlockModel<T> {
|
||||
resource: APIResource;
|
||||
|
@ -216,78 +216,70 @@ export class TableModel extends DataBlockModel<TableModelStructure> {
|
||||
},
|
||||
};
|
||||
|
||||
render() {
|
||||
renderComponent() {
|
||||
return (
|
||||
<Card>
|
||||
<Spin spinning={this.resource.loading}>
|
||||
<DndProvider>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
|
||||
<Space>
|
||||
{this.mapSubModels('actions', (action) => {
|
||||
// @ts-ignore
|
||||
if (action.props.position === 'left') {
|
||||
return (
|
||||
<FlowModelRenderer
|
||||
model={action}
|
||||
showFlowSettings={{ showBackground: false, showBorder: false }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
<Spin spinning={this.resource.loading}>
|
||||
<DndProvider>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
|
||||
<Space>
|
||||
{this.mapSubModels('actions', (action) => {
|
||||
// @ts-ignore
|
||||
if (action.props.position === 'left') {
|
||||
return (
|
||||
<FlowModelRenderer model={action} showFlowSettings={{ showBackground: false, showBorder: false }} />
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
})}
|
||||
{/* 占位 */}
|
||||
<span></span>
|
||||
</Space>
|
||||
<Space>
|
||||
{this.mapSubModels('actions', (action) => {
|
||||
// @ts-ignore
|
||||
if (action.props.position !== 'left') {
|
||||
return (
|
||||
<FlowModelRenderer
|
||||
model={action}
|
||||
showFlowSettings={{ showBackground: false, showBorder: false }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
})}
|
||||
{/* 占位 */}
|
||||
<span></span>
|
||||
</Space>
|
||||
<Space>
|
||||
{this.mapSubModels('actions', (action) => {
|
||||
// @ts-ignore
|
||||
if (action.props.position !== 'left') {
|
||||
return (
|
||||
<FlowModelRenderer model={action} showFlowSettings={{ showBackground: false, showBorder: false }} />
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
})}
|
||||
<AddActionButton model={this} subModelBaseClass="GlobalActionModel" subModelKey="actions" />
|
||||
</Space>
|
||||
</div>
|
||||
</DndProvider>
|
||||
<Table
|
||||
components={this.components}
|
||||
tableLayout="fixed"
|
||||
rowKey={this.collection.filterTargetKey}
|
||||
rowSelection={{
|
||||
columnWidth: 50,
|
||||
type: 'checkbox',
|
||||
onChange: (_, selectedRows) => {
|
||||
this.resource.setSelectedRows(selectedRows);
|
||||
},
|
||||
selectedRowKeys: this.resource.getSelectedRows().map((row) => row.id),
|
||||
}}
|
||||
virtual={this.props.virtual}
|
||||
scroll={{ x: 'max-content', y: 600 }}
|
||||
dataSource={this.resource.getData()}
|
||||
columns={this.getColumns()}
|
||||
pagination={{
|
||||
current: this.resource.getPage(),
|
||||
pageSize: this.resource.getPageSize(),
|
||||
total: this.resource.getMeta('count'),
|
||||
}}
|
||||
onChange={(pagination) => {
|
||||
console.log('onChange pagination:', pagination);
|
||||
this.resource.loading = true;
|
||||
this.resource.setPage(pagination.current);
|
||||
this.resource.setPageSize(pagination.pageSize);
|
||||
this.resource.refresh();
|
||||
}}
|
||||
/>
|
||||
</Spin>
|
||||
</Card>
|
||||
return null;
|
||||
})}
|
||||
<AddActionButton model={this} subModelBaseClass="GlobalActionModel" subModelKey="actions" />
|
||||
</Space>
|
||||
</div>
|
||||
</DndProvider>
|
||||
<Table
|
||||
components={this.components}
|
||||
tableLayout="fixed"
|
||||
rowKey={this.collection.filterTargetKey}
|
||||
rowSelection={{
|
||||
columnWidth: 50,
|
||||
type: 'checkbox',
|
||||
onChange: (_, selectedRows) => {
|
||||
this.resource.setSelectedRows(selectedRows);
|
||||
},
|
||||
selectedRowKeys: this.resource.getSelectedRows().map((row) => row.id),
|
||||
}}
|
||||
virtual={this.props.virtual}
|
||||
scroll={{ x: 'max-content', y: 600 }}
|
||||
dataSource={this.resource.getData()}
|
||||
columns={this.getColumns()}
|
||||
pagination={{
|
||||
current: this.resource.getPage(),
|
||||
pageSize: this.resource.getPageSize(),
|
||||
total: this.resource.getMeta('count'),
|
||||
}}
|
||||
onChange={(pagination) => {
|
||||
console.log('onChange pagination:', pagination);
|
||||
this.resource.loading = true;
|
||||
this.resource.setPage(pagination.current);
|
||||
this.resource.setPageSize(pagination.pageSize);
|
||||
this.resource.refresh();
|
||||
}}
|
||||
/>
|
||||
</Spin>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -436,6 +436,10 @@ export class CollectionField {
|
||||
return this.options.uiSchema || {};
|
||||
}
|
||||
|
||||
get targetCollection() {
|
||||
return this.collection.collectionManager.getCollection(this.options.target);
|
||||
}
|
||||
|
||||
getComponentProps() {
|
||||
return this.options.uiSchema?.['x-component-props'] || {};
|
||||
}
|
||||
@ -444,11 +448,10 @@ export class CollectionField {
|
||||
if (!this.options.target) {
|
||||
return [];
|
||||
}
|
||||
const targetCollection = this.collection.collectionManager.getCollection(this.options.target);
|
||||
if (!targetCollection) {
|
||||
if (!this.targetCollection) {
|
||||
throw new Error(`Target collection ${this.options.target} not found for field ${this.name}`);
|
||||
}
|
||||
return targetCollection.getFields();
|
||||
return this.targetCollection.getFields();
|
||||
}
|
||||
|
||||
getInterfaceOptions() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user