add feature: setSchema and render page

fix : event-dialog bugs
This commit is contained in:
zude.hzd 2020-09-03 22:03:57 +08:00
parent d4ab19a671
commit 2462596fbd
7 changed files with 44 additions and 13 deletions

View File

@ -123,6 +123,9 @@ export default {
const simulatorUrl = [
'https://dev.g.alicdn.com/ali-lowcode/ali-lowcode-engine/0.9.50/react-simulator-renderer.css',
'https://dev.g.alicdn.com/ali-lowcode/ali-lowcode-engine/0.9.50/react-simulator-renderer.js',
// for debug simulator
// 'http://localhost:3333/js/react-simulator-renderer.js',
];
editor.set('simulatorUrl', simulatorUrl);
// editor.set('renderEnv', 'rax');

View File

@ -33,6 +33,15 @@ export class Project {
};
}
/**
* document的schema,render
* @param schema
*/
setSchema(schema?: ProjectSchema){
let doc = this.documents.find((doc) => doc.actived);
doc && doc.import(schema?.componentsTree[0]);
}
/**
* schema
*

View File

@ -207,7 +207,6 @@ export default function(metadata: TransformedComponentMetadata): TransformedComp
},
setValue(field: SettingTarget, eventData) {
debugger;
const { eventDataList, eventList } = eventData;
eventList.map((item) => {
field.parent.clearPropValue(item.name);

View File

@ -48,18 +48,25 @@ export default class EventBindDialog extends Component<PluginProps> {
// },
];
private bindEventName :''
state: any = {
visiable: false,
setterName:'event-setter',
selectedEventName: '',
eventName: '',
bindEventName:'',
paramStr:''
};
openDialog = (bindEventName: String) => {
this.bindEventName = bindEventName;
this.initEventName();
this.setState({
visiable: true,
eventName: bindEventName,
selectedEventName:''
});
};
@ -69,9 +76,6 @@ export default class EventBindDialog extends Component<PluginProps> {
});
};
componentDidMount() {
const { editor, config } = this.props;
editor.on(`${config.pluginKey}.openDialog`, (bindEventName: String,setterName:String,paramStr:String) => {
@ -96,8 +100,7 @@ export default class EventBindDialog extends Component<PluginProps> {
}
initEventName = () => {
const { bindEventName } = this.state;
let eventName = bindEventName;
let eventName = this.bindEventName;
this.eventList.map((item) => {
if (item.name === eventName) {
eventName = `${eventName}_new`;

View File

@ -17,7 +17,7 @@
height: 100%;
width: 100%;
position: absolute;
top: 35px;
top: 38px;
}

View File

@ -108,6 +108,8 @@ export default class SourceEditor extends Component<{
});
}
this.showJsEditor();
if (eventName === 'sourceEditor.addFunction') {
setTimeout(() => {
this.addFunction(params);
@ -218,14 +220,22 @@ export default class SourceEditor extends Component<{
});
if (key === TAB_KEY.JS_TAB) {
document.getElementById('cssEditorDom').setAttribute('style', 'display:none');
document.getElementById('jsEditorDom').setAttribute('style', 'block');
this.showJsEditor();
} else {
document.getElementById('jsEditorDom').setAttribute('style', 'display:none');
document.getElementById('cssEditorDom').setAttribute('style', 'block');
this.showCssEditor();
}
};
showJsEditor = () => {
document.getElementById('cssEditorDom').setAttribute('style', 'display:none');
document.getElementById('jsEditorDom').setAttribute('style', 'block');
}
showCssEditor = () => {
document.getElementById('jsEditorDom').setAttribute('style', 'display:none');
document.getElementById('cssEditorDom').setAttribute('style', 'block');
}
updateCode = (newCode) => {
const { selectTab } = this.state;
const { editor } = this.props;
@ -258,7 +268,7 @@ export default class SourceEditor extends Component<{
let newSchema = transfrom.setFunction2Schema(functionMap, schema);
if (newSchema!='' && JSON.stringify(newSchema) != oldSchemaStr){
editor.get('designer').project.load(newSchema,true);
editor.get('designer').project.setSchema(newSchema);
}
}

View File

@ -74,6 +74,13 @@ export default class PageRenderer extends BaseRenderer {
return '页面schema结构异常';
}
debug(`page.render - ${__schema.fileName}`);
this.state = this.__parseData(__schema.state || {});
this.__bindCustomMethods(this.props);
this.__initDataSource(this.props);
// this.__setLifeCycleMethods('constructor', arguments);
this.__generateCtx({
page: this,
});