This commit is contained in:
qitmac000249 2017-08-24 11:13:16 +08:00
commit 1799088ac8
6 changed files with 93 additions and 73 deletions

View File

@ -1,7 +1,7 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
// import { connect } from 'react-redux'
import { Button, Input, Select, Card, Alert, Spin, Icon, Collapse, Radio, Tooltip } from 'antd'
import { Button, Input, Select, Card, Alert, Spin, Icon, Collapse, Radio, Tooltip, message } from 'antd'
import { autobind } from 'core-decorators';
import crossRequest from 'cross-request';
// import { withRouter } from 'react-router';
@ -25,15 +25,14 @@ export default class Run extends Component {
static propTypes = {
data: PropTypes.object,
save: PropTypes.oneOfType([
PropTypes.bool,
PropTypes.func
]),
saveTip: PropTypes.string
save: PropTypes.func,
saveTip: PropTypes.string,
type: PropTypes.string
}
state = {
res: '',
resHeader: '',
method: 'GET',
domains: [],
pathname: '',
@ -62,7 +61,7 @@ export default class Run extends Component {
@autobind
getInterfaceState(nextProps) {
const props = nextProps || this.props;
const { data } = props;
const { data, type } = props;
const {
method = '',
path: url = '',
@ -76,7 +75,8 @@ export default class Run extends Component {
env = [],
domain = ''
} = data;
const pathname = (basepath + url).replace(/\/+/g, '/');
// case 任意编辑 pathname不管项目的 basepath
const pathname = (type === 'inter' ? (basepath + url) : url).replace(/\/+/g, '/');
let hasContentType = false;
req_headers.forEach(headerItem => {
@ -129,17 +129,26 @@ export default class Run extends Component {
headers: this.getHeadersObj(headers),
data: bodyType === 'form' ? this.arrToObj(bodyForm) : bodyOther,
files: bodyType === 'form' ? this.getFiles(bodyForm) : {},
success: (res) => {
try {
res = JSON.parse(res)
} catch (e) {
null
}
this.setState({res})
success: (res, header) => {
// try {
// res = JSON.parse(res)
// header = JSON.parse(header)
// } catch (e) {
// message.error(e.message)
// }
message.success('请求完成')
this.setState({res, resHeader: header})
this.setState({ loading: false })
},
error: (err) => {
this.setState({res: err || '请求失败'})
error: (err, header) => {
// try {
// err = JSON.parse(err)
// header = JSON.parse(header)
// } catch (e) {
// message.error(e.message)
// }
message.success('请求完成')
this.setState({res: err || '请求失败', resHeader: header})
this.setState({ loading: false })
}
})
@ -407,8 +416,8 @@ export default class Run extends Component {
<Button
onClick={this.props.save}
type="primary"
style={{marginLeft: 10, display: this.props.save === false ? 'none' : ''}}
>保存</Button>
style={{marginLeft: 10}}
>{this.props.type === 'inter' ? '保存' : '更新'}</Button>
</Tooltip>
</div>
@ -531,14 +540,21 @@ export default class Run extends Component {
<Card title="返回结果" noHovering className="resp-part">
<Spin spinning={this.state.loading}>
<div className="res-part">
<div style={{padding: 10}}>
<div className="res-code"></div>
<Collapse defaultActiveKey={['0', '1']} bordered={true}>
<Panel header="BODY" key="0" >
<TextArea
value={typeof this.state.res === 'object' ? JSON.stringify(this.state.res, null, 2) : this.state.res.toString()}
autosize={{ minRows: 2, maxRows: 6 }}
autosize={{ minRows: 2, maxRows: 10 }}
></TextArea>
</div>
</div>
</Panel>
<Panel header="HEADERS" key="1" >
<TextArea
value={typeof this.state.resHeader === 'object' ? JSON.stringify(this.state.resHeader, null, 2) : this.state.resHeader.toString()}
autosize={{ minRows: 2, maxRows: 10 }}
></TextArea>
</Panel>
</Collapse>
</Spin>
</Card>
</div>

View File

@ -2,6 +2,8 @@ import React, { Component } from 'react'
import { connect } from 'react-redux';
import PropTypes from 'prop-types'
import { withRouter } from 'react-router'
import axios from 'axios'
import { message } from 'antd'
import { fetchInterfaceColList, setColData, fetchCaseData } from '../../../../reducer/modules/interfaceCol'
import { Postman } from '../../../../components'
@ -77,40 +79,42 @@ export default class InterfaceCaseContent extends Component {
}
}
// updateCase = () => {
// const project_id = this.props.match.params.id;
// const {
// currDomain: domain,
// pathname: path,
// method,
// pathParam: req_params,
// query: req_query,
// headers: req_headers,
// bodyType: req_body_type,
// bodyForm: req_body_form,
// bodyOther: req_body_other
// } = this.postman.state;
// const res = await axios.post('/api/col/add_case', {
// casename: caseName,
// col_id: colId,
// project_id,
// domain,
// path,
// method,
// req_params,
// req_query,
// req_headers,
// req_body_type,
// req_body_form,
// req_body_other
// });
// if (res.data.errcode) {
// message.error(res.data.errmsg)
// } else {
// message.success('添加成功')
// this.setState({saveCaseModalVisible: false})
// }
// }
savePostmanRef = (postman) => {
this.postman = postman;
}
updateCase = async () => {
const {
currDomain: domain,
pathname: path,
method,
pathParam: req_params,
query: req_query,
headers: req_headers,
bodyType: req_body_type,
bodyForm: req_body_form,
bodyOther: req_body_other
} = this.postman.state;
const {_id: id, casename} = this.props.currCase;
const res = await axios.post('/api/col/up_case', {
id,
casename,
domain,
path,
method,
req_params,
req_query,
req_headers,
req_body_type,
req_body_form,
req_body_other
});
if (res.data.errcode) {
message.error(res.data.errmsg)
} else {
message.success('更新成功')
}
}
render() {
const { currCase, currProject } = this.props;
@ -119,7 +123,7 @@ export default class InterfaceCaseContent extends Component {
<div>
<h1 style={{marginLeft: 8}}>{currCase.casename}</h1>
<div>
<Postman data={data} saveTip="更新保存用例" save={false} />
<Postman data={data} type="case" saveTip="更新保存修改" save={this.updateCase} ref={this.savePostmanRef} />
</div>
</div>
)

View File

@ -86,7 +86,7 @@ export default class Run extends Component {
return (
<div>
<Postman data={data} saveTip="保存到集合" save={() => this.setState({saveCaseModalVisible: true})} ref={this.savePostmanRef} />
<Postman data={data} type="inter" saveTip="保存到集合" save={() => this.setState({saveCaseModalVisible: true})} ref={this.savePostmanRef} />
<AddColModal
visible={this.state.saveCaseModalVisible}
onCancel={() => this.setState({saveCaseModalVisible: false})}

View File

@ -199,7 +199,7 @@ class interfaceColController extends baseController{
params.uid = this.getUid();
let result = await this.caseModel.up(params);
let result = await this.caseModel.up(params.id, params);
ctx.body = yapi.commons.resReturn(result);

View File

@ -74,7 +74,7 @@ var interfaceColController = function (_baseController) {
(0, _createClass3.default)(interfaceColController, [{
key: 'list',
value: function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(ctx) {
var id, result, i;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
@ -149,7 +149,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'addCol',
value: function () {
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2(ctx) {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(ctx) {
var params, result;
return _regenerator2.default.wrap(function _callee2$(_context2) {
while (1) {
@ -233,7 +233,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'getCaseList',
value: function () {
var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3(ctx) {
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(ctx) {
var id, inst, result;
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
@ -297,7 +297,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'addCase',
value: function () {
var _ref4 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee4(ctx) {
var _ref4 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4(ctx) {
var params, result;
return _regenerator2.default.wrap(function _callee4$(_context4) {
while (1) {
@ -399,7 +399,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'upCase',
value: function () {
var _ref5 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee5(ctx) {
var _ref5 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee5(ctx) {
var params, result;
return _regenerator2.default.wrap(function _callee5$(_context5) {
while (1) {
@ -435,7 +435,7 @@ var interfaceColController = function (_baseController) {
params.uid = this.getUid();
_context5.next = 10;
return this.caseModel.up(params);
return this.caseModel.up(params.id, params);
case 10:
result = _context5.sent;
@ -481,7 +481,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'getCase',
value: function () {
var _ref6 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee6(ctx) {
var _ref6 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee6(ctx) {
var id, result;
return _regenerator2.default.wrap(function _callee6$(_context6) {
while (1) {
@ -535,7 +535,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'upCol',
value: function () {
var _ref7 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee7(ctx) {
var _ref7 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee7(ctx) {
var params, result;
return _regenerator2.default.wrap(function _callee7$(_context7) {
while (1) {
@ -592,7 +592,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'upCaseIndex',
value: function () {
var _ref8 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee8(ctx) {
var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(ctx) {
var _this2 = this;
var params;
@ -651,7 +651,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'delCol',
value: function () {
var _ref9 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee9(ctx) {
var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee9(ctx) {
var id, colData, auth, result;
return _regenerator2.default.wrap(function _callee9$(_context9) {
while (1) {
@ -728,7 +728,7 @@ var interfaceColController = function (_baseController) {
}, {
key: 'delCase',
value: function () {
var _ref10 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee10(ctx) {
var _ref10 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee10(ctx) {
var caseid, caseData, auth, result;
return _regenerator2.default.wrap(function _callee10$(_context10) {
while (1) {

View File

@ -355,7 +355,7 @@ function createAction(controller, action, path, method) {
var _this = this;
router[method]("/api" + INTERFACE_CONFIG[controller].prefix + path, function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(ctx) {
var inst;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {