From 0c78c9d97ec0dd1d99efe54cce2e02aa881bf3f4 Mon Sep 17 00:00:00 2001 From: "zude.hzd" Date: Sat, 12 Sep 2020 21:46:14 +0800 Subject: [PATCH] fix:event-setter with params --- .../src/transducers/addon-combine.ts | 3 +- .../plugin-event-bind-dialog/src/index.tsx | 3 +- packages/plugin-source-editor/src/index.tsx | 31 ++++++++++++------- .../plugin-source-editor/src/transform.ts | 3 +- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/packages/editor-skeleton/src/transducers/addon-combine.ts b/packages/editor-skeleton/src/transducers/addon-combine.ts index b00547e42..af8d42975 100644 --- a/packages/editor-skeleton/src/transducers/addon-combine.ts +++ b/packages/editor-skeleton/src/transducers/addon-combine.ts @@ -215,7 +215,8 @@ export default function(metadata: TransformedComponentMetadata): TransformedComp eventDataList.map((item) => { field.parent.setPropValue(item.name, { type: 'JSFunction', - value: `function(){ this.${item.relatedEventName}(${item.paramStr?item.paramStr:''}) }`, + // 需要传下入参 + value: `function(){this.${item.relatedEventName}.apply(this,Array.prototype.slice.call(arguments).concat([${item.paramStr?item.paramStr:''}])) }`, }); return item; }); diff --git a/packages/plugin-event-bind-dialog/src/index.tsx b/packages/plugin-event-bind-dialog/src/index.tsx index 3170aff73..08f67a118 100644 --- a/packages/plugin-event-bind-dialog/src/index.tsx +++ b/packages/plugin-event-bind-dialog/src/index.tsx @@ -80,7 +80,6 @@ export default class EventBindDialog extends Component { const { editor, config } = this.props; editor.on(`${config.pluginKey}.openDialog`, (bindEventName: String,setterName:String,paramStr:String) => { console.log('paramStr:'+paramStr); - this.openDialog(bindEventName); this.setState({ setterName, paramStr @@ -96,6 +95,8 @@ export default class EventBindDialog extends Component { }) } } + + this.openDialog(bindEventName); }); } diff --git a/packages/plugin-source-editor/src/index.tsx b/packages/plugin-source-editor/src/index.tsx index 1a55a80fc..372fdb786 100644 --- a/packages/plugin-source-editor/src/index.tsx +++ b/packages/plugin-source-editor/src/index.tsx @@ -56,7 +56,8 @@ export default class SourceEditor extends Component<{ state = { isFullScreen:false, tabKey: TAB_KEY.JS_TAB, - isShowSaveBtn:true + isShowSaveBtn:true, + visiable:false }; componentWillMount() { @@ -77,6 +78,9 @@ export default class SourceEditor extends Component<{ editor.on('skeleton.panel-dock.unactive',(pluginName,dock)=>{ if (pluginName == 'sourceEditor'){ this.saveSchema(); + this.setState({ + visiable:false + }) } }) @@ -142,6 +146,7 @@ export default class SourceEditor extends Component<{ jsCode, css, selectTab: TAB_KEY.JS_TAB, + visiable:true }); }; @@ -272,18 +277,21 @@ export default class SourceEditor extends Component<{ const {jsCode} = this.state; const {editor} = this.props; let functionMap = transfrom.code2Schema(jsCode); - let schema = editor.get('designer').project.getSchema(); - //let oldSchemaStr = JSON.stringify(schema); - let newSchema = transfrom.setFunction2Schema(functionMap, schema); - if (newSchema!=''){ - editor.get('designer').project.setSchema(newSchema); - successFlag && Message.success('保存成功') - } + if (functionMap!=null){ + let schema = editor.get('designer').project.getSchema(); + //let oldSchemaStr = JSON.stringify(schema); + let newSchema = transfrom.setFunction2Schema(functionMap, schema); + + if (newSchema!=''){ + editor.get('designer').project.setSchema(newSchema); + successFlag && Message.success('保存成功') + } + } } render() { - const { selectTab, jsCode, css ,isShowSaveBtn} = this.state; + const { selectTab, jsCode, css ,isShowSaveBtn,visiable} = this.state; const tabs = [ { tab: 'index.js', key: TAB_KEY.JS_TAB }, { tab: 'style.css', key: TAB_KEY.CSS_TAB }, @@ -298,7 +306,7 @@ export default class SourceEditor extends Component<{ ))} { isShowSaveBtn &&
} - + { visiable &&
- - + } {/*
*/} diff --git a/packages/plugin-source-editor/src/transform.ts b/packages/plugin-source-editor/src/transform.ts index 9598eed5f..a438cfe01 100644 --- a/packages/plugin-source-editor/src/transform.ts +++ b/packages/plugin-source-editor/src/transform.ts @@ -23,7 +23,8 @@ const transfrom = { A = eval('('+newCode + ')'); a = new A(); }catch(e){ - return '' + console.log(e.message); + return null } let functionNameList = Object.getOwnPropertyNames(a.__proto__);