fix: fix empty edit interface info

This commit is contained in:
sean 2017-08-18 12:37:32 +08:00
parent 4158855022
commit 2805ea0b82
4 changed files with 37 additions and 23 deletions

View File

@ -38,7 +38,7 @@ class InterfaceEdit extends Component {
} }
onSubmit = async (params) => { 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); let result = await axios.post('/api/interface/up', params);
if (result.data.errcode === 0) { if (result.data.errcode === 0) {
this.props.updateInterfaceData(params); this.props.updateInterfaceData(params);
@ -49,7 +49,6 @@ class InterfaceEdit extends Component {
} }
componentWillUnmount(){ componentWillUnmount(){
console.log('unmount')
try{ try{
if(this.state.status === 1){ if(this.state.status === 1){
this.WebSocket.close() this.WebSocket.close()
@ -84,7 +83,6 @@ class InterfaceEdit extends Component {
} }
render() { render() {
console.log(this.state.status)
return <div className="interface-edit"> return <div className="interface-edit">
{this.state.status === 1 ? {this.state.status === 1 ?
<InterfaceEditForm mockUrl={this.state.mockUrl} basepath={this.props.currProject.basepath} onSubmit={this.onSubmit} curdata={this.state.curdata} /> <InterfaceEditForm mockUrl={this.state.mockUrl} basepath={this.props.currProject.basepath} onSubmit={this.onSubmit} curdata={this.state.curdata} />

View File

@ -36,7 +36,12 @@ class InterfaceEditForm extends Component {
if (curdata.req_headers && curdata.req_headers.length === 0) delete curdata.req_headers; 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_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_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({ this.state = Object.assign({
title: '', title: '',
path: '', path: '',
@ -55,8 +60,8 @@ class InterfaceEditForm extends Component {
}], }],
req_body_form: [{ req_body_form: [{
name: '', name: '',
type: '', type: 'text',
required: '' required: '1'
}], }],
res_body_type: 'json', res_body_type: 'json',
res_body: '', res_body: '',
@ -64,6 +69,8 @@ class InterfaceEditForm extends Component {
res_body_mock: '', res_body_mock: '',
mockUrl: this.props.mockUrl mockUrl: this.props.mockUrl
}, curdata) }, curdata)
} }
handleSubmit = (e) => { handleSubmit = (e) => {
@ -94,9 +101,10 @@ class InterfaceEditForm extends Component {
value: isfile ? 'multipart/form-data' : 'application/x-www-form-urlencoded' 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) this.props.onSubmit(values)
} }
@ -109,7 +117,7 @@ class InterfaceEditForm extends Component {
container: 'req_body_json', container: 'req_body_json',
data: that.state.req_body_json, data: that.state.req_body_json,
onChange: function (d) { onChange: function (d) {
if(d.format !== true) return false; if (d.format !== true) return false;
that.setState({ that.setState({
req_body_json: d.text req_body_json: d.text
}) })
@ -120,7 +128,7 @@ class InterfaceEditForm extends Component {
container: 'res_body_json', container: 'res_body_json',
data: that.state.res_body, data: that.state.res_body,
onChange: function (d) { onChange: function (d) {
if(d.format !== true) return false; if (d.format !== true) return false;
mockPreview.editor.setValue(d.mockText) mockPreview.editor.setValue(d.mockText)
that.setState({ that.setState({
res_body: d.text, res_body: d.text,
@ -158,15 +166,15 @@ class InterfaceEditForm extends Component {
let val = e.target.value; let val = e.target.value;
if (val && val.indexOf(":") !== -1) { if (val && val.indexOf(":") !== -1) {
let paths = val.split("/"), name, i; let paths = val.split("/"), name, i;
for(i=1; i< paths.length; i++){ for (i = 1; i < paths.length; i++) {
if(paths[i][0] === ':'){ if (paths[i][0] === ':') {
name = paths[i].substr(1); 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 }) this.addParams('req_params', { name: name })
} }
} }
} }
} }
} }

View File

@ -254,6 +254,10 @@ class interfaceController extends baseController {
data.req_body_other = params.req_body_other; 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) { if (params.res_body_type) {
data.res_body_type = params.res_body_type; data.res_body_type = params.res_body_type;
} }

View File

@ -472,6 +472,10 @@ var interfaceController = function (_baseController) {
data.req_body_other = params.req_body_other; 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) { if (params.res_body_type) {
data.res_body_type = 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; data.res_body = params.res_body;
} }
_context4.prev = 30; _context4.prev = 31;
_context4.next = 33; _context4.next = 34;
return this.Model.up(id, data); return this.Model.up(id, data);
case 33: case 34:
result = _context4.sent; result = _context4.sent;
ctx.body = _yapi2.default.commons.resReturn(result); ctx.body = _yapi2.default.commons.resReturn(result);
_context4.next = 40; _context4.next = 41;
break; break;
case 37: case 38:
_context4.prev = 37; _context4.prev = 38;
_context4.t0 = _context4['catch'](30); _context4.t0 = _context4['catch'](31);
ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message); ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message);
case 40: case 41:
case 'end': case 'end':
return _context4.stop(); return _context4.stop();
} }
} }
}, _callee4, this, [[30, 37]]); }, _callee4, this, [[31, 38]]);
})); }));
function up(_x4) { function up(_x4) {