Skip to content

Commit

Permalink
fix:修复上下文重复问题
Browse files Browse the repository at this point in the history
  • Loading branch information
hsm-lv committed Jan 2, 2024
1 parent d9ace50 commit 77d1ea9
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 90 deletions.
60 changes: 37 additions & 23 deletions packages/amis-editor-core/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2021,24 +2021,32 @@ export class EditorManager {
if (!nearestScope && scopeNode && !scopeNode.isSecondFactor) {
nearestScope = scope;
}
if (scopeNode) {
const tmpSchema = await scopeNode?.info?.plugin?.buildDataSchemas?.(
scopeNode,
region,
trigger
);

const jsonschema = await scopeNode?.info?.plugin?.buildDataSchemas?.(
scopeNode,
region,
trigger
);
if (jsonschema) {
scope.removeSchema(jsonschema.$id);
scope.addSchema(jsonschema);
}
if (tmpSchema) {
const jsonschema = {
...tmpSchema,
...(tmpSchema?.$id
? {}
: {$id: `${scopeNode!.id}-${scopeNode!.type}`})
};
scope.removeSchema(jsonschema.$id);
scope.addSchema(jsonschema);
}

// 记录each列表等组件顺序
if (scopeNode?.info?.isListComponent) {
listScope.unshift(scope);
// 记录each列表等组件顺序
if (scopeNode?.info?.isListComponent) {
listScope.unshift(scope);

// 如果当前节点是list类型节点,当前scope从父节点上取
if (nodeId === id) {
nearestScope = scope.parent;
// 如果当前节点是list类型节点,当前scope从父节点上取
if (nodeId === id) {
nearestScope = scope.parent;
}
}
}

Expand All @@ -2050,14 +2058,20 @@ export class EditorManager {
for (let scope of listScope) {
const [id, type] = scope.id.split('-');
const node = this.store.getNodeById(id, type);
const jsonschema = await node?.info?.plugin?.buildDataSchemas?.(
node,
region,
trigger
);
if (jsonschema) {
scope.removeSchema(jsonschema.$id);
scope.addSchema(jsonschema);
if (node) {
const tmpSchema = await node?.info?.plugin?.buildDataSchemas?.(
node,
region,
trigger
);
if (tmpSchema) {
const jsonschema = {
...tmpSchema,
...(tmpSchema?.$id ? {} : {$id: `${node!.id}-${node!.type}`})
};
scope.removeSchema(jsonschema.$id);
scope.addSchema(jsonschema);
}
}
}
}
Expand Down
40 changes: 22 additions & 18 deletions packages/amis-editor/src/plugin/CRUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2178,20 +2178,25 @@ export class CRUDPlugin extends BasePlugin {
return;
}

let childSchame = await child.info.plugin.buildDataSchemas(
const tmpSchema = await child.info.plugin.buildDataSchemas?.(
child,
undefined,
trigger,
node
);

let childSchema = {
...tmpSchema,
...(tmpSchema?.$id ? {} : {$id: `${child.id}-${child.type}`})
};

// 兼容table的rows,并自行merged异步数据
if (child.type === 'table') {
let itemsSchema: any = {}; // 收集选择记录中的列
const columns: EditorNodeType = child.children.find(
item => item.isRegion && item.region === 'columns'
);
const rowsSchema = childSchame.properties.rows?.items;
const rowsSchema = childSchema.properties.rows?.items;

if (trigger) {
const isColumnChild = someTree(
Expand All @@ -2213,13 +2218,13 @@ export class CRUDPlugin extends BasePlugin {
...rowsSchema?.properties
};

if (isColumnChild) {
Object.keys(tmpProperties).map(key => {
itemsSchema[key] = {
...tmpProperties[key]
};
});
Object.keys(tmpProperties).map(key => {
itemsSchema[key] = {
...tmpProperties[key]
};
});

if (isColumnChild) {
const childScope = this.manager.dataSchema.getScope(
`${child.id}-${child.type}-currentRow`
);
Expand All @@ -2236,23 +2241,22 @@ export class CRUDPlugin extends BasePlugin {
}
}
}

childSchame = {
$id: childSchame.$id,
type: childSchame.type,
childSchema = {
$id: childSchema.$id,
type: childSchema.type,
properties: {
items: childSchame.properties.rows,
items: childSchema.properties.rows,
selectedItems: {
...childSchame.properties.selectedItems,
...childSchema.properties.selectedItems,
items: {
...childSchame.properties.selectedItems.items,
...childSchema.properties.selectedItems.items,
properties: itemsSchema
}
},
unSelectedItems: {
...childSchame.properties.unSelectedItems,
...childSchema.properties.unSelectedItems,
items: {
...childSchame.properties.unSelectedItems.items,
...childSchema.properties.unSelectedItems.items,
properties: itemsSchema
}
},
Expand All @@ -2268,7 +2272,7 @@ export class CRUDPlugin extends BasePlugin {
};
}

return childSchame;
return childSchema;
}

rendererBeforeDispatchEvent(node: EditorNodeType, e: any, data: any) {
Expand Down
11 changes: 7 additions & 4 deletions packages/amis-editor/src/plugin/CRUD2/BaseCRUD.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1129,10 +1129,13 @@ export class BaseCRUDPlugin extends BasePlugin {
return;
}

const childDataSchema = await child.info.plugin.buildDataSchemas(
child,
region
);
const tmpSchema = await child.info.plugin.buildDataSchemas?.(child, region);

const childDataSchema = {
...tmpSchema,
...(tmpSchema?.$id ? {} : {$id: `${child.id}-${child.type}`})
};

const items =
childDataSchema?.properties?.rows ?? childDataSchema?.properties?.items;
const schema: any = {
Expand Down
17 changes: 10 additions & 7 deletions packages/amis-editor/src/plugin/Form/Combo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -722,13 +722,16 @@ export class ComboControlPlugin extends BasePlugin {
const current = pool.shift() as EditorNodeType;
const schema = current.schema;
if (schema?.name) {
itemsSchema.properties[schema.name] =
await current.info.plugin.buildDataSchemas?.(
current,
region,
trigger,
node
);
const tmpSchema = await current.info.plugin.buildDataSchemas?.(
current,
region,
trigger,
node
);
itemsSchema.properties[schema.name] = {
tmpSchema,
...(tmpSchema?.$id ? {} : {$id: `${current!.id}-${current!.type}`})
};
}
}

Expand Down
17 changes: 10 additions & 7 deletions packages/amis-editor/src/plugin/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1259,13 +1259,16 @@ export class FormPlugin extends BasePlugin {
const schema = current.schema;

if (current.rendererConfig?.isFormItem && schema.name) {
jsonschema.properties[schema.name] =
await current.info.plugin.buildDataSchemas?.(
current,
region,
trigger,
node
);
const tmpSchema = await current.info.plugin.buildDataSchemas?.(
current,
region,
trigger,
node
);
jsonschema.properties[schema.name] = {
...tmpSchema,
...(tmpSchema?.$id ? {} : {$id: `${current.id}-${current.type}`})
};
} else {
pool.push(...current.children);
}
Expand Down
17 changes: 10 additions & 7 deletions packages/amis-editor/src/plugin/Form/InputTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1440,13 +1440,16 @@ export class TableControlPlugin extends BasePlugin {
const schema = current.schema;

if (schema.name) {
itemsSchema.properties[schema.name] =
await current.info.plugin.buildDataSchemas?.(
current,
region,
trigger,
node
);
const tmpSchema = await current.info.plugin.buildDataSchemas?.(
current,
region,
trigger,
node
);
itemsSchema.properties[schema.name] = {
...tmpSchema,
...(tmpSchema?.$id ? {} : {$id: `${current!.id}-${current!.type}`})
};
}
}
}
Expand Down
17 changes: 10 additions & 7 deletions packages/amis-editor/src/plugin/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -408,13 +408,16 @@ export class PagePlugin extends BasePlugin {
const schema = current.schema;

if (current.rendererConfig?.isFormItem && schema?.name) {
jsonschema.properties[schema.name] =
await current.info.plugin.buildDataSchemas?.(
current,
undefined,
trigger,
node
);
const tmpSchema = await current.info.plugin.buildDataSchemas?.(
current,
undefined,
trigger,
node
);
jsonschema.properties[schema.name] = {
...tmpSchema,
...(tmpSchema?.$id ? {} : {$id: `${current.id}-${current.type}`})
};
} else if (!current.rendererConfig?.storeType) {
pool.push(...current.children);
}
Expand Down
17 changes: 10 additions & 7 deletions packages/amis-editor/src/plugin/Service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,16 @@ export class ServicePlugin extends BasePlugin {
const schema = current.schema;

if (current.rendererConfig?.isFormItem && schema?.name) {
jsonschema.properties[schema.name] =
await current.info.plugin.buildDataSchemas?.(
current,
undefined,
trigger,
node
);
const tmpSchema = await current.info.plugin.buildDataSchemas?.(
current,
undefined,
trigger,
node
);
jsonschema.properties[schema.name] = {
...tmpSchema,
...(tmpSchema?.$id ? {} : {$id: `${current.id}-${current.type}`})
};
} else if (!current.rendererConfig?.storeType) {
pool.push(...current.children);
}
Expand Down
17 changes: 10 additions & 7 deletions packages/amis-editor/src/plugin/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -846,13 +846,16 @@ export class TablePlugin extends BasePlugin {
const current = items.shift() as EditorNodeType;
const schema = current.schema;
if (schema.name) {
itemsSchema.properties[schema.name] =
await current.info.plugin.buildDataSchemas?.(
current,
region,
trigger,
node
);
const tmpSchema = await current.info.plugin.buildDataSchemas?.(
current,
region,
trigger,
node
);
itemsSchema.properties[schema.name] = {
...tmpSchema,
...(tmpSchema?.$id ? {} : {$id: `${current!.id}-${current!.type}`})
};
}
}
index++;
Expand Down
9 changes: 6 additions & 3 deletions packages/amis-editor/src/plugin/Table2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -643,13 +643,16 @@ export class Table2Plugin extends BasePlugin {
for (let current of columns.children) {
const schema = current.schema;
if (schema?.name) {
itemsSchema.properties[schema.name] = current.info?.plugin
?.buildDataSchemas
? await current.info.plugin.buildDataSchemas(current, region)
const tmpSchema = current.info?.plugin?.buildDataSchemas
? await current.info.plugin.buildDataSchemas?.(current, region)
: {
type: 'string',
title: schema.label || schema.title
};
itemsSchema.properties[schema.name] = {
...tmpSchema,
...(tmpSchema?.$id ? {} : {$id: `${current!.id}-${current!.type}`})
};
}
}
}
Expand Down

0 comments on commit 77d1ea9

Please sign in to comment.