Skip to content

Commit

Permalink
UI编辑器保留当前编辑信息,当意外关闭时可恢复。
Browse files Browse the repository at this point in the history
  • Loading branch information
javamxd committed Aug 2, 2020
1 parent d7bb900 commit e6db211
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/main/resources/magicapi-support/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var MagicEditor = {
this.initScriptEditor();
this.resetEditor();
this.checkUpdate();
this.backupInterval();
var _this = this;
$.getJSON('config.json',function(data){
_this.config = data;
Expand Down Expand Up @@ -819,6 +820,38 @@ var MagicEditor = {
}
}])];
},
backupInterval : function(){
var _this = this;
var info = _this.getValue('api_info');
if(info){
info = JSON.parse(info);
_this.apiId = info.id;
$('input[name=name]').val(info.name || '');
$('input[name=path]').val(info.path || '');
$('input[name=method]').val(info.method || '');
$('input[name=group]').val(info.groupName || '');
$('input[name=prefix]').val(info.groupPrefix || '');
_this.scriptEditor&&_this.scriptEditor.setValue(info.script || 'return message;');
_this.requestEditor&&_this.requestEditor.setValue(info.parameters || _this.defaultRequestValue);
_this.options&&_this.options.setValue(info.options || '{\r\n}');
_this.output&&_this.output.setValue(info.options || '');

}
setInterval(function(){
_this.setValue('api_info',{
id : _this.apiId,
name : $('input[name=name]').val(),
path : $('input[name=path]').val(),
method : $('input[name=method]').val(),
groupName : $('input[name=group]').val(),
groupPrefix : $('input[name=prefix]').val(),
script : _this.scriptEditor&&_this.scriptEditor.getValue(),
parameters : _this.requestEditor&&_this.requestEditor.getValue(),
options : _this.optionsEditor&&_this.optionsEditor.getValue(),
output: _this.outputEditor&&_this.outputEditor.getValue()
})
},5000)
},
// 初始化快捷键
initShortKey : function(){
var _this = this;
Expand Down Expand Up @@ -1102,6 +1135,9 @@ var MagicEditor = {
}
localStorage&&localStorage.setItem(key,value) || '';
},
removeValue : function(key){
localStorage&&localStorage.removeItem(key);
},
bindEditorShortKey : function(editor){
// Alt + / 代码提示
editor.addCommand(monaco.KeyMod.Alt | monaco.KeyCode.US_SLASH,function(){
Expand Down

0 comments on commit e6db211

Please sign in to comment.