From fc3ccf25403a20de12ce9ba4dd958029bc12ef61 Mon Sep 17 00:00:00 2001 From: "waliang.wang" Date: Tue, 25 Jul 2017 15:11:43 +0800 Subject: [PATCH 1/7] =?UTF-8?q?feat=20-=20=E6=9C=80=E6=96=B0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/containers/AddInterface/Result/Result.js | 2 +- package.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/client/containers/AddInterface/Result/Result.js b/client/containers/AddInterface/Result/Result.js index 89185937..18133daa 100644 --- a/client/containers/AddInterface/Result/Result.js +++ b/client/containers/AddInterface/Result/Result.js @@ -3,7 +3,7 @@ import { Tabs } from 'antd' import Mock from 'mockjs' import { connect } from 'react-redux' import PropTypes from 'prop-types' - +console.log('测试') @connect( state => { return { diff --git a/package.json b/package.json index fc957728..7bb1ea9a 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "babel-plugin-transform-decorators-legacy": "^1.3.4", "copy-webpack-plugin": "^4.0.1", "core-decorators": "^0.17.0", + "fast-sass-loader": "^1.2.5", "fs-extra": "^3.0.1", "jsoneditor": "^5.9.3", "jsonwebtoken": "^7.4.1", From ee31f5cb4ce8ee6f4c65199e97c4823079db457a Mon Sep 17 00:00:00 2001 From: "waliang.wang" Date: Tue, 25 Jul 2017 17:41:58 +0800 Subject: [PATCH 2/7] =?UTF-8?q?feat=20-=20=E4=BF=AE=E6=94=B9=E8=B7=AF?= =?UTF-8?q?=E7=94=B1=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Header/Header.js | 4 ++-- client/containers/AddInterface/AddInterface.js | 10 ++++++---- .../containers/AddInterface/ResParams/ResParams.js | 4 +--- client/containers/Interface/Interface.js | 11 +++++++++-- client/containers/Interface/Interface.scss | 2 +- .../Interface/InterfaceList/InterfaceList.js | 14 +++++++++++--- .../ProjectGroups/ProjectList/ProjectList.js | 2 +- 7 files changed, 31 insertions(+), 16 deletions(-) diff --git a/client/components/Header/Header.js b/client/components/Header/Header.js index 982d6b68..4a4d96ff 100644 --- a/client/components/Header/Header.js +++ b/client/components/Header/Header.js @@ -142,8 +142,8 @@ class HeaderCom extends Component { 首页 - - 分组 + + 分组 接口 diff --git a/client/containers/AddInterface/AddInterface.js b/client/containers/AddInterface/AddInterface.js index 5dfdb26e..38ad4144 100644 --- a/client/containers/AddInterface/AddInterface.js +++ b/client/containers/AddInterface/AddInterface.js @@ -73,6 +73,7 @@ class AddInterface extends Component { let interfaceId = undefined if (ifTrue) { interfaceId = this.getInterfaceId() + console.log('interfaceId', interfaceId) this.initInterfaceData(interfaceId) } else { const props = this.props @@ -91,8 +92,10 @@ class AddInterface extends Component { } getInterfaceId () { - const value = location.hash.match(/\d+/g) - return value ? value[0] : '' + const reg = /AddInterface\/edit\/(\d+)/g + const url = location.href + url.match(reg) + return RegExp.$1 } verificationURL () { @@ -159,7 +162,7 @@ class AddInterface extends Component { path: url, method: 'POST', req_headers: seqGroup, - project_id: 558, + project_id: interfaceId, req_params_type: 'json', req_params_other: reqParams, res_body_type: 'json', @@ -180,7 +183,6 @@ class AddInterface extends Component { this.setLoading() success() this.changeState(true) - // this.routerPage() }) .catch(e => { console.log(e) diff --git a/client/containers/AddInterface/ResParams/ResParams.js b/client/containers/AddInterface/ResParams/ResParams.js index 475aed33..32681c0d 100644 --- a/client/containers/AddInterface/ResParams/ResParams.js +++ b/client/containers/AddInterface/ResParams/ResParams.js @@ -38,10 +38,8 @@ class ResParams extends Component { const reg = /(

)|(<\/p>)| |(
)|\s+|

|<\/div>/g editor.customConfig.menus = [] editor.customConfig.onchange = html => { - console.log(html) - html = html.match(/{.*}/g)[0] + // html = html.match(/{.*}/g)[0] html = html.replace(reg, '') - console.log(html) this.props.getResParams(html) } setTimeout(() => { diff --git a/client/containers/Interface/Interface.js b/client/containers/Interface/Interface.js index 88852848..0a96066a 100644 --- a/client/containers/Interface/Interface.js +++ b/client/containers/Interface/Interface.js @@ -42,10 +42,10 @@ class Interface extends Component { } componentWillMount () { - // 558 665 704 743 + const interfaceId = this.getInterfaceId() const params = { params: { - project_id: 558 + project_id: interfaceId } } @@ -63,6 +63,13 @@ class Interface extends Component { }) } + getInterfaceId () { + const reg = /Interface\/(\d+)/g + const url = location.href + url.match(reg) + return RegExp.$1 + } + render () { const { interfaceData, projectMember, modalVisible } = this.props return ( diff --git a/client/containers/Interface/Interface.scss b/client/containers/Interface/Interface.scss index 308e672f..07489b8f 100644 --- a/client/containers/Interface/Interface.scss +++ b/client/containers/Interface/Interface.scss @@ -32,7 +32,7 @@ .interface-table { -webkit-box-flex: 1; - margin: 0 0 0 20px; + margin: 0 20px; .ant-table-wrapper table { font-size: .14rem; diff --git a/client/containers/Interface/InterfaceList/InterfaceList.js b/client/containers/Interface/InterfaceList/InterfaceList.js index e7cfe677..b0720f50 100644 --- a/client/containers/Interface/InterfaceList/InterfaceList.js +++ b/client/containers/Interface/InterfaceList/InterfaceList.js @@ -11,16 +11,24 @@ class InterfaceList extends Component { super(props) } + getInterfaceId () { + const reg = /Interface\/(\d+)/g + const url = location.href + url.match(reg) + return RegExp.$1 + } + render () { const { projectMember } = this.props - + const getInterfaceId = this.getInterfaceId() + console.log(`/AddInterface/${getInterfaceId}`) return (
    -
  • 添加接口
  • +
  • 添加接口
  • 管理项目成员
) } } -export default InterfaceList \ No newline at end of file +export default InterfaceList diff --git a/client/containers/ProjectGroups/ProjectList/ProjectList.js b/client/containers/ProjectGroups/ProjectList/ProjectList.js index 6c2130c8..ee6138eb 100644 --- a/client/containers/ProjectGroups/ProjectList/ProjectList.js +++ b/client/containers/ProjectGroups/ProjectList/ProjectList.js @@ -41,7 +41,7 @@ const getColumns = (data, props) => { dataIndex: 'name', key: 'name', render: (text, record) => { - return {text} + return {text} } }, { title: '创建人', From 4f8dfa7dd6d33da8ca7891ec90a5b81c45a6712d Mon Sep 17 00:00:00 2001 From: "waliang.wang" Date: Wed, 26 Jul 2017 12:31:42 +0800 Subject: [PATCH 3/7] =?UTF-8?q?feat=20-=20=E8=B0=83=E8=AF=95=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../containers/AddInterface/AddInterface.js | 55 +++++++++++----- .../containers/AddInterface/AddInterface.scss | 66 +++++++++++-------- .../AddInterface/ReqHeader/ReqList.js | 3 +- .../AddInterface/ReqParams/ParamsList.js | 3 +- .../AddInterface/ReqParams/ReqParams.js | 11 ++-- .../AddInterface/ResParams/ResParams.js | 14 ++-- .../containers/AddInterface/Result/Result.js | 21 ++---- package.json | 1 + 8 files changed, 104 insertions(+), 70 deletions(-) diff --git a/client/containers/AddInterface/AddInterface.js b/client/containers/AddInterface/AddInterface.js index 38ad4144..6dd78135 100644 --- a/client/containers/AddInterface/AddInterface.js +++ b/client/containers/AddInterface/AddInterface.js @@ -2,6 +2,7 @@ import './AddInterface.scss' import React, { Component } from 'react' import PropTypes from 'prop-types' import axios from 'axios' +import Mock from 'mockjs' import { connect } from 'react-redux' import { autobind } from 'core-decorators' import { Button, Tabs, message } from 'antd' @@ -64,16 +65,21 @@ class AddInterface extends Component { super(props) this.state = { isLoading: '', - isSave: false + isSave: false, + mockJson: '' } } componentDidMount () { const ifTrue = this.verificationURL() + const initData = [{ + id: 0, + name: '', + value: '' + }] let interfaceId = undefined if (ifTrue) { interfaceId = this.getInterfaceId() - console.log('interfaceId', interfaceId) this.initInterfaceData(interfaceId) } else { const props = this.props @@ -81,21 +87,21 @@ class AddInterface extends Component { props.pushInterfaceName('') props.getReqParams('') props.getResParams('') - props.addReqHeader([ - { - id: 0, - name: '', - value: '' - } - ]) + props.addReqHeader(initData) } } getInterfaceId () { const reg = /AddInterface\/edit\/(\d+)/g + const regTwo = /AddInterface\/(\d+)/g const url = location.href - url.match(reg) - return RegExp.$1 + if ( url.match(reg) ) { + return RegExp.$1 + } else { + url.match(regTwo) + return RegExp.$1 + } + } verificationURL () { @@ -127,6 +133,8 @@ class AddInterface extends Component { return value }) this.editState(result) + // 初始化 mock + this.mockData() }) .catch(e => { console.log(e) @@ -151,6 +159,21 @@ class AddInterface extends Component { }) } + @autobind + mockData () { // mock 数据 + let resParams = '' + let json = '' + + if(this.props.resParams){ + resParams = JSON.parse(this.props.resParams) + json = JSON.stringify(Mock.mock(resParams), null, 2) + } + console.log('json', json) + this.setState({ + mockJson: json + }) + } + @autobind saveForms () { let postURL = undefined @@ -191,21 +214,21 @@ class AddInterface extends Component { render () { const TabPane = Tabs.TabPane - const { isLoading, isSave } = this.state - + const { isLoading, isSave, mockJson='' } = this.state + console.log('mockJson', mockJson) return (
+ - + - mock 测试
@@ -216,5 +239,3 @@ class AddInterface extends Component { } export default AddInterface - - diff --git a/client/containers/AddInterface/AddInterface.scss b/client/containers/AddInterface/AddInterface.scss index 7aa9cec9..5c4ecc9c 100644 --- a/client/containers/AddInterface/AddInterface.scss +++ b/client/containers/AddInterface/AddInterface.scss @@ -9,11 +9,16 @@ margin: 0 auto; background: #FFF; padding: 10px 20px 50px 20px; - + .save { float: right; margin: 0 0 10px 0; } + + .mock { + float: right; + margin: 0 15px 0 0; + } table { width: 100%; @@ -38,7 +43,7 @@ .url { margin: 0 0 0 15px; - width: 57.8%; + width: 61.2%; } } @@ -93,40 +98,47 @@ margin: 20px 0 0 0; border-top: 1px #EEE solid; } + + .res-params-box { + display: inline-block; + width: 530px; + float: left; + + /* .req-save.css */ + .res-params { + display: -webkit-box; + line-height: 32px; + padding: 20px 0 0 0; + border-top: 1px #EEE solid; + margin: 20px 0 0 0; - /* .req-save.css */ - .res-params { - display: -webkit-box; - line-height: 32px; - padding: 20px 0 0 0; - border-top: 1px #EEE solid; - margin: 20px 0 0 0; + ul { + -webkit-box-flex: 1; + margin: 0 0 0 24px; - ul { - -webkit-box-flex: 1; - margin: 0 0 0 24px; + li { + display: -webkit-box; + } - li { - display: -webkit-box; - } + .required { + margin: 0 10px 0 20px; + } - .required { - margin: 0 10px 0 20px; - } - - .title { - margin: 0 10px; - display: block; + .title { + margin: 0 10px; + display: block; + } } } } - + + /* Result.css */ .result { - display: -webkit-box; + display: inline-block; line-height: 32px; - padding: 20px 0 0 0; - border-top: 1px #EEE solid; - margin: 20px 0 0 0; + margin: 0 0 0 20px; + width: 500px; + float: left; textarea { width: 100%; diff --git a/client/containers/AddInterface/ReqHeader/ReqList.js b/client/containers/AddInterface/ReqHeader/ReqList.js index 085a4f7c..21db94e1 100644 --- a/client/containers/AddInterface/ReqHeader/ReqList.js +++ b/client/containers/AddInterface/ReqHeader/ReqList.js @@ -77,12 +77,13 @@ class ReqList extends Component { const propsValue = this.props.value const Option = Select.Option const value = propsValue.value - const name = propsValue.name || 'Accept' + const name = propsValue.name || '' return (
  • 头部标签 × -
  • + ) } } diff --git a/client/containers/AddInterface/ReqParams/ReqParams.js b/client/containers/AddInterface/ReqParams/ReqParams.js index f5e2b0b5..4cb85458 100644 --- a/client/containers/AddInterface/ReqParams/ReqParams.js +++ b/client/containers/AddInterface/ReqParams/ReqParams.js @@ -3,7 +3,9 @@ import PropTypes from 'prop-types' import { connect } from 'react-redux' import wangEditor from 'wangeditor' import { getReqParams } from '../../../actions/addInterface.js' + const editor = new wangEditor('#req-cover') + @connect( state => { return { @@ -34,20 +36,21 @@ class ReqParams extends Component { componentDidMount () { const reg = /(

    )|(<\/p>)| |(
    )|\s+/g + let json = '' editor.customConfig.menus = [] editor.customConfig.onchange = html => { - html = html.replace(reg, '') - this.props.getReqParams(html) + json = html.replace(reg, '') + this.props.getReqParams(json) } setTimeout(() => { this.initParams() - }, 200) + }, 500) editor.create() } render () { return ( -

    +
    请求参数 :
    diff --git a/client/containers/AddInterface/ResParams/ResParams.js b/client/containers/AddInterface/ResParams/ResParams.js index 32681c0d..bf69d583 100644 --- a/client/containers/AddInterface/ResParams/ResParams.js +++ b/client/containers/AddInterface/ResParams/ResParams.js @@ -2,6 +2,7 @@ import React, { Component } from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' import wangEditor from 'wangeditor' +import { Tabs } from 'antd' import { getResParams } from '../../../actions/addInterface.js' const editor = new wangEditor('#res-cover') @@ -38,7 +39,6 @@ class ResParams extends Component { const reg = /(

    )|(<\/p>)| |(
    )|\s+|

    |<\/div>/g editor.customConfig.menus = [] editor.customConfig.onchange = html => { - // html = html.match(/{.*}/g)[0] html = html.replace(reg, '') this.props.getResParams(html) } @@ -49,12 +49,14 @@ class ResParams extends Component { } render () { + const TabPane = Tabs.TabPane return ( -
    -
    - 返回参数 : -
    -
    +
    + + +
    +
    +
    ) } diff --git a/client/containers/AddInterface/Result/Result.js b/client/containers/AddInterface/Result/Result.js index 18133daa..ee2ad149 100644 --- a/client/containers/AddInterface/Result/Result.js +++ b/client/containers/AddInterface/Result/Result.js @@ -1,9 +1,8 @@ import React, { Component } from 'react' import { Tabs } from 'antd' -import Mock from 'mockjs' import { connect } from 'react-redux' import PropTypes from 'prop-types' -console.log('测试') + @connect( state => { return { @@ -17,7 +16,8 @@ class Result extends Component { static propTypes = { resParams: PropTypes.string, reqParams: PropTypes.string, - isSave: PropTypes.bool + isSave: PropTypes.bool, + mockJson: PropTypes.string } constructor(props) { @@ -25,21 +25,14 @@ class Result extends Component { } render () { - let TabPane = Tabs.TabPane - let resParams = '' - let json = '' - - if(this.props.resParams){ - resParams = JSON.parse(this.props.resParams) - json = JSON.stringify(Mock.mock(resParams), null, 2) - } - + const TabPane = Tabs.TabPane + const { mockJson } = this.props + console.log('mockJson', typeof mockJson, mockJson) return (
    - 返回示例 : -
    {json}
    +
    {mockJson}
    diff --git a/package.json b/package.json index afa7b43a..4eba0e06 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "core-decorators": "^0.17.0", "fast-sass-loader": "^1.2.5", "fs-extra": "^3.0.1", + "json2html": "0.0.8", "jsoneditor": "^5.9.3", "jsonwebtoken": "^7.4.1", "koa": "^2.0.0", From 2b8eb63fbfe0e9661f642018dd562e209cd0e6b7 Mon Sep 17 00:00:00 2001 From: qitmac000249 Date: Wed, 26 Jul 2017 13:07:12 +0800 Subject: [PATCH 4/7] =?UTF-8?q?fix:=20interface=20=E6=9C=80=E5=B0=8F?= =?UTF-8?q?=E9=AB=98=E5=BA=A6=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/containers/Interface/Interface.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/containers/Interface/Interface.scss b/client/containers/Interface/Interface.scss index 07489b8f..b60df331 100644 --- a/client/containers/Interface/Interface.scss +++ b/client/containers/Interface/Interface.scss @@ -33,7 +33,7 @@ .interface-table { -webkit-box-flex: 1; margin: 0 20px; - + min-height: 740px; .ant-table-wrapper table { font-size: .14rem; From be42920b366e3431186dd380fef155e85f77bc1c Mon Sep 17 00:00:00 2001 From: suxiaoxin Date: Wed, 26 Jul 2017 14:22:59 +0800 Subject: [PATCH 5/7] feat: params trim --- server/controllers/group.js | 12 ++- server/controllers/interface.js | 12 +++ server/controllers/project.js | 17 +++- server/controllers/user.js | 11 +++ server/utils/commons.js | 49 ++++++++-- server_dist/controllers/group.js | 62 ++++++++----- server_dist/controllers/interface.js | 90 ++++++++++-------- server_dist/controllers/project.js | 134 +++++++++++++++------------ server_dist/controllers/user.js | 77 ++++++++------- server_dist/utils/commons.js | 40 ++++++++ 10 files changed, 341 insertions(+), 163 deletions(-) diff --git a/server/controllers/group.js b/server/controllers/group.js index 62ee0e75..9dbb7db0 100644 --- a/server/controllers/group.js +++ b/server/controllers/group.js @@ -23,6 +23,10 @@ class groupController extends baseController{ */ async add(ctx) { let params = ctx.request.body; + params = yapi.commons.handleParams(params, { + group_name: 'string', + group_desc: 'string' + }) if(this.getRole() !== 'admin'){ return ctx.body = yapi.commons.resReturn(null,401,'没有权限'); } @@ -38,7 +42,7 @@ class groupController extends baseController{ let data = { group_name: params.group_name, group_desc: params.group_desc, - uid: '0', + uid: this.getUid(), add_time: yapi.commons.time(), up_time: yapi.commons.time() } @@ -124,6 +128,12 @@ class groupController extends baseController{ return ctx.body = yapi.commons.resReturn(null,401,'没有权限'); } try{ + + ctx.request.body = yapi.commons.handleParams(ctx.request.body, { + id: 'number', + group_name: 'string', + group_desc: 'string' + }) var groupInst = yapi.getInst(groupModel); let id = ctx.request.body.id; let data = {}; diff --git a/server/controllers/interface.js b/server/controllers/interface.js index d34666ac..67dfd945 100644 --- a/server/controllers/interface.js +++ b/server/controllers/interface.js @@ -37,6 +37,12 @@ class interfaceController extends baseController{ */ async add(ctx){ let params = ctx.request.body; + params = yapi.commons.handleParams(params, { + title: 'string', + path: 'string', + method: 'string', + desc: 'string' + }) params.method = params.method || 'GET'; params.method = params.method.toUpperCase() params.res_body_type = params.res_body_type ? params.res_body_type.toLowerCase() : 'json'; @@ -159,6 +165,12 @@ class interfaceController extends baseController{ async up(ctx){ let params = ctx.request.body; + params = yapi.commons.handleParams(params, { + title: 'string', + path: 'string', + method: 'string', + desc: 'string' + }) params.method = params.method || 'GET'; params.method = params.method.toUpperCase() let id = ctx.request.body.id; diff --git a/server/controllers/project.js b/server/controllers/project.js index 6e53388e..d641f3de 100644 --- a/server/controllers/project.js +++ b/server/controllers/project.js @@ -49,7 +49,14 @@ class projectController extends baseController { */ async add(ctx) { let params = ctx.request.body; - + params = yapi.commons.handleParams(params, { + name: 'string', + basepath: 'string', + prd_host: 'string', + protocol: 'string', + group_id: 'number', + desc: 'string' + }) if(!params.group_id){ return ctx.body = yapi.commons.resReturn(null, 400, '项目分组id不能为空'); } @@ -322,6 +329,14 @@ class projectController extends baseController { try{ let id = ctx.request.body.id; let params = ctx.request.body; + params = yapi.commons.handleParams(params, { + name: 'string', + basepath: 'string', + prd_host: 'string', + protocol: 'string', + group_id: 'number', + desc: 'string' + }) if(!id){ return ctx.body = yapi.commons.resReturn(null, 405, '项目id不能为空'); } diff --git a/server/controllers/user.js b/server/controllers/user.js index e38d642c..b4c790c9 100644 --- a/server/controllers/user.js +++ b/server/controllers/user.js @@ -241,6 +241,13 @@ class userController extends baseController { async reg(ctx) { //注册 var userInst = yapi.getInst(userModel); let params = ctx.request.body; //获取请求的参数,检查是否存在用户名和密码 + + params = yapi.commons.handleParams(params, { + username: 'string', + password: 'string', + email: 'string' + }) + if (!params.email) { return ctx.body = yapi.commons.resReturn(null, 400, '邮箱不能为空'); } @@ -395,6 +402,10 @@ class userController extends baseController { async update(ctx){ //更新用户信息 try{ let params = ctx.request.body; + params = yapi.commons.handleParams(params, { + username: 'string', + email: 'string' + }) if(this.getRole() !== 'admin' && params.uid != this.getUid()){ return ctx.body = yapi.commons.resReturn(null,401,'没有权限'); } diff --git a/server/utils/commons.js b/server/utils/commons.js index 1cd806ca..69840030 100644 --- a/server/utils/commons.js +++ b/server/utils/commons.js @@ -107,14 +107,14 @@ exports.sendMail = (options, cb) => { } } - try{ + try { yapi.mail.sendMail({ - from: yapi.WEBCONFIG.mail.auth.user, - to: options.to, - subject: 'yapi平台', - html: options.contents + from: yapi.WEBCONFIG.mail.auth.user, + to: options.to, + subject: 'yapi平台', + html: options.contents }, cb) - }catch(e){ + } catch (e) { console.error(e.message) } } @@ -150,4 +150,41 @@ exports.verifyPath = (path) => { } else { return false; } +} + +function trim(str) { + if (!str) return str; + str = str + ''; + return str.replace(/(^\s*)|(\s*$)/g, ""); +} + +function ltrim(str) { + if (!str) return str; + str = str + ''; + return str.replace(/(^\s*)/g, ""); +} + +function rtrim(str) { + if (!str) return str; + str = str + ''; + return str.replace(/(\s*$)/g, ""); +} + +exports.trim = trim; +exports.ltrim = ltrim; +exports.rtrim = rtrim; + +exports.handleParams = (params, keys) => { + if (!params || typeof params !== 'object' || !keys || typeof keys !== 'object') return false; + for (var key in keys) { + var filter = keys[key]; + if (params[key]) { + switch (filter) { + case 'string': params[key] = trim(params[key] + ''); break; + case 'number': params[key] = parseInt(params[key], 10); break; + default: params[key] = trim(params + ''); + } + } + } + return params; } \ No newline at end of file diff --git a/server_dist/controllers/group.js b/server_dist/controllers/group.js index 38498170..1b1f3e79 100644 --- a/server_dist/controllers/group.js +++ b/server_dist/controllers/group.js @@ -83,68 +83,73 @@ var groupController = function (_baseController) { case 0: params = ctx.request.body; + params = _yapi2.default.commons.handleParams(params, { + group_name: 'string', + group_desc: 'string' + }); + if (!(this.getRole() !== 'admin')) { - _context.next = 3; + _context.next = 4; break; } return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限')); - case 3: + case 4: if (params.group_name) { - _context.next = 5; + _context.next = 6; break; } return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组名不能为空')); - case 5: + case 6: groupInst = _yapi2.default.getInst(_group2.default); - _context.next = 8; + _context.next = 9; return groupInst.checkRepeat(params.group_name); - case 8: + case 9: checkRepeat = _context.sent; if (!(checkRepeat > 0)) { - _context.next = 11; + _context.next = 12; break; } return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '项目分组名已存在')); - case 11: + case 12: data = { group_name: params.group_name, group_desc: params.group_desc, - uid: '0', + uid: this.getUid(), add_time: _yapi2.default.commons.time(), up_time: _yapi2.default.commons.time() }; - _context.prev = 12; - _context.next = 15; + _context.prev = 13; + _context.next = 16; return groupInst.save(data); - case 15: + case 16: result = _context.sent; result = _yapi2.default.commons.fieldSelect(result, ['_id', 'group_name', 'group_desc', 'uid']); ctx.body = _yapi2.default.commons.resReturn(result); - _context.next = 23; + _context.next = 24; break; - case 20: - _context.prev = 20; - _context.t0 = _context['catch'](12); + case 21: + _context.prev = 21; + _context.t0 = _context['catch'](13); ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message); - case 23: + case 24: case 'end': return _context.stop(); } } - }, _callee, this, [[12, 20]]); + }, _callee, this, [[13, 21]]); })); function add(_x) { @@ -323,6 +328,13 @@ var groupController = function (_baseController) { case 2: _context4.prev = 2; + + + ctx.request.body = _yapi2.default.commons.handleParams(ctx.request.body, { + id: 'number', + group_name: 'string', + group_desc: 'string' + }); groupInst = _yapi2.default.getInst(_group2.default); id = ctx.request.body.id; data = {}; @@ -332,28 +344,28 @@ var groupController = function (_baseController) { if ((0, _keys2.default)(data).length === 0) { ctx.body = _yapi2.default.commons.resReturn(null, 404, '分组名和分组描述不能为空'); } - _context4.next = 11; + _context4.next = 12; return groupInst.up(id, data); - case 11: + case 12: result = _context4.sent; ctx.body = _yapi2.default.commons.resReturn(result); - _context4.next = 18; + _context4.next = 19; break; - case 15: - _context4.prev = 15; + case 16: + _context4.prev = 16; _context4.t0 = _context4['catch'](2); ctx.body = _yapi2.default.commons.resReturn(null, 402, e.message); - case 18: + case 19: case 'end': return _context4.stop(); } } - }, _callee4, this, [[2, 15]]); + }, _callee4, this, [[2, 16]]); })); function up(_x4) { diff --git a/server_dist/controllers/interface.js b/server_dist/controllers/interface.js index 5150b604..603da0d3 100644 --- a/server_dist/controllers/interface.js +++ b/server_dist/controllers/interface.js @@ -94,49 +94,55 @@ var interfaceController = function (_baseController) { case 0: params = ctx.request.body; + params = _yapi2.default.commons.handleParams(params, { + title: 'string', + path: 'string', + method: 'string', + desc: 'string' + }); params.method = params.method || 'GET'; params.method = params.method.toUpperCase(); params.res_body_type = params.res_body_type ? params.res_body_type.toLowerCase() : 'json'; if (params.project_id) { - _context.next = 6; + _context.next = 7; break; } return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目id不能为空')); - case 6: + case 7: if (params.path) { - _context.next = 8; + _context.next = 9; break; } return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口请求路径不能为空')); - case 8: + case 9: if (_yapi2.default.commons.verifyPath(params.path)) { - _context.next = 10; + _context.next = 11; break; } return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/')); - case 10: - _context.next = 12; + case 11: + _context.next = 13; return this.Model.checkRepeat(params.path, params.method); - case 12: + case 13: checkRepeat = _context.sent; if (!(checkRepeat > 0)) { - _context.next = 15; + _context.next = 16; break; } return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']')); - case 15: - _context.prev = 15; + case 16: + _context.prev = 16; data = { project_id: params.project_id, title: params.title, @@ -156,28 +162,28 @@ var interfaceController = function (_baseController) { if (params.req_params_form) data.req_params_form = params.req_params_form; if (params.req_params_other) data.req_params_other = params.req_params_other; - _context.next = 21; + _context.next = 22; return this.Model.save(data); - case 21: + case 22: result = _context.sent; ctx.body = _yapi2.default.commons.resReturn(result); - _context.next = 28; + _context.next = 29; break; - case 25: - _context.prev = 25; - _context.t0 = _context['catch'](15); + case 26: + _context.prev = 26; + _context.t0 = _context['catch'](16); ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message); - case 28: + case 29: case 'end': return _context.stop(); } } - }, _callee, this, [[15, 25]]); + }, _callee, this, [[16, 26]]); })); function add(_x) { @@ -349,51 +355,57 @@ var interfaceController = function (_baseController) { case 0: params = ctx.request.body; + params = _yapi2.default.commons.handleParams(params, { + title: 'string', + path: 'string', + method: 'string', + desc: 'string' + }); params.method = params.method || 'GET'; params.method = params.method.toUpperCase(); id = ctx.request.body.id; if (id) { - _context4.next = 6; + _context4.next = 7; break; } return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口id不能为空')); - case 6: - _context4.next = 8; + case 7: + _context4.next = 9; return this.Model.get(id); - case 8: + case 9: interfaceData = _context4.sent; if (!(params.path && !_yapi2.default.commons.verifyPath(params.path))) { - _context4.next = 11; + _context4.next = 12; break; } return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '接口path第一位必须是/,最后一位不能为/')); - case 11: + case 12: if (!(params.path && params.path !== interfaceData.path && params.method !== interfaceData.method)) { - _context4.next = 17; + _context4.next = 18; break; } - _context4.next = 14; + _context4.next = 15; return this.Model.checkRepeat(params.path, params.method); - case 14: + case 15: checkRepeat = _context4.sent; if (!(checkRepeat > 0)) { - _context4.next = 17; + _context4.next = 18; break; } return _context4.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的接口:' + params.path + '[' + params.method + ']')); - case 17: + case 18: data = { up_time: _yapi2.default.commons.time() }; @@ -412,29 +424,29 @@ var interfaceController = function (_baseController) { if (params.res_body_type) data.res_body_type = params.res_body_type; if (params.res_body) data.res_body = params.res_body; - _context4.prev = 27; - _context4.next = 30; + _context4.prev = 28; + _context4.next = 31; return this.Model.up(id, data); - case 30: + case 31: result = _context4.sent; ctx.body = _yapi2.default.commons.resReturn(result); - _context4.next = 37; + _context4.next = 38; break; - case 34: - _context4.prev = 34; - _context4.t0 = _context4['catch'](27); + case 35: + _context4.prev = 35; + _context4.t0 = _context4['catch'](28); ctx.body = _yapi2.default.commons.resReturn(null, 402, _context4.t0.message); - case 37: + case 38: case 'end': return _context4.stop(); } } - }, _callee4, this, [[27, 34]]); + }, _callee4, this, [[28, 35]]); })); function up(_x4) { diff --git a/server_dist/controllers/project.js b/server_dist/controllers/project.js index a93f4d3e..2f337485 100644 --- a/server_dist/controllers/project.js +++ b/server_dist/controllers/project.js @@ -119,82 +119,91 @@ var projectController = function (_baseController) { case 0: params = ctx.request.body; + params = _yapi2.default.commons.handleParams(params, { + name: 'string', + basepath: 'string', + prd_host: 'string', + protocol: 'string', + group_id: 'number', + desc: 'string' + }); + if (params.group_id) { - _context.next = 3; + _context.next = 4; break; } return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目分组id不能为空')); - case 3: + case 4: if (params.name) { - _context.next = 5; + _context.next = 6; break; } return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目名不能为空')); - case 5: - _context.next = 7; + case 6: + _context.next = 8; return this.Model.checkNameRepeat(params.name); - case 7: + case 8: checkRepeat = _context.sent; if (!(checkRepeat > 0)) { - _context.next = 10; + _context.next = 11; break; } return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名')); - case 10: + case 11: if (params.basepath) { - _context.next = 12; + _context.next = 13; break; } return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目basepath不能为空')); - case 12: + case 13: if (params.prd_host) { - _context.next = 14; + _context.next = 15; break; } return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '项目domain不能为空')); - case 14: + case 15: if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) { - _context.next = 16; + _context.next = 17; break; } return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误')); - case 16: + case 17: if (this.verifyDomain(params.prd_host)) { - _context.next = 18; + _context.next = 19; break; } return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '线上域名格式有误')); - case 18: - _context.next = 20; + case 19: + _context.next = 21; return this.Model.checkDomainRepeat(params.prd_host, params.basepath); - case 20: + case 21: checkRepeatDomain = _context.sent; if (!(checkRepeatDomain > 0)) { - _context.next = 23; + _context.next = 24; break; } return _context.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath')); - case 23: + case 24: data = { name: params.name, desc: params.desc, @@ -207,29 +216,29 @@ var projectController = function (_baseController) { add_time: _yapi2.default.commons.time(), up_time: _yapi2.default.commons.time() }; - _context.prev = 24; - _context.next = 27; + _context.prev = 25; + _context.next = 28; return this.Model.save(data); - case 27: + case 28: result = _context.sent; ctx.body = _yapi2.default.commons.resReturn(result); - _context.next = 34; + _context.next = 35; break; - case 31: - _context.prev = 31; - _context.t0 = _context['catch'](24); + case 32: + _context.prev = 32; + _context.t0 = _context['catch'](25); ctx.body = _yapi2.default.commons.resReturn(null, 402, _context.t0.message); - case 34: + case 35: case 'end': return _context.stop(); } } - }, _callee, this, [[24, 31]]); + }, _callee, this, [[25, 32]]); })); function add(_x) { @@ -750,50 +759,59 @@ var projectController = function (_baseController) { id = ctx.request.body.id; params = ctx.request.body; + params = _yapi2.default.commons.handleParams(params, { + name: 'string', + basepath: 'string', + prd_host: 'string', + protocol: 'string', + group_id: 'number', + desc: 'string' + }); + if (id) { - _context8.next = 5; + _context8.next = 6; break; } return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '项目id不能为空')); - case 5: - _context8.next = 7; + case 6: + _context8.next = 8; return this.jungeMemberAuth(id, this.getUid()); - case 7: + case 8: _context8.t0 = _context8.sent; if (!(_context8.t0 !== true)) { - _context8.next = 10; + _context8.next = 11; break; } return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 405, '没有权限')); - case 10: - _context8.next = 12; + case 11: + _context8.next = 13; return this.Model.get(id); - case 12: + case 13: projectData = _context8.sent; if (!((params.basepath = this.handleBasepath(params.basepath)) === false)) { - _context8.next = 15; + _context8.next = 16; break; } return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, 'basepath格式有误')); - case 15: + case 16: if (this.verifyDomain(params.prd_host)) { - _context8.next = 17; + _context8.next = 18; break; } return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '线上域名格式有误')); - case 17: + case 18: if (projectData.name === params.name) { delete params.name; @@ -804,43 +822,43 @@ var projectController = function (_baseController) { } if (!params.name) { - _context8.next = 25; + _context8.next = 26; break; } - _context8.next = 22; + _context8.next = 23; return this.Model.checkNameRepeat(params.name); - case 22: + case 23: checkRepeat = _context8.sent; if (!(checkRepeat > 0)) { - _context8.next = 25; + _context8.next = 26; break; } return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在的项目名')); - case 25: + case 26: if (!(params.basepath && params.prd_host)) { - _context8.next = 31; + _context8.next = 32; break; } - _context8.next = 28; + _context8.next = 29; return this.Model.checkDomainRepeat(params.prd_host, params.basepath); - case 28: + case 29: checkRepeatDomain = _context8.sent; if (!(checkRepeatDomain > 0)) { - _context8.next = 31; + _context8.next = 32; break; } return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '已存在domain和basepath')); - case 31: + case 32: data = { uid: this.getUid(), up_time: _yapi2.default.commons.time() @@ -856,28 +874,28 @@ var projectController = function (_baseController) { if (params.protocol) data.protocol = params.protocol; if (params.env) data.env = params.env; - _context8.next = 39; + _context8.next = 40; return this.Model.up(id, data); - case 39: + case 40: result = _context8.sent; ctx.body = _yapi2.default.commons.resReturn(result); - _context8.next = 46; + _context8.next = 47; break; - case 43: - _context8.prev = 43; + case 44: + _context8.prev = 44; _context8.t1 = _context8['catch'](0); ctx.body = _yapi2.default.commons.resReturn(null, 402, _context8.t1.message); - case 46: + case 47: case 'end': return _context8.stop(); } } - }, _callee8, this, [[0, 43]]); + }, _callee8, this, [[0, 44]]); })); function up(_x8) { diff --git a/server_dist/controllers/user.js b/server_dist/controllers/user.js index 4a765424..bb5627a6 100644 --- a/server_dist/controllers/user.js +++ b/server_dist/controllers/user.js @@ -547,36 +547,42 @@ var userController = function (_baseController) { userInst = _yapi2.default.getInst(_user2.default); params = ctx.request.body; //获取请求的参数,检查是否存在用户名和密码 + params = _yapi2.default.commons.handleParams(params, { + username: 'string', + password: 'string', + email: 'string' + }); + if (params.email) { - _context8.next = 4; + _context8.next = 5; break; } return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '邮箱不能为空')); - case 4: + case 5: if (params.password) { - _context8.next = 6; + _context8.next = 7; break; } return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, '密码不能为空')); - case 6: - _context8.next = 8; + case 7: + _context8.next = 9; return userInst.checkRepeat(params.email); - case 8: + case 9: checkRepeat = _context8.sent; if (!(checkRepeat > 0)) { - _context8.next = 11; + _context8.next = 12; break; } return _context8.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '该email已经注册')); - case 11: + case 12: passsalt = _yapi2.default.commons.randStr(); data = { username: params.username, @@ -591,11 +597,11 @@ var userController = function (_baseController) { if (!data.username) { data.username = data.email.substr(0, data.email.indexOf('@')); } - _context8.prev = 14; - _context8.next = 17; + _context8.prev = 15; + _context8.next = 18; return userInst.save(data); - case 17: + case 18: user = _context8.sent; this.setLoginCookie(user._id, user.passsalt); @@ -612,21 +618,21 @@ var userController = function (_baseController) { to: user.email, contents: '

    \u4EB2\u7231\u7684\u7528\u6237\uFF1A

    \u60A8\u597D\uFF0C\u611F\u8C22\u4F7F\u7528YApi,\u60A8\u7684\u8D26\u53F7 ' + params.email + ' \u5DF2\u7ECF\u6CE8\u518C\u6210\u529F

    ' }); - _context8.next = 26; + _context8.next = 27; break; - case 23: - _context8.prev = 23; - _context8.t0 = _context8['catch'](14); + case 24: + _context8.prev = 24; + _context8.t0 = _context8['catch'](15); ctx.body = _yapi2.default.commons.resReturn(null, 401, _context8.t0.message); - case 26: + case 27: case 'end': return _context8.stop(); } } - }, _callee8, this, [[14, 23]]); + }, _callee8, this, [[15, 24]]); })); function reg(_x9) { @@ -868,25 +874,30 @@ var userController = function (_baseController) { _context12.prev = 0; params = ctx.request.body; + params = _yapi2.default.commons.handleParams(params, { + username: 'string', + email: 'string' + }); + if (!(this.getRole() !== 'admin' && params.uid != this.getUid())) { - _context12.next = 4; + _context12.next = 5; break; } return _context12.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '没有权限')); - case 4: + case 5: userInst = _yapi2.default.getInst(_user2.default); id = params.uid; if (id) { - _context12.next = 8; + _context12.next = 9; break; } return _context12.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 400, 'uid不能为空')); - case 8: + case 9: data = { up_time: _yapi2.default.commons.time() @@ -899,46 +910,46 @@ var userController = function (_baseController) { params.email && (data.email = params.email); if (!data.email) { - _context12.next = 18; + _context12.next = 19; break; } - _context12.next = 15; + _context12.next = 16; return userInst.checkRepeat(data.email); - case 15: + case 16: checkRepeat = _context12.sent; if (!(checkRepeat > 0)) { - _context12.next = 18; + _context12.next = 19; break; } return _context12.abrupt('return', ctx.body = _yapi2.default.commons.resReturn(null, 401, '该email已经注册')); - case 18: - _context12.next = 20; + case 19: + _context12.next = 21; return userInst.update(id, data); - case 20: + case 21: result = _context12.sent; ctx.body = _yapi2.default.commons.resReturn(result); - _context12.next = 27; + _context12.next = 28; break; - case 24: - _context12.prev = 24; + case 25: + _context12.prev = 25; _context12.t0 = _context12['catch'](0); ctx.body = _yapi2.default.commons.resReturn(null, 402, _context12.t0.message); - case 27: + case 28: case 'end': return _context12.stop(); } } - }, _callee12, this, [[0, 24]]); + }, _callee12, this, [[0, 25]]); })); function update(_x13) { diff --git a/server_dist/utils/commons.js b/server_dist/utils/commons.js index 27bf7ff6..fa9147d3 100644 --- a/server_dist/utils/commons.js +++ b/server_dist/utils/commons.js @@ -171,4 +171,44 @@ exports.verifyPath = function (path) { } else { return false; } +}; + +function trim(str) { + if (!str) return str; + str = str + ''; + return str.replace(/(^\s*)|(\s*$)/g, ""); +} + +function ltrim(str) { + if (!str) return str; + str = str + ''; + return str.replace(/(^\s*)/g, ""); +} + +function rtrim(str) { + if (!str) return str; + str = str + ''; + return str.replace(/(\s*$)/g, ""); +} + +exports.trim = trim; +exports.ltrim = ltrim; +exports.rtrim = rtrim; + +exports.handleParams = function (params, keys) { + if (!params || (typeof params === 'undefined' ? 'undefined' : (0, _typeof3.default)(params)) !== 'object' || !keys || (typeof keys === 'undefined' ? 'undefined' : (0, _typeof3.default)(keys)) !== 'object') return false; + for (var key in keys) { + var filter = keys[key]; + if (params[key]) { + switch (filter) { + case 'string': + params[key] = trim(params[key] + '');break; + case 'number': + params[key] = parseInt(params[key], 10);break; + default: + params[key] = trim(params + ''); + } + } + } + return params; }; \ No newline at end of file From 0c7ee1c03bb8c54884d03bc8fd932069411e2668 Mon Sep 17 00:00:00 2001 From: zwjamnsss Date: Wed, 26 Jul 2017 14:54:14 +0800 Subject: [PATCH 6/7] =?UTF-8?q?opti:=20group=20=E6=8E=A5=E5=8F=A3=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=20=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../containers/AddInterface/AddInterface.js | 12 +-- .../containers/AddInterface/AddInterface.scss | 25 +++--- .../InterfaceTest/InterfaceTest.js | 81 ++++++++++++++----- .../InterfaceTest/InterfaceTest.scss | 9 +++ client/containers/Interface/Interface.scss | 10 +-- .../ProjectGroups/GroupList/GroupList.scss | 7 +- 6 files changed, 100 insertions(+), 44 deletions(-) diff --git a/client/containers/AddInterface/AddInterface.js b/client/containers/AddInterface/AddInterface.js index e19eef63..8697a273 100644 --- a/client/containers/AddInterface/AddInterface.js +++ b/client/containers/AddInterface/AddInterface.js @@ -81,7 +81,7 @@ class AddInterface extends Component { id: 0, name: '', value: '' - }] + }] let interfaceId = undefined if (ifTrue) { interfaceId = this.getInterfaceId() @@ -106,7 +106,7 @@ class AddInterface extends Component { url.match(regTwo) return RegExp.$1 } - + } verificationURL () { @@ -170,7 +170,7 @@ class AddInterface extends Component { mockData () { // mock 数据 let resParams = '' let json = '' - + if(this.props.resParams){ resParams = JSON.parse(this.props.resParams) json = JSON.stringify(Mock.mock(resParams), null, 2) @@ -236,8 +236,10 @@ class AddInterface extends Component { - mock - + { + // mock + } + diff --git a/client/containers/AddInterface/AddInterface.scss b/client/containers/AddInterface/AddInterface.scss index 5c4ecc9c..6115b7db 100644 --- a/client/containers/AddInterface/AddInterface.scss +++ b/client/containers/AddInterface/AddInterface.scss @@ -6,10 +6,11 @@ .content { max-width: 11rem; - margin: 0 auto; + margin: 24px auto; + border-radius: 4px; background: #FFF; padding: 10px 20px 50px 20px; - + .save { float: right; margin: 0 0 10px 0; @@ -19,7 +20,7 @@ float: right; margin: 0 15px 0 0; } - + table { width: 100%; border-top: 1px #EEE solid; @@ -27,7 +28,7 @@ th { padding:0 10px; } - + td { padding: 10px 0; } @@ -54,7 +55,7 @@ margin: 0 0 0 10px; cursor: pointer; } - + /* .req-header.css */ .req-header { display: -webkit-box; @@ -90,7 +91,7 @@ .req-save, .res-save { margin: 5px 0 0 107px; } - + /* .req-params.css */ .req-params { display: -webkit-box; @@ -98,12 +99,12 @@ margin: 20px 0 0 0; border-top: 1px #EEE solid; } - + .res-params-box { display: inline-block; width: 530px; float: left; - + /* .req-save.css */ .res-params { display: -webkit-box; @@ -131,7 +132,7 @@ } } } - + /* Result.css */ .result { display: inline-block; @@ -153,10 +154,10 @@ border: 1px #CCC solid; height: 300px; overflow-x: hidden; - overflow-y: auto; + overflow-y: auto; line-height: 1.2; } - + .ant-tabs { -webkit-box-flex: 1; } @@ -243,4 +244,4 @@ body { padding: 0 20px; background-color: #FFF; -webkit-box-flex: 1; -} \ No newline at end of file +} diff --git a/client/containers/AddInterface/InterfaceTest/InterfaceTest.js b/client/containers/AddInterface/InterfaceTest/InterfaceTest.js index 728d6279..51f2f830 100644 --- a/client/containers/AddInterface/InterfaceTest/InterfaceTest.js +++ b/client/containers/AddInterface/InterfaceTest/InterfaceTest.js @@ -12,6 +12,8 @@ import { import './InterfaceTest.scss' +const { TextArea } = Input; + @connect( state => ({ reqParams: state.addInterface.reqParams, @@ -52,9 +54,34 @@ export default class InterfaceTest extends Component { @autobind testInterface() { + const { method, url, seqGroup, interfaceProject } = this.props; + const { prd_host, basepath, protocol } = interfaceProject; + const reqParams = JSON.parse(this.props.reqParams); + const headers = {} + let query = {}; + + if (method === 'GET') { + Object.keys(reqParams).forEach(key => { + const value = typeof reqParams[key] === 'object' ? JSON.stringify(reqParams) : reqParams.toString(); + query[key] = value; + }) + } + + seqGroup.forEach((headerItem) => { + headers[headerItem.name] = headerItem.value; + }) + + const href = URL.format({ + protocol: protocol || 'http', + host: prd_host, + pathname: (basepath + url).replace(/\/+/g, '/'), + query + }); + crossRequest({ - url: 'http://petstore.swagger.io/v2/swagger.json', - method: 'GET', + url: href, + method, + headers, data: { a:1 }, @@ -74,7 +101,7 @@ export default class InterfaceTest extends Component { if (method === 'GET') { Object.keys(reqParams).forEach(key => { - const value = typeof reqParams[key] === 'object' ? JSON.stringify(reqParams) : reqParams.toString(); + const value = typeof reqParams[key] === 'object' ? JSON.stringify(reqParams[key]) : reqParams[key].toString(); query[key] = value; }) } @@ -82,37 +109,53 @@ export default class InterfaceTest extends Component { const href = URL.format({ protocol: protocol || 'http', host: prd_host, - pathname: URL.resolve(basepath, url), + pathname: (basepath + url).replace(/\/+/g, '/'), query }); return ( -
    -
    接口名:{interfaceName}
    -
    - METHOD: - URL: - HEADERS: - 请求参数: -
    +
    +
    {interfaceName}
    +
    +
    + METHOD: +
    +
    + URL: + +
    +
    + HEADERS: { - Object.keys(reqParams).map((key, index) => { - const value = typeof reqParams[key] === 'object' ? JSON.stringify(reqParams) : reqParams.toString(); + seqGroup.map((headerItem, index) => { return (
    - {' = '} - + {' = '} + +
    + ) + }) + } +
    +
    + 请求参数: + { + Object.keys(reqParams).map((key, index) => { + const value = typeof reqParams[key] === 'object' ? JSON.stringify(reqParams[key]) : reqParams[key].toString(); + return ( +
    + {' = '} +
    ) }) }
    - -
    +
    返回结果: - {JSON.stringify(this.state.res, 2)} +
    ) diff --git a/client/containers/AddInterface/InterfaceTest/InterfaceTest.scss b/client/containers/AddInterface/InterfaceTest/InterfaceTest.scss index e69de29b..14350c6c 100644 --- a/client/containers/AddInterface/InterfaceTest/InterfaceTest.scss +++ b/client/containers/AddInterface/InterfaceTest/InterfaceTest.scss @@ -0,0 +1,9 @@ +.interface-test { + .interface-name { + font-size: 24px; + margin-bottom: 24px; + } + .req-row { + margin-bottom: 24px; + } +} diff --git a/client/containers/Interface/Interface.scss b/client/containers/Interface/Interface.scss index b60df331..7e66ca20 100644 --- a/client/containers/Interface/Interface.scss +++ b/client/containers/Interface/Interface.scss @@ -3,7 +3,8 @@ max-width: 11rem; display: -webkit-box; -webkit-box-flex: 1; - margin: 15px auto 0 auto; + margin: 24px auto; + border-radius: 4px; font-size: 0.14rem; background: #FFF; @@ -11,16 +12,16 @@ width: 216px; line-height: 45px; background: #f9fafe; - + li { padding: 0 0 0 30px; color: #344562; cursor: pointer; - + &:hover { color: #29f; } - + a { color: #344562; &:hover { @@ -69,4 +70,3 @@ } } } - diff --git a/client/containers/ProjectGroups/GroupList/GroupList.scss b/client/containers/ProjectGroups/GroupList/GroupList.scss index 47ab3822..68902b46 100644 --- a/client/containers/ProjectGroups/GroupList/GroupList.scss +++ b/client/containers/ProjectGroups/GroupList/GroupList.scss @@ -1,7 +1,8 @@ .group-bar { + box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20); + border-radius: 4px; .curr-group { background: #34495E; - box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20); border-radius: 4px 4px 0 0; padding: 32px 24px; .curr-group-name { @@ -38,7 +39,7 @@ height: 48px; min-width: 263px; padding: 10px 6px; - background: #fff; + background: #eee; .search { display: inline-block; margin-right: 6px; @@ -51,7 +52,7 @@ overflow-x: hidden; border-bottom: 1px solid #e9e9e9; padding-bottom: 24px; - border-radius: 0 0 6px 6px; + border-radius: 0 0 4px 4px; .group-item { // height: 48px; // line-height: 48px; From b5718ea7427a265002b7cd1c1395040aadf3fad2 Mon Sep 17 00:00:00 2001 From: zwjamnsss Date: Wed, 26 Jul 2017 14:56:13 +0800 Subject: [PATCH 7/7] =?UTF-8?q?opti:=20=E6=8E=A5=E5=8F=A3=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/containers/AddInterface/AddInterface.scss | 1 + client/containers/Interface/Interface.scss | 1 + 2 files changed, 2 insertions(+) diff --git a/client/containers/AddInterface/AddInterface.scss b/client/containers/AddInterface/AddInterface.scss index 6115b7db..f2c24971 100644 --- a/client/containers/AddInterface/AddInterface.scss +++ b/client/containers/AddInterface/AddInterface.scss @@ -8,6 +8,7 @@ max-width: 11rem; margin: 24px auto; border-radius: 4px; + box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20); background: #FFF; padding: 10px 20px 50px 20px; diff --git a/client/containers/Interface/Interface.scss b/client/containers/Interface/Interface.scss index 7e66ca20..7e451f49 100644 --- a/client/containers/Interface/Interface.scss +++ b/client/containers/Interface/Interface.scss @@ -5,6 +5,7 @@ -webkit-box-flex: 1; margin: 24px auto; border-radius: 4px; + box-shadow: 0 2px 4px 0 rgba(0,0,0,0.20); font-size: 0.14rem; background: #FFF;