Merge pull request #9517 from zhangtao07/master

修复crud2 若干bug
This commit is contained in:
张涛 2024-01-24 20:35:08 +08:00 committed by GitHub
commit 03175e1df5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 62 additions and 14 deletions

View File

@ -1120,7 +1120,11 @@ export class BaseCRUDPlugin extends BasePlugin {
}
}
async buildDataSchemas(node: EditorNodeType, region?: EditorNodeType) {
async buildDataSchemas(
node: EditorNodeType,
region?: EditorNodeType,
trigger?: EditorNodeType
) {
const child: EditorNodeType = node.children.find(
item => !!~['table2', 'cards', 'list'].indexOf(item.type)
);
@ -1129,7 +1133,12 @@ export class BaseCRUDPlugin extends BasePlugin {
return;
}
const tmpSchema = await child.info.plugin.buildDataSchemas?.(child, region);
const tmpSchema = await child.info.plugin.buildDataSchemas?.(
child,
region,
trigger,
node
);
const childDataSchema = {
...tmpSchema,
@ -1142,7 +1151,6 @@ export class BaseCRUDPlugin extends BasePlugin {
$id: 'crud2',
type: 'object',
properties: {
...items?.properties,
items: {
...items,
title: '全部数据'

View File

@ -628,7 +628,8 @@ export class Table2Plugin extends BasePlugin {
async buildDataSchemas(
node: EditorNodeType,
region?: EditorNodeType,
trigger?: EditorNodeType
trigger?: EditorNodeType,
parent?: EditorNodeType
) {
const itemsSchema: any = {
$id: 'tableRow',
@ -639,6 +640,32 @@ export class Table2Plugin extends BasePlugin {
item => item.isRegion && item.region === 'columns'
);
const parentScopeId = `${parent?.id}-${parent?.type}${
node.parent?.type === 'cell' ? '-currentRow' : ''
}`;
// 追加当前行scope
let isColumnChild = false;
if (trigger) {
isColumnChild = someTree(
columns?.children,
item => item.id === trigger.id
);
if (isColumnChild) {
const scopeId = `${node.id}-${node.type}-currentRow`;
if (this.manager.dataSchema.getScope(scopeId)) {
this.manager.dataSchema.removeScope(scopeId);
}
if (this.manager.dataSchema.getScope(parentScopeId)) {
this.manager.dataSchema.switchTo(parentScopeId);
}
this.manager.dataSchema.addScope([], scopeId);
this.manager.dataSchema.current.tag = '当前行记录';
this.manager.dataSchema.current.group = '组件上下文';
}
}
if (columns) {
for (let current of columns.children) {
const schema = current.schema;
@ -657,21 +684,24 @@ export class Table2Plugin extends BasePlugin {
}
}
let cellProperties = {};
if (trigger) {
const isColumnChild = someTree(
columns?.children,
item => item.id === trigger.id
);
isColumnChild && (cellProperties = itemsSchema.properties);
// 追加当前行数据
if (isColumnChild) {
const scopeId = `${node.id}-${node.type}-currentRow`;
const scope = this.manager.dataSchema.getScope(scopeId);
scope?.addSchema(itemsSchema);
}
}
const result: any = {
$id: 'table2',
$id: `${node.id}-${node.type}`,
type: 'object',
properties: {
...cellProperties,
rows: {
type: 'array',
title: '数据列表',

View File

@ -28,7 +28,7 @@ import type {
CRUDScaffoldConfig
} from '../../builder';
import type {EditorNodeType} from 'amis-editor-core';
import type {FormControlProps} from 'amis';
import type {FormControlProps, PlainObject} from 'amis';
interface Option {
label: string;
@ -235,6 +235,12 @@ export class CRUDFiltersControl extends React.Component<
this.setState({loading: false});
}
setFilterVisible(schema: PlainObject) {
if (!('visibleOn' in schema) && schema.type) {
schema.visible = schema.body?.length > 0;
}
}
async updateSimpleQuery(enable: boolean) {
const {manager, nodeId, builder} = this.props;
const store = manager.store;
@ -269,7 +275,7 @@ export class CRUDFiltersControl extends React.Component<
}
})) ?? [];
const newFilterSchema = traverseSchemaDeep(
let newFilterSchema = traverseSchemaDeep(
filterSchema,
(key: string, value: any, host: any) => {
/** 更新标识符 */
@ -292,6 +298,7 @@ export class CRUDFiltersControl extends React.Component<
return [key, value];
}
);
this.setFilterVisible(newFilterSchema);
const targetNode = manager.store.getNodeById(filterSchema.$$id);
@ -299,7 +306,7 @@ export class CRUDFiltersControl extends React.Component<
targetNode.updateSchema(newFilterSchema);
}
} else {
const newFilterSchema = traverseSchemaDeep(
let newFilterSchema = traverseSchemaDeep(
filterSchema,
(key: string, value: any, host: any) => {
/** 更新标识符 */
@ -330,6 +337,7 @@ export class CRUDFiltersControl extends React.Component<
}
);
this.setFilterVisible(newFilterSchema);
const targetNode = manager.store.getNodeById(filterSchema.$$id);
if (targetNode) {
@ -402,7 +410,7 @@ export class CRUDFiltersControl extends React.Component<
}
});
const newFilterSchema = traverseSchemaDeep(
let newFilterSchema = traverseSchemaDeep(
filterSchema,
(key: string, value: any, host: any) => {
/** 更新标识符 */
@ -425,6 +433,7 @@ export class CRUDFiltersControl extends React.Component<
return [key, value];
}
);
this.setFilterVisible(newFilterSchema);
const targetNode = manager.store.getNodeById(filterSchema.$$id);
@ -432,7 +441,7 @@ export class CRUDFiltersControl extends React.Component<
targetNode.updateSchema(newFilterSchema);
}
} else {
const newFilterSchema = traverseSchemaDeep(
let newFilterSchema = traverseSchemaDeep(
filterSchema,
(key: string, value: any, host: any) => {
/** 更新标识符 */
@ -464,6 +473,7 @@ export class CRUDFiltersControl extends React.Component<
return [key, value];
}
);
this.setFilterVisible(newFilterSchema);
const targetNode = manager.store.getNodeById(filterSchema.$$id);

View File

@ -300,7 +300,7 @@ export default class Head extends React.PureComponent<Props> {
colIndex === data.length - 1
})}
depth={item.depth}
col={cIndex > -1 ? cIndex.toString() : undefined}
col={String(colIndex)}
>
{typeof item.title === 'function'
? item.title(children)