|
@@ -29,15 +29,19 @@ $(function(){
|
|
var editor;
|
|
var editor;
|
|
var requestEditor;
|
|
var requestEditor;
|
|
var outputEditor;
|
|
var outputEditor;
|
|
|
|
+ var optionEditor;
|
|
var editorLayout = function(){
|
|
var editorLayout = function(){
|
|
editor&&editor.layout();
|
|
editor&&editor.layout();
|
|
requestEditor&&requestEditor.layout();
|
|
requestEditor&&requestEditor.layout();
|
|
|
|
+ optionEditor && optionEditor.layout();
|
|
outputEditor&&outputEditor.layout();
|
|
outputEditor&&outputEditor.layout();
|
|
}
|
|
}
|
|
|
|
+ var defaultRequestValue = '{\r\n\t"request" : {\r\n\t\t"message" : "Hello MagicAPI!"\r\n\t},\r\n\t"path" : {\r\n\t\t"id" : "123456"\r\n\t},\r\n\t"header" : {\r\n\t\t"token" : "tokenValue"\r\n\t},\r\n\t"cookie" : {\r\n\t\t"cookieName" : "cookieValue"\r\n\t},\r\n\t"session" : {\r\n\t\t"userId" : "123"\r\n\t}\r\n}';
|
|
var resetEditor = function(){
|
|
var resetEditor = function(){
|
|
editor&&editor.setValue('return message;');
|
|
editor&&editor.setValue('return message;');
|
|
- requestEditor&&requestEditor.setValue('{\r\n\t"request" : {\r\n\t\t"message" : "Hello MagicAPI!"\r\n\t},\r\n\t"path" : {\r\n\t\t"id" : "123456"\r\n\t},\r\n\t"header" : {\r\n\t\t"token" : "tokenValue"\r\n\t},\r\n\t"cookie" : {\r\n\t\t"cookieName" : "cookieValue"\r\n\t},\r\n\t"session" : {\r\n\t\t"userId" : "123"\r\n\t}\r\n}');
|
|
+ requestEditor && requestEditor.setValue(defaultRequestValue);
|
|
outputEditor&&outputEditor.setValue('');
|
|
outputEditor&&outputEditor.setValue('');
|
|
|
|
+ optionEditor && optionEditor.setValue('{\r\n}');
|
|
}
|
|
}
|
|
var addBreakPoint = function(line){
|
|
var addBreakPoint = function(line){
|
|
if(editor){
|
|
if(editor){
|
|
@@ -89,6 +93,15 @@ $(function(){
|
|
fixedOverflowWidgets :true,
|
|
fixedOverflowWidgets :true,
|
|
theme : 'json'
|
|
theme : 'json'
|
|
});
|
|
});
|
|
|
|
+ optionEditor = monaco.editor.create(document.getElementById('option-parameter'), {
|
|
|
|
+ minimap: {
|
|
|
|
+ enabled: false
|
|
|
|
+ },
|
|
|
|
+ language: 'json',
|
|
|
|
+ folding: false,
|
|
|
|
+ fixedOverflowWidgets: true,
|
|
|
|
+ theme: 'json'
|
|
|
|
+ });
|
|
outputEditor = monaco.editor.create(document.getElementById('output-result'), {
|
|
outputEditor = monaco.editor.create(document.getElementById('output-result'), {
|
|
minimap : {
|
|
minimap : {
|
|
enabled : false
|
|
enabled : false
|
|
@@ -123,6 +136,10 @@ $(function(){
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+ var formatJson = function (val, defaultVal) {
|
|
|
|
+ return (val ? JSON.stringify(val, null, 4) : defaultVal) || '';
|
|
|
|
+ }
|
|
|
|
+
|
|
var $tbody = $('#debug-tbody');
|
|
var $tbody = $('#debug-tbody');
|
|
var debugDecorations;
|
|
var debugDecorations;
|
|
var debugIn = function(id,data){
|
|
var debugIn = function(id,data){
|
|
@@ -174,7 +191,7 @@ $(function(){
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
layui.element.tabChange('output-container', 'output');
|
|
layui.element.tabChange('output-container', 'output');
|
|
- outputEditor.setValue(JSON.stringify(json,null,4))
|
|
+ outputEditor.setValue(formatJson(json))
|
|
}
|
|
}
|
|
|
|
|
|
$(window).resize(editorLayout);
|
|
$(window).resize(editorLayout);
|
|
@@ -242,6 +259,9 @@ $(function(){
|
|
resizeY.setCapture && resizeY.setCapture();
|
|
resizeY.setCapture && resizeY.setCapture();
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
+ layui.element.on('tab', function () {
|
|
|
|
+ editorLayout();
|
|
|
|
+ });
|
|
$('body').on('keydown',function(e){
|
|
$('body').on('keydown',function(e){
|
|
if(e.keyCode == 119){
|
|
if(e.keyCode == 119){
|
|
if(debugSessionId){
|
|
if(debugSessionId){
|
|
@@ -260,8 +280,6 @@ $(function(){
|
|
}
|
|
}
|
|
e.preventDefault();
|
|
e.preventDefault();
|
|
}
|
|
}
|
|
- }).on('blur','#request-parameter',function(){
|
|
|
|
- var value = this.value;
|
|
|
|
}).on('click','.api-list li[data-id]',function(){
|
|
}).on('click','.api-list li[data-id]',function(){
|
|
var id = $(this).data('id');
|
|
var id = $(this).data('id');
|
|
_ajax({
|
|
_ajax({
|
|
@@ -276,7 +294,9 @@ $(function(){
|
|
$('select[name=method]').val(info.method);
|
|
$('select[name=method]').val(info.method);
|
|
layui.form.render();
|
|
layui.form.render();
|
|
resetEditor();
|
|
resetEditor();
|
|
- editor.setValue(info.script);
|
|
+ editor && editor.setValue(info.script);
|
|
|
|
+ requestEditor && requestEditor.setValue(info.parameter || defaultRequestValue);
|
|
|
|
+ optionEditor && optionEditor.setValue(info.option || '{\r\n}');
|
|
|
|
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -335,6 +355,8 @@ $(function(){
|
|
path : path,
|
|
path : path,
|
|
method : method,
|
|
method : method,
|
|
id : apiId,
|
|
id : apiId,
|
|
|
|
+ parameter: requestEditor.getValue(),
|
|
|
|
+ option: optionEditor.getValue(),
|
|
name : name
|
|
name : name
|
|
},
|
|
},
|
|
async : false,
|
|
async : false,
|