diff --git a/client/components/Postman/Postman.js b/client/components/Postman/Postman.js index dcc2207c..1d0213ff 100644 --- a/client/components/Postman/Postman.js +++ b/client/components/Postman/Postman.js @@ -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 { + style={{marginLeft: 10}} + >{this.props.type === 'inter' ? '保存' : '更新'} @@ -531,14 +540,21 @@ export default class Run extends Component { -
-
+
+ + -
-
+ + + + +
diff --git a/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js b/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js index 7afddce2..130930c4 100644 --- a/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js +++ b/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js @@ -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 {

{currCase.casename}

- +
) diff --git a/client/containers/Project/Interface/InterfaceList/Run/Run.js b/client/containers/Project/Interface/InterfaceList/Run/Run.js index fcd99e4f..552cede0 100644 --- a/client/containers/Project/Interface/InterfaceList/Run/Run.js +++ b/client/containers/Project/Interface/InterfaceList/Run/Run.js @@ -86,7 +86,7 @@ export default class Run extends Component { return (
- this.setState({saveCaseModalVisible: true})} ref={this.savePostmanRef} /> + this.setState({saveCaseModalVisible: true})} ref={this.savePostmanRef} /> this.setState({saveCaseModalVisible: false})} diff --git a/server/controllers/interfaceCol.js b/server/controllers/interfaceCol.js index 11c0b7ae..0ed7fdcf 100644 --- a/server/controllers/interfaceCol.js +++ b/server/controllers/interfaceCol.js @@ -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); diff --git a/server_dist/controllers/interfaceCol.js b/server_dist/controllers/interfaceCol.js index bb2c49d6..83711415 100644 --- a/server_dist/controllers/interfaceCol.js +++ b/server_dist/controllers/interfaceCol.js @@ -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) { diff --git a/server_dist/router.js b/server_dist/router.js index da6e1bc5..d93b4552 100644 --- a/server_dist/router.js +++ b/server_dist/router.js @@ -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) {