From 05b13df73134495ffcec9240aad611c248507bf8 Mon Sep 17 00:00:00 2001 From: zwjamnsss Date: Fri, 18 Aug 2017 11:33:37 +0800 Subject: [PATCH 1/4] feat: col menu --- .../InterfaceCol/InterfaceCaseContent.js | 59 +++++++++++++++++++ .../InterfaceCol/InterfaceColContent.js | 2 +- .../InterfaceCol/InterfaceColMenu.js | 21 ++++--- client/reducer/modules/interfaceCol.js | 2 +- 4 files changed, 73 insertions(+), 11 deletions(-) diff --git a/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js b/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js index e69de29b..361914ef 100644 --- a/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js +++ b/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js @@ -0,0 +1,59 @@ +import React, { Component } from 'react' +import { connect } from 'react-redux'; +import PropTypes from 'prop-types' +import { withRouter } from 'react-router' +import { fetchInterfaceColList, fetchInterfaceCaseList, setColData } from '../../../../reducer/modules/interfaceCol' + +@connect( + state => { + return { + interfaceColList: state.interfaceCol.interfaceColList, + currColId: state.interfaceCol.currColId, + currCaseId: state.interfaceCol.currCaseId, + isShowCol: state.interfaceCol.isShowCol + } + }, + { + fetchInterfaceColList, + fetchInterfaceCaseList, + setColData + } +) +@withRouter +export default class InterfaceCaseContent extends Component { + + static propTypes = { + match: PropTypes.object, + interfaceColList: PropTypes.array, + fetchInterfaceColList: PropTypes.func, + fetchInterfaceCaseList: PropTypes.func, + setColData: PropTypes.func, + history: PropTypes.object, + currColId: PropTypes.number, + currCaseId: PropTypes.number, + isShowCol: PropTypes.bool + } + + constructor(props) { + super(props) + } + + async componentWillMount() { + const result = await this.props.fetchInterfaceColList(this.props.match.params.id) + let { currColId, currCaseId, isShowCol } = this.props; + const params = this.props.match.params; + const { actionId } = params; + currColId = +currColId || result.payload.data.data[0]._id; + currCaseId = +actionId || +currCaseId || result.payload.data.data[0].caseList[0]._id; + if (isShowCol) { + this.props.history.push('/project/' + params.id + '/interface/col/' + currColId) + } else { + this.props.history.push('/project/' + params.id + '/interface/case/' + currCaseId) + } + this.props.setColData({currColId: +currColId, currCaseId: +currCaseId}) + } + + render() { + return

hello caseContent

+ } +} diff --git a/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js b/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js index c4d69f6f..7b67be1d 100644 --- a/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js +++ b/client/containers/Project/Interface/InterfaceCol/InterfaceColContent.js @@ -50,7 +50,7 @@ export default class InterfaceColContent extends Component { } else { this.props.history.push('/project/' + params.id + '/interface/case/' + currCaseId) } - this.props.setColData({currColId, currCaseId}) + this.props.setColData({currColId: +currColId, currCaseId: +currCaseId}) } render() { diff --git a/client/containers/Project/Interface/InterfaceCol/InterfaceColMenu.js b/client/containers/Project/Interface/InterfaceCol/InterfaceColMenu.js index a219c41b..881079a4 100644 --- a/client/containers/Project/Interface/InterfaceCol/InterfaceColMenu.js +++ b/client/containers/Project/Interface/InterfaceCol/InterfaceColMenu.js @@ -45,7 +45,8 @@ export default class InterfaceColMenu extends Component { state = { addColModalVisible: false, addColName: '', - addColDesc: '' + addColDesc: '', + expandedKeys: [] } constructor(props) { @@ -84,25 +85,25 @@ export default class InterfaceColMenu extends Component { } } - @autobind - async onSelect(key) { - const type = key.split('_')[0]; - const id = key.split('_')[1]; + onSelect = (keys) => { + const type = keys[0].split('_')[0]; + const id = keys[0].split('_')[1]; if (type === 'col') { this.props.setColData({ isShowCol: true, - currColId: id + currColId: +id }) } else { this.props.setColData({ isShowCol: false, - currCaseId: id + currCaseId: +id }) } } render() { const { currColId, currCaseId, isShowCol } = this.props; + return (
@@ -113,9 +114,11 @@ export default class InterfaceColMenu extends Component {
this.setState({expandedKeys: keys})} > { this.props.interfaceColList.map((col) => ( diff --git a/client/reducer/modules/interfaceCol.js b/client/reducer/modules/interfaceCol.js index 1eb4083a..e560f188 100644 --- a/client/reducer/modules/interfaceCol.js +++ b/client/reducer/modules/interfaceCol.js @@ -45,7 +45,7 @@ export default (state = initialState, action) => { case SET_COL_DATA: { return { ...state, - ...action.payload.data + ...action.payload } } default: From 8021b055d88e56e37e1c0ebb4784c26d9327050d Mon Sep 17 00:00:00 2001 From: zwjamnsss Date: Fri, 18 Aug 2017 12:00:21 +0800 Subject: [PATCH 2/4] feat: col menu --- .../Project/Interface/InterfaceCol/InterfaceColMenu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/containers/Project/Interface/InterfaceCol/InterfaceColMenu.js b/client/containers/Project/Interface/InterfaceCol/InterfaceColMenu.js index 881079a4..493a4d9d 100644 --- a/client/containers/Project/Interface/InterfaceCol/InterfaceColMenu.js +++ b/client/containers/Project/Interface/InterfaceCol/InterfaceColMenu.js @@ -124,7 +124,7 @@ export default class InterfaceColMenu extends Component { this.props.interfaceColList.map((col) => ( {col.name}} + title={{col.name}} > { col.caseList && col.caseList.map((interfaceCase) => ( From 9bec5d6bb4082cae1c17838271ffde68667027c2 Mon Sep 17 00:00:00 2001 From: sean Date: Fri, 18 Aug 2017 12:07:14 +0800 Subject: [PATCH 3/4] fix: interfaceContent bug --- client/containers/Project/Interface/Interface.js | 2 +- .../Interface/InterfaceList/InterfaceContent.js | 12 +++++------- .../Project/Interface/InterfaceList/View.js | 1 + 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/client/containers/Project/Interface/Interface.js b/client/containers/Project/Interface/Interface.js index 206088d4..d5a6c308 100644 --- a/client/containers/Project/Interface/Interface.js +++ b/client/containers/Project/Interface/Interface.js @@ -71,7 +71,7 @@ class Interface extends Component {
- +
diff --git a/client/containers/Project/Interface/InterfaceList/InterfaceContent.js b/client/containers/Project/Interface/InterfaceList/InterfaceContent.js index 5ecbed4f..773eb582 100644 --- a/client/containers/Project/Interface/InterfaceList/InterfaceContent.js +++ b/client/containers/Project/Interface/InterfaceList/InterfaceContent.js @@ -48,15 +48,13 @@ class Content extends Component { handleRequest(nextProps) { let matchParams = nextProps.match.params; - let _actionId; - _actionId = matchParams.actionId || 0; - if (_actionId === 0 && (nextProps.list.length > 0)) { + + if (!matchParams.actionId && (nextProps.list.length > 0)) { return this.props.history.replace('/project/' + matchParams.id + '/interface/api/' + nextProps.list[0]._id) } - if (!nextProps.curdata) return; - if (this._actionId !== _actionId) { - this._actionId = _actionId; - this.props.fetchInterfaceData(_actionId) + if (matchParams.actionId && this._actionId !== matchParams.actionId) { + this._actionId = matchParams.actionId; + this.props.fetchInterfaceData(matchParams.actionId) } this.setState({ curtab: 'view' diff --git a/client/containers/Project/Interface/InterfaceList/View.js b/client/containers/Project/Interface/InterfaceList/View.js index 166405ba..d32e9b9a 100644 --- a/client/containers/Project/Interface/InterfaceList/View.js +++ b/client/containers/Project/Interface/InterfaceList/View.js @@ -193,6 +193,7 @@ class View extends Component { render () { const dataSource = []; + console.log(this.props.curData) if(this.props.curData.req_headers&&this.props.curData.req_headers.length){ this.props.curData.req_headers.map((item,i)=>{ dataSource.push({ From 2805ea0b82cbe02f914e977a8a7b91789cf7dfaa Mon Sep 17 00:00:00 2001 From: sean Date: Fri, 18 Aug 2017 12:37:32 +0800 Subject: [PATCH 4/4] fix: fix empty edit interface info --- .../Project/Interface/InterfaceList/Edit.js | 4 +-- .../InterfaceList/InterfaceEditForm.js | 30 ++++++++++++------- server/controllers/interface.js | 4 +++ server_dist/controllers/interface.js | 22 ++++++++------ 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/client/containers/Project/Interface/InterfaceList/Edit.js b/client/containers/Project/Interface/InterfaceList/Edit.js index 07052952..93f53ccb 100644 --- a/client/containers/Project/Interface/InterfaceList/Edit.js +++ b/client/containers/Project/Interface/InterfaceList/Edit.js @@ -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
{this.state.status === 1 ? diff --git a/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js b/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js index f0a21d8e..47c94ff1 100644 --- a/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js +++ b/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js @@ -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 }) } } } - + } } diff --git a/server/controllers/interface.js b/server/controllers/interface.js index 62e0e8ba..3700d38c 100644 --- a/server/controllers/interface.js +++ b/server/controllers/interface.js @@ -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; } diff --git a/server_dist/controllers/interface.js b/server_dist/controllers/interface.js index fcfca4ad..45213d7d 100644 --- a/server_dist/controllers/interface.js +++ b/server_dist/controllers/interface.js @@ -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) {