diff --git a/packages/plugin-source-editor/src/index.tsx b/packages/plugin-source-editor/src/index.tsx index 642b031ad..3becac7b7 100644 --- a/packages/plugin-source-editor/src/index.tsx +++ b/packages/plugin-source-editor/src/index.tsx @@ -234,6 +234,7 @@ export default class SourceEditor extends Component<{ let functionMap = transfrom.code2Schema(newCode); let schema = editor.get('designer').project.getSchema(); let newSchema = transfrom.setFunction2Schema(functionMap,schema); + editor.get('designer').project.load(newSchema); }; render() { diff --git a/packages/plugin-source-editor/src/transform.ts b/packages/plugin-source-editor/src/transform.ts index afb761381..f6c3eaafc 100644 --- a/packages/plugin-source-editor/src/transform.ts +++ b/packages/plugin-source-editor/src/transform.ts @@ -40,15 +40,11 @@ const transfrom = { } }) - console.log(JSON.stringify(a.state)); - - console.log(functionMap); if (a.state){ functionMap.state = a.state } - return functionMap; }, @@ -63,12 +59,33 @@ const transfrom = { if (key == 'state'){ pageNode.state = functionMap[key]; }else{ + // 判断是否属于lifeCycles节点 if (LIFECYCLES_FUNCTION_MAP.react.indexOf(key)>=0){ // 判断有没有lifecycles节点 + if (!pageNode.lifeCycles){ + pageNode.lifeCycles = {} + }else{ + pageNode.lifeCycles[key] = { + "type": "JSFunction", + "value": functionMap[key], + } + } + }else{ + // methods节点 + if (!pageNode.methods){ + pageNode.methods = {} + }else{ + pageNode.methods[key] = { + "type": "JSFunction", + "value": functionMap[key], + } + } } } } + return schema; + } };