fix: fieldId 重复问题

This commit is contained in:
mario.gk 2020-08-06 20:45:08 +08:00
parent 956fdeb1c1
commit e761b1ae86
3 changed files with 28 additions and 13 deletions

View File

@ -301,8 +301,11 @@ export class DocumentModel {
}
import(schema: RootSchema, checkId = false) {
// TODO: do purge
this.nodes.forEach(node => {
this.destroyNode(node);
});
this.rootNode.import(schema as any, checkId);
// todo: purge something
// todo: select added and active track added
}

View File

@ -70,11 +70,6 @@ export class Prop implements IPropParent {
return undefined;
}
// 兼容 vision 之前逻辑
if (this.key === 'fieldId' && stage === TransformStage.Clone) {
return undefined;
}
if (type === 'literal' || type === 'expression') {
// TODO 后端改造之后删除此逻辑
if (this._value === null && stage === TransformStage.Save) {

View File

@ -25,10 +25,17 @@ export const designer = new Designer({ editor: editor });
editor.set(Designer, designer);
editor.set('designer', designer);
const nodeCache: any = {};
designer.project.onCurrentDocumentChange((doc) => {
doc.onRendererReady(() => {
bus.emit(VE_EVENTS.VE_PAGE_PAGE_READY);
});
doc.onNodeCreate((node) => {
nodeCache[node.id] = node;
});
doc.onNodeDestroy((node) => {
delete nodeCache[node.id];
});
});
interface Variable {
@ -80,11 +87,23 @@ designer.addPropsReducer(upgradePropsReducer, TransformStage.Upgrade);
// 节点 props 初始化
designer.addPropsReducer((props, node) => {
// run initials
const newProps: any = {
...props,
};
if (newProps.fieldId) {
const fieldIds: any = [];
Object.keys(nodeCache).forEach(nodeId => {
const fieldId = nodeCache[nodeId].getPropValue('fieldId');
if (fieldId) {
fieldIds.push(fieldId);
}
});
if (fieldIds.indexOf(props.fieldId) >= 0) {
newProps.fieldId = undefined;
}
}
const initials = node.componentMeta.getMetadata().experimental?.initials;
if (initials) {
const newProps: any = {
...props,
};
const getRealValue = (propValue: any) => {
if (isVariable(propValue)) {
return propValue.value;
@ -98,7 +117,7 @@ designer.addPropsReducer((props, node) => {
// FIXME! this implements SettingTarget
try {
// FIXME! item.name could be 'xxx.xxx'
const ov = props[item.name];
const ov = newProps[item.name];
const v = item.initial(node as any, getRealValue(ov));
if (ov === undefined && v !== undefined) {
newProps[item.name] = v;
@ -112,10 +131,8 @@ designer.addPropsReducer((props, node) => {
node.props.add(newProps[item.name], item.name);
}
});
return newProps;
}
return props;
return newProps;
}, TransformStage.Init);
designer.addPropsReducer((props: any, node: Node) => {