From fa510e96087f95db33ff72549d859e4495e6dcf0 Mon Sep 17 00:00:00 2001 From: sean Date: Mon, 14 Aug 2017 19:58:33 +0800 Subject: [PATCH 1/2] feat: add interface res some module --- client/components/Header/Header.js | 2 +- .../InterfaceList/InterfaceEditForm.js | 112 ++++++++++++++---- .../Interface/InterfaceList/mockEditor.js | 7 +- server/controllers/interfaceCol.js | 13 +- server/models/interface.js | 16 +-- server/models/interfaceCase.js | 12 +- server_dist/controllers/interfaceCol.js | 70 +++++------ server_dist/models/interface.js | 16 +-- server_dist/models/interfaceCase.js | 12 +- 9 files changed, 155 insertions(+), 105 deletions(-) diff --git a/client/components/Header/Header.js b/client/components/Header/Header.js index f33a980b..d7ae2071 100644 --- a/client/components/Header/Header.js +++ b/client/components/Header/Header.js @@ -165,7 +165,7 @@ export default class HeaderCom extends Component {
- + YAPI
diff --git a/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js b/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js index 46819cb3..2219bddf 100644 --- a/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js +++ b/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js @@ -35,13 +35,15 @@ class InterfaceEditForm extends Component { req_body_type: 'form', req_headers: [{ name: 'Content-Type', - value: 'application/urlencode', required: "1" + value: 'application/x-www-form-urlencoded', required: "1" }], req_body_form: [{ name: 'id', type: 'text', required: '1' - }] + }], + res_body_type: 'json', + res_body: '' } } @@ -50,20 +52,29 @@ class InterfaceEditForm extends Component { this.props.form.validateFields((err, values) => { if (!err) { console.log('Received values of form: ', values); - console.log(this.props.form.getFieldValue('keys')) } }); } componentDidMount() { + let that = this; mockEditor({ container: 'req_body_json', - data: { - name: "@name" - }, + data: that.state.req_body_json, onChange: function (d) { - console.log(this) - console.log(d) + that.setState({ + req_body_json: d.text + }) + } + }) + + mockEditor({ + container: 'res_body_json', + data: that.state.res_body, + onChange: function (d) { + that.setState({ + res_body: d.text + }) } }) } @@ -294,33 +305,94 @@ class InterfaceEditForm extends Component { form json file + raw )} + {this.props.form.getFieldValue('req_body_type') === 'form' ? + + + + - - - - + - + - + + {requestBodyList} + - - {requestBodyList} - + + : + null + } - - - + + + + + {this.props.form.getFieldValue('req_body_type') === 'file' ? + + + {getFieldDecorator('req_body_other', { initialValue: this.state.req_body_other })( + + )} + + + + + : + null + } + {this.props.form.getFieldValue('req_body_type') === 'raw' ? + + + {getFieldDecorator('req_body_other', { initialValue: this.state.req_body_other })( + + )} + + + : null + } + + + {getFieldDecorator('res_body_type', { + initialValue: this.state.res_body_type + })( + + json + raw + + + )} + + + + + + + + + {getFieldDecorator('req_body_other', { initialValue: this.state.res_body })( + + )} + + + + + + diff --git a/client/containers/Project/Interface/InterfaceList/mockEditor.js b/client/containers/Project/Interface/InterfaceList/mockEditor.js index 90332287..f7c01589 100644 --- a/client/containers/Project/Interface/InterfaceList/mockEditor.js +++ b/client/containers/Project/Interface/InterfaceList/mockEditor.js @@ -3,8 +3,6 @@ var ace = require('brace'), require('brace/mode/javascript'); require('brace/theme/xcode'); require("brace/ext/language_tools.js"); -require("brace/snippets/javascript.js"); - var json5 = require('json5'); var langTools = ace.acequire("ace/ext/language_tools"), @@ -76,8 +74,9 @@ function run(options) { editor.setTheme('ace/theme/xcode'); editor.setOptions({ enableBasicAutocompletion: true, - enableSnippets: true, - enableLiveAutocompletion: true + enableSnippets: false, + enableLiveAutocompletion: true, + useWorker: false }); mockEditor = { curData: {}, diff --git a/server/controllers/interfaceCol.js b/server/controllers/interfaceCol.js index 6e372b2e..5196ae6e 100644 --- a/server/controllers/interfaceCol.js +++ b/server/controllers/interfaceCol.js @@ -24,6 +24,11 @@ class interfaceColController extends baseController{ try { let id = ctx.query.project_id; let result = await this.colModel.list(id); + + for(let i=0; i< result.length;i++){ + result[i] = result[i].toObject(); + result[i].caseList = await this.caseModel.list(result[i]._id) + } ctx.body = yapi.commons.resReturn(result); } catch (e) { ctx.body = yapi.commons.resReturn(null, 402, e.message); @@ -134,13 +139,7 @@ class interfaceColController extends baseController{ return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空'); } if (!params.col_id) { - return ctx.body = yapi.commons.resReturn(null, 400, '项目id不能为空'); - } - if (!params.env) { - return ctx.body = yapi.commons.resReturn(null, 400, '缺少环境配置'); - } - if (!params.path) { - return ctx.body = yapi.commons.resReturn(null, 400, 'path 不能为空'); + return ctx.body = yapi.commons.resReturn(null, 400, '接口集id不能为空'); } diff --git a/server/models/interface.js b/server/models/interface.js index 441e7125..2be3710a 100644 --- a/server/models/interface.js +++ b/server/models/interface.js @@ -42,26 +42,12 @@ class interfaceModel extends baseModel { default: "1" } }], - req_body_json_doc: [{ - json_path: String, desc: String,required:{ - type:String, - enum: ["1", "0"], - default: "1" - } - }], req_body_other: String, res_body_type: { type: String, enum: ['json', 'text', 'xml'] }, - res_body: String, - res_body_json_doc: [{ - json_path: String, desc: String,required:{ - type:String, - enum: ["1", "0"], - default: "1" - } - }] + res_body: String }; } diff --git a/server/models/interfaceCase.js b/server/models/interfaceCase.js index bb1524b7..481d9421 100644 --- a/server/models/interfaceCase.js +++ b/server/models/interfaceCase.js @@ -15,10 +15,10 @@ class interfaceCase extends baseModel { project_id: { type: Number, required: true }, add_time: Number, up_time: Number, - env: { type: String, required: true }, + env: { type: String }, domain: {type: String }, - path: { type: String, required: true }, - method: { type: String, required: true }, + path: { type: String }, + method: { type: String }, req_query: [{ name: String, value: String }], @@ -48,8 +48,10 @@ class interfaceCase extends baseModel { }).exec(); } - list() { - return this.model.find().select("casename uid col_id _id index").exec(); + list(col_id) { + return this.model.find({ + col_id: col_id + }).select("casename uid col_id _id index").exec(); } del(id) { diff --git a/server_dist/controllers/interfaceCol.js b/server_dist/controllers/interfaceCol.js index 712693a3..862f037c 100644 --- a/server_dist/controllers/interfaceCol.js +++ b/server_dist/controllers/interfaceCol.js @@ -75,7 +75,7 @@ var interfaceColController = function (_baseController) { key: 'list', value: function () { var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(ctx) { - var id, result; + var id, result, i; return _regenerator2.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { @@ -87,23 +87,43 @@ var interfaceColController = function (_baseController) { case 4: result = _context.sent; + i = 0; - ctx.body = _yapi2.default.commons.resReturn(result); - _context.next = 11; + case 6: + if (!(i < result.length)) { + _context.next = 14; + break; + } + + result[i] = result[i].toObject(); + _context.next = 10; + return this.caseModel.list(result[i]._id); + + case 10: + result[i].caseList = _context.sent; + + case 11: + i++; + _context.next = 6; break; - case 8: - _context.prev = 8; + case 14: + ctx.body = _yapi2.default.commons.resReturn(result); + _context.next = 20; + break; + + case 17: + _context.prev = 17; _context.t0 = _context['catch'](0); ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message); - case 11: + case 20: case 'end': return _context.stop(); } } - }, _callee, this, [[0, 8]]); + }, _callee, this, [[0, 17]]); })); function list(_x) { @@ -309,62 +329,46 @@ var interfaceColController = function (_baseController) { break; } - return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空')); + return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口集id不能为空')); case 7: - if (params.env) { - _context4.next = 9; - break; - } - - return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '缺少环境配置')); - - case 9: - if (params.path) { - _context4.next = 11; - break; - } - - return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, 'path 不能为空')); - - case 11: if (params.casename) { - _context4.next = 13; + _context4.next = 9; break; } return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '用例名称不能为空')); - case 13: + case 9: params.uid = this.getUid(); params.index = 0; params.add_time = _yapi2.default.commons.time(); params.up_time = _yapi2.default.commons.time(); - _context4.next = 19; + _context4.next = 15; return this.caseModel.save(params); - case 19: + case 15: result = _context4.sent; ctx.body = _yapi2.default.commons.resReturn(result); - _context4.next = 26; + _context4.next = 22; break; - case 23: - _context4.prev = 23; + case 19: + _context4.prev = 19; _context4.t0 = _context4['catch'](0); ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message); - case 26: + case 22: case 'end': return _context4.stop(); } } - }, _callee4, this, [[0, 23]]); + }, _callee4, this, [[0, 19]]); })); function addCase(_x4) { diff --git a/server_dist/models/interface.js b/server_dist/models/interface.js index de19d3f0..fb1a8f13 100644 --- a/server_dist/models/interface.js +++ b/server_dist/models/interface.js @@ -81,26 +81,12 @@ var interfaceModel = function (_baseModel) { default: "1" } }], - req_body_json_doc: [{ - json_path: String, desc: String, required: { - type: String, - enum: ["1", "0"], - default: "1" - } - }], req_body_other: String, res_body_type: { type: String, enum: ['json', 'text', 'xml'] }, - res_body: String, - res_body_json_doc: [{ - json_path: String, desc: String, required: { - type: String, - enum: ["1", "0"], - default: "1" - } - }] + res_body: String }; } }, { diff --git a/server_dist/models/interfaceCase.js b/server_dist/models/interfaceCase.js index 5b8f5ba4..02b0dda0 100644 --- a/server_dist/models/interfaceCase.js +++ b/server_dist/models/interfaceCase.js @@ -54,10 +54,10 @@ var interfaceCase = function (_baseModel) { project_id: { type: Number, required: true }, add_time: Number, up_time: Number, - env: { type: String, required: true }, + env: { type: String }, domain: { type: String }, - path: { type: String, required: true }, - method: { type: String, required: true }, + path: { type: String }, + method: { type: String }, req_query: [{ name: String, value: String }], @@ -90,8 +90,10 @@ var interfaceCase = function (_baseModel) { } }, { key: 'list', - value: function list() { - return this.model.find().select("casename uid col_id _id index").exec(); + value: function list(col_id) { + return this.model.find({ + col_id: col_id + }).select("casename uid col_id _id index").exec(); } }, { key: 'del', From 04791fa39e362a9f035d02c505aaa233efe6ae58 Mon Sep 17 00:00:00 2001 From: sean Date: Mon, 14 Aug 2017 20:09:47 +0800 Subject: [PATCH 2/2] fix: message login when guest open site --- client/reducer/middleware/messageMiddleware.js | 2 +- server/controllers/base.js | 2 +- server/router.js | 2 +- server_dist/controllers/base.js | 2 +- server_dist/router.js | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/reducer/middleware/messageMiddleware.js b/client/reducer/middleware/messageMiddleware.js index 8abb3d5d..5c16bde7 100644 --- a/client/reducer/middleware/messageMiddleware.js +++ b/client/reducer/middleware/messageMiddleware.js @@ -3,7 +3,7 @@ import { message } from 'antd'; export default () => next => action => { if (action.error) { message.error((action.payload && action.payload.message) || '服务器错误'); - } else if (action.payload && action.payload.data && action.payload.data.errcode) { + } else if (action.payload && action.payload.data && action.payload.data.errcode && action.payload.data.errcode !== 40011) { message.error(action.payload.data.errmsg); } return next(action); diff --git a/server/controllers/base.js b/server/controllers/base.js index f71c8dc8..781eed53 100644 --- a/server/controllers/base.js +++ b/server/controllers/base.js @@ -72,7 +72,7 @@ class baseController { result.server_ip = yapi.WEBCONFIG.server_ip; return ctx.body = yapi.commons.resReturn(result); } - return ctx.body = yapi.commons.resReturn(null, 300, 'Please login.'); + return ctx.body = yapi.commons.resReturn(null, 40011, '请登录...'); } getRole() { diff --git a/server/router.js b/server/router.js index 84a4115e..1dfd5b2c 100644 --- a/server/router.js +++ b/server/router.js @@ -320,7 +320,7 @@ function createAction(controller, action, path, method) { if (inst.$auth === true) { await inst[action].call(inst, ctx); } else { - ctx.body = yapi.commons.resReturn(null, 40011, '请登录.'); + ctx.body = yapi.commons.resReturn(null, 40011, '请登录...'); } }); } diff --git a/server_dist/controllers/base.js b/server_dist/controllers/base.js index d5b02e1b..3cdad72b 100644 --- a/server_dist/controllers/base.js +++ b/server_dist/controllers/base.js @@ -193,7 +193,7 @@ var baseController = function () { return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(result)); case 7: - return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 300, 'Please login.')); + return _context3.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 40011, '请登录...')); case 8: case 'end': diff --git a/server_dist/router.js b/server_dist/router.js index 68b8c1ef..bc493ebf 100644 --- a/server_dist/router.js +++ b/server_dist/router.js @@ -339,7 +339,7 @@ function createAction(controller, action, path, method) { break; case 8: - ctx.body = _yapi2.default.commons.resReturn(null, 40011, '请登录.'); + ctx.body = _yapi2.default.commons.resReturn(null, 40011, '请登录...'); case 9: case 'end':