mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +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 { 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> {
|
export class DataBlockModel<T = DefaultStructure> extends BlockModel<T> {
|
||||||
resource: APIResource;
|
resource: APIResource;
|
||||||
|
@ -216,9 +216,8 @@ export class TableModel extends DataBlockModel<TableModelStructure> {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
renderComponent() {
|
||||||
return (
|
return (
|
||||||
<Card>
|
|
||||||
<Spin spinning={this.resource.loading}>
|
<Spin spinning={this.resource.loading}>
|
||||||
<DndProvider>
|
<DndProvider>
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
|
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: 16 }}>
|
||||||
@ -227,10 +226,7 @@ export class TableModel extends DataBlockModel<TableModelStructure> {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (action.props.position === 'left') {
|
if (action.props.position === 'left') {
|
||||||
return (
|
return (
|
||||||
<FlowModelRenderer
|
<FlowModelRenderer model={action} showFlowSettings={{ showBackground: false, showBorder: false }} />
|
||||||
model={action}
|
|
||||||
showFlowSettings={{ showBackground: false, showBorder: false }}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -244,10 +240,7 @@ export class TableModel extends DataBlockModel<TableModelStructure> {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
if (action.props.position !== 'left') {
|
if (action.props.position !== 'left') {
|
||||||
return (
|
return (
|
||||||
<FlowModelRenderer
|
<FlowModelRenderer model={action} showFlowSettings={{ showBackground: false, showBorder: false }} />
|
||||||
model={action}
|
|
||||||
showFlowSettings={{ showBackground: false, showBorder: false }}
|
|
||||||
/>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,7 +280,6 @@ export class TableModel extends DataBlockModel<TableModelStructure> {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Spin>
|
</Spin>
|
||||||
</Card>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -436,6 +436,10 @@ export class CollectionField {
|
|||||||
return this.options.uiSchema || {};
|
return this.options.uiSchema || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get targetCollection() {
|
||||||
|
return this.collection.collectionManager.getCollection(this.options.target);
|
||||||
|
}
|
||||||
|
|
||||||
getComponentProps() {
|
getComponentProps() {
|
||||||
return this.options.uiSchema?.['x-component-props'] || {};
|
return this.options.uiSchema?.['x-component-props'] || {};
|
||||||
}
|
}
|
||||||
@ -444,11 +448,10 @@ export class CollectionField {
|
|||||||
if (!this.options.target) {
|
if (!this.options.target) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
const targetCollection = this.collection.collectionManager.getCollection(this.options.target);
|
if (!this.targetCollection) {
|
||||||
if (!targetCollection) {
|
|
||||||
throw new Error(`Target collection ${this.options.target} not found for field ${this.name}`);
|
throw new Error(`Target collection ${this.options.target} not found for field ${this.name}`);
|
||||||
}
|
}
|
||||||
return targetCollection.getFields();
|
return this.targetCollection.getFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
getInterfaceOptions() {
|
getInterfaceOptions() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user