Merge branch 'dev' of gitlab.corp.qunar.com:mfe/yapi into dev

This commit is contained in:
wenbo.dong 2017-08-18 15:25:30 +08:00
commit e5eb0f6ec4
11 changed files with 118 additions and 43 deletions

View File

@ -71,7 +71,7 @@ class Interface extends Component {
<div className="right-content">
<Switch>
<Route exact path="/project/:id/interface/:action" component={InterfaceRoute} />
<Route path="/project/:id/interface/:action/:actionId" component={InterfaceRoute} />
<Route exact path="/project/:id/interface/:action/:actionId" component={InterfaceRoute} />
</Switch>
</div>
</Col>

View File

@ -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 <h1>hello caseContent</h1>
}
}

View File

@ -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() {

View File

@ -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 (
<div>
<div className="interface-filter">
@ -113,15 +114,17 @@ export default class InterfaceColMenu extends Component {
</div>
<Tree
className="col-list-tree"
defaultExpandedKeys={[''+currColId, ''+currCaseId]}
defaultSelectedKeys={[isShowCol ? ''+currColId : ''+currCaseId]}
expandedKeys={this.state.expandedKeys}
selectedKeys={[isShowCol ? 'col_'+currColId : 'case_'+currCaseId]}
onSelect={this.onSelect}
autoExpandParent
onExpand={keys => this.setState({expandedKeys: keys})}
>
{
this.props.interfaceColList.map((col) => (
<TreeNode
key={'col_' + col._id}
title={<span><Icon type="folder-open" /><span>{col.name}</span></span>}
title={<span><Icon type="folder-open" style={{marginRight: 5}} /><span>{col.name}</span></span>}
>
{
col.caseList && col.caseList.map((interfaceCase) => (

View File

@ -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} />

View File

@ -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'

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_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 })
}
}
}
}
}

View File

@ -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({

View File

@ -45,7 +45,7 @@ export default (state = initialState, action) => {
case SET_COL_DATA: {
return {
...state,
...action.payload.data
...action.payload
}
}
default:

View File

@ -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;
}

View File

@ -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) {