1
0
mirror of synced 2026-04-05 07:48:35 +08:00

feat(data-source,utils,runtime): 数据源setData支持指定路径

This commit is contained in:
roymondchen
2024-01-02 20:57:37 +08:00
parent 6b4bfae30b
commit d3777b236d
18 changed files with 229 additions and 97 deletions

View File

@@ -17,12 +17,12 @@
*/
import { reactive } from 'vue';
import { cloneDeep, get, mergeWith, set } from 'lodash-es';
import { cloneDeep, mergeWith } from 'lodash-es';
import { DepTargetType } from '@tmagic/dep';
import type { FormConfig } from '@tmagic/form';
import type { Id, MComponent, MNode } from '@tmagic/schema';
import { guid, toLine } from '@tmagic/utils';
import { getValueByKeyPath, guid, setValueByKeyPath, toLine } from '@tmagic/utils';
import depService from '@editor/services/dep';
import editorService from '@editor/services/editor';
@@ -194,17 +194,22 @@ class Props extends BaseService {
public replaceRelateId(originConfigs: MNode[], targetConfigs: MNode[]) {
const relateIdMap = this.getRelateIdMap();
if (Object.keys(relateIdMap).length === 0) return;
const target = depService.getTarget(DepTargetType.RELATED_COMP_WHEN_COPY, DepTargetType.RELATED_COMP_WHEN_COPY);
if (!target) return;
originConfigs.forEach((config: MNode) => {
const newId = relateIdMap[config.id];
const targetConfig = targetConfigs.find((targetConfig) => targetConfig.id === newId);
if (!targetConfig) return;
target.deps[config.id]?.keys?.forEach((fullKey) => {
const relateOriginId = get(config, fullKey);
const relateOriginId = getValueByKeyPath(fullKey, config);
const relateTargetId = relateIdMap[relateOriginId];
if (!relateTargetId) return;
set(targetConfig, fullKey, relateTargetId);
setValueByKeyPath(fullKey, relateTargetId, targetConfig);
});
});
}