mirror of
https://github.com/YMFE/yapi.git
synced 2025-03-01 14:05:44 +08:00
fix: fix empty edit interface info
This commit is contained in:
parent
4158855022
commit
2805ea0b82
@ -38,7 +38,7 @@ class InterfaceEdit extends Component {
|
||||
}
|
||||
|
||||
onSubmit = async (params) => {
|
||||
params.id = params._id = this.props.curdata._id;
|
||||
params.id = this.props.match.params.actionId;
|
||||
let result = await axios.post('/api/interface/up', params);
|
||||
if (result.data.errcode === 0) {
|
||||
this.props.updateInterfaceData(params);
|
||||
@ -49,7 +49,6 @@ class InterfaceEdit extends Component {
|
||||
}
|
||||
|
||||
componentWillUnmount(){
|
||||
console.log('unmount')
|
||||
try{
|
||||
if(this.state.status === 1){
|
||||
this.WebSocket.close()
|
||||
@ -84,7 +83,6 @@ class InterfaceEdit extends Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
console.log(this.state.status)
|
||||
return <div className="interface-edit">
|
||||
{this.state.status === 1 ?
|
||||
<InterfaceEditForm mockUrl={this.state.mockUrl} basepath={this.props.currProject.basepath} onSubmit={this.onSubmit} curdata={this.state.curdata} />
|
||||
|
@ -36,7 +36,12 @@ class InterfaceEditForm extends Component {
|
||||
if (curdata.req_headers && curdata.req_headers.length === 0) delete curdata.req_headers;
|
||||
if (curdata.req_body_form && curdata.req_body_form.length === 0) delete curdata.req_body_form;
|
||||
if (curdata.req_params && curdata.req_params.length === 0) delete curdata.req_params;
|
||||
|
||||
if (curdata.req_body_form) {
|
||||
curdata.req_body_form = curdata.req_body_form.map((item) => {
|
||||
item.type = item.type === 'text' ? 'text' : 'file'
|
||||
return item
|
||||
})
|
||||
}
|
||||
this.state = Object.assign({
|
||||
title: '',
|
||||
path: '',
|
||||
@ -55,8 +60,8 @@ class InterfaceEditForm extends Component {
|
||||
}],
|
||||
req_body_form: [{
|
||||
name: '',
|
||||
type: '',
|
||||
required: ''
|
||||
type: 'text',
|
||||
required: '1'
|
||||
}],
|
||||
res_body_type: 'json',
|
||||
res_body: '',
|
||||
@ -64,6 +69,8 @@ class InterfaceEditForm extends Component {
|
||||
res_body_mock: '',
|
||||
mockUrl: this.props.mockUrl
|
||||
}, curdata)
|
||||
|
||||
|
||||
}
|
||||
|
||||
handleSubmit = (e) => {
|
||||
@ -94,9 +101,10 @@ class InterfaceEditForm extends Component {
|
||||
value: isfile ? 'multipart/form-data' : 'application/x-www-form-urlencoded'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
values.req_headers = values.req_headers.filter((item)=> item.name !== '')
|
||||
values.req_body_form = values.req_body_form.filter((item)=> item.name !== '')
|
||||
values.req_params = values.req_params.filter(item=>item.name !== '')
|
||||
|
||||
this.props.onSubmit(values)
|
||||
}
|
||||
@ -109,7 +117,7 @@ class InterfaceEditForm extends Component {
|
||||
container: 'req_body_json',
|
||||
data: that.state.req_body_json,
|
||||
onChange: function (d) {
|
||||
if(d.format !== true) return false;
|
||||
if (d.format !== true) return false;
|
||||
that.setState({
|
||||
req_body_json: d.text
|
||||
})
|
||||
@ -120,7 +128,7 @@ class InterfaceEditForm extends Component {
|
||||
container: 'res_body_json',
|
||||
data: that.state.res_body,
|
||||
onChange: function (d) {
|
||||
if(d.format !== true) return false;
|
||||
if (d.format !== true) return false;
|
||||
mockPreview.editor.setValue(d.mockText)
|
||||
that.setState({
|
||||
res_body: d.text,
|
||||
@ -158,15 +166,15 @@ class InterfaceEditForm extends Component {
|
||||
let val = e.target.value;
|
||||
if (val && val.indexOf(":") !== -1) {
|
||||
let paths = val.split("/"), name, i;
|
||||
for(i=1; i< paths.length; i++){
|
||||
if(paths[i][0] === ':'){
|
||||
for (i = 1; i < paths.length; i++) {
|
||||
if (paths[i][0] === ':') {
|
||||
name = paths[i].substr(1);
|
||||
if(!_.find(this.state.req_params, {name: name})){
|
||||
if (!_.find(this.state.req_params, { name: name })) {
|
||||
this.addParams('req_params', { name: name })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -254,6 +254,10 @@ class interfaceController extends baseController {
|
||||
data.req_body_other = params.req_body_other;
|
||||
}
|
||||
|
||||
if (params.req_body_type) {
|
||||
data.req_body_type = params.req_body_type;
|
||||
}
|
||||
|
||||
if (params.res_body_type) {
|
||||
data.res_body_type = params.res_body_type;
|
||||
}
|
||||
|
@ -472,6 +472,10 @@ var interfaceController = function (_baseController) {
|
||||
data.req_body_other = params.req_body_other;
|
||||
}
|
||||
|
||||
if (params.req_body_type) {
|
||||
data.req_body_type = params.req_body_type;
|
||||
}
|
||||
|
||||
if (params.res_body_type) {
|
||||
data.res_body_type = params.res_body_type;
|
||||
}
|
||||
@ -479,29 +483,29 @@ var interfaceController = function (_baseController) {
|
||||
data.res_body = params.res_body;
|
||||
}
|
||||
|
||||
_context4.prev = 30;
|
||||
_context4.next = 33;
|
||||
_context4.prev = 31;
|
||||
_context4.next = 34;
|
||||
return this.Model.up(id, data);
|
||||
|
||||
case 33:
|
||||
case 34:
|
||||
result = _context4.sent;
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(result);
|
||||
_context4.next = 40;
|
||||
_context4.next = 41;
|
||||
break;
|
||||
|
||||
case 37:
|
||||
_context4.prev = 37;
|
||||
_context4.t0 = _context4['catch'](30);
|
||||
case 38:
|
||||
_context4.prev = 38;
|
||||
_context4.t0 = _context4['catch'](31);
|
||||
|
||||
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
|
||||
|
||||
case 40:
|
||||
case 41:
|
||||
case 'end':
|
||||
return _context4.stop();
|
||||
}
|
||||
}
|
||||
}, _callee4, this, [[30, 37]]);
|
||||
}, _callee4, this, [[31, 38]]);
|
||||
}));
|
||||
|
||||
function up(_x4) {
|
||||
|
Loading…
Reference in New Issue
Block a user