mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-01-13 01:21:58 +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 handleSaveClick = () => {
|
||||
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('保存成功');
|
||||
}
|
||||
|
||||
debugger;
|
||||
|
||||
let schema = editor.get('designer').project.getSchema();
|
||||
console.log(schema);
|
||||
|
||||
|
||||
// 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 = () => {
|
||||
|
||||
@ -71,6 +71,14 @@ export default class SourceEditor extends Component<{
|
||||
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();
|
||||
this.initCode(schema);
|
||||
}
|
||||
@ -231,12 +239,29 @@ 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);
|
||||
// let functionMap = transfrom.code2Schema(newCode);
|
||||
// let schema = editor.get('designer').project.getSchema();
|
||||
// let newSchema = transfrom.setFunction2Schema(functionMap, schema);
|
||||
// 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() {
|
||||
const { selectTab, jsCode, css } = this.state;
|
||||
const tabs = [
|
||||
|
||||
@ -17,9 +17,7 @@ const transfrom = {
|
||||
},
|
||||
|
||||
code2Schema(code: String) {
|
||||
|
||||
let newCode = code.replace(/export default class/,'class A');
|
||||
|
||||
let A,a;
|
||||
try {
|
||||
A = eval('('+newCode + ')');
|
||||
@ -28,7 +26,6 @@ const transfrom = {
|
||||
return ''
|
||||
}
|
||||
|
||||
|
||||
let functionNameList = Object.getOwnPropertyNames(a.__proto__);
|
||||
|
||||
let functionMap = {};
|
||||
@ -42,11 +39,11 @@ const transfrom = {
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
if (a.state){
|
||||
functionMap.state = a.state
|
||||
}
|
||||
|
||||
console.log(functionMap);
|
||||
return functionMap;
|
||||
|
||||
},
|
||||
@ -56,7 +53,9 @@ const transfrom = {
|
||||
},
|
||||
|
||||
setFunction2Schema(functionMap,schema){
|
||||
|
||||
let pageNode = schema.componentsTree[0];
|
||||
if (!pageNode) return '';
|
||||
for (let key in functionMap){
|
||||
if (key == 'state'){
|
||||
pageNode.state = functionMap[key];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user