mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-18 21:38:14 +00:00
fix: 修改js面板的保存schema问题
This commit is contained in:
parent
f9ceda58e0
commit
0ee8892190
@ -22,14 +22,21 @@ interface BasicSection {
|
|||||||
|
|
||||||
const Codeout = ({ editor }: PluginProps) => {
|
const Codeout = ({ editor }: PluginProps) => {
|
||||||
const handleSaveClick = () => {
|
const handleSaveClick = () => {
|
||||||
const designer = editor.get(Designer);
|
|
||||||
if (designer) {
|
debugger;
|
||||||
const schema = designer.schema.componentsTree[designer.schema.componentsTree.length - 1]; // editor.get('schema');
|
|
||||||
const schemaStr = JSON.stringify(schema);
|
let schema = editor.get('designer').project.getSchema();
|
||||||
window.localStorage.setItem('schema_data', schemaStr);
|
console.log(schema);
|
||||||
console.info('save schema:', schemaStr);
|
|
||||||
alert('保存成功');
|
|
||||||
}
|
// const designer = editor.get(Designer);
|
||||||
|
// if (designer) {
|
||||||
|
// const schema = designer.schema.componentsTree[designer.schema.componentsTree.length - 1]; // editor.get('schema');
|
||||||
|
// const schemaStr = JSON.stringify(schema);
|
||||||
|
// window.localStorage.setItem('schema_data', schemaStr);
|
||||||
|
// console.info('save schema:', schemaStr);
|
||||||
|
// alert('保存成功');
|
||||||
|
// }
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleLoadClick = () => {
|
const handleLoadClick = () => {
|
||||||
|
|||||||
@ -71,6 +71,14 @@ export default class SourceEditor extends Component<{
|
|||||||
this.callEditorEvent('sourceEditor.focusByFunction', params);
|
this.callEditorEvent('sourceEditor.focusByFunction', params);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// 插件面板关闭事件,监听规则同上
|
||||||
|
editor.on('skeleton.panel-dock.unactive',(pluginName,dock)=>{
|
||||||
|
if (pluginName == 'sourceEditor'){
|
||||||
|
this.saveSchema();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
let schema = editor.get('designer').project.getSchema();
|
let schema = editor.get('designer').project.getSchema();
|
||||||
this.initCode(schema);
|
this.initCode(schema);
|
||||||
}
|
}
|
||||||
@ -231,12 +239,29 @@ export default class SourceEditor extends Component<{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let functionMap = transfrom.code2Schema(newCode);
|
// let functionMap = transfrom.code2Schema(newCode);
|
||||||
let schema = editor.get('designer').project.getSchema();
|
// let schema = editor.get('designer').project.getSchema();
|
||||||
let newSchema = transfrom.setFunction2Schema(functionMap, schema);
|
// let newSchema = transfrom.setFunction2Schema(functionMap, schema);
|
||||||
editor.get('designer').project.load(newSchema);
|
// if (newSchema!=''){
|
||||||
|
// editor.get('designer').project.load(newSchema,true);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
saveSchema = () => {
|
||||||
|
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!='' && JSON.stringify(newSchema) != oldSchemaStr){
|
||||||
|
editor.get('designer').project.load(newSchema,true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { selectTab, jsCode, css } = this.state;
|
const { selectTab, jsCode, css } = this.state;
|
||||||
const tabs = [
|
const tabs = [
|
||||||
|
|||||||
@ -17,9 +17,7 @@ const transfrom = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
code2Schema(code: String) {
|
code2Schema(code: String) {
|
||||||
|
|
||||||
let newCode = code.replace(/export default class/,'class A');
|
let newCode = code.replace(/export default class/,'class A');
|
||||||
|
|
||||||
let A,a;
|
let A,a;
|
||||||
try {
|
try {
|
||||||
A = eval('('+newCode + ')');
|
A = eval('('+newCode + ')');
|
||||||
@ -28,7 +26,6 @@ const transfrom = {
|
|||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let functionNameList = Object.getOwnPropertyNames(a.__proto__);
|
let functionNameList = Object.getOwnPropertyNames(a.__proto__);
|
||||||
|
|
||||||
let functionMap = {};
|
let functionMap = {};
|
||||||
@ -42,11 +39,11 @@ const transfrom = {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
if (a.state){
|
if (a.state){
|
||||||
functionMap.state = a.state
|
functionMap.state = a.state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(functionMap);
|
||||||
return functionMap;
|
return functionMap;
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -56,7 +53,9 @@ const transfrom = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setFunction2Schema(functionMap,schema){
|
setFunction2Schema(functionMap,schema){
|
||||||
|
|
||||||
let pageNode = schema.componentsTree[0];
|
let pageNode = schema.componentsTree[0];
|
||||||
|
if (!pageNode) return '';
|
||||||
for (let key in functionMap){
|
for (let key in functionMap){
|
||||||
if (key == 'state'){
|
if (key == 'state'){
|
||||||
pageNode.state = functionMap[key];
|
pageNode.state = functionMap[key];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user