From 49c9178ea20827196d92f04a810ef0ea2d0cd8eb Mon Sep 17 00:00:00 2001 From: suxiaoxin Date: Thu, 21 Sep 2017 20:47:08 +0800 Subject: [PATCH] opti: interface Edit style --- .../Project/Interface/InterfaceList/Edit.scss | 3 + .../InterfaceList/InterfaceEditForm.js | 124 +++++++++++++----- .../Project/Interface/interface.scss | 2 +- .../Setting/ProjectData/ProjectData.js | 6 +- exts/yapi-plugin-advanced-mock/AdvMock.js | 4 +- server/models/interface.js | 9 +- 6 files changed, 105 insertions(+), 43 deletions(-) diff --git a/client/containers/Project/Interface/InterfaceList/Edit.scss b/client/containers/Project/Interface/InterfaceList/Edit.scss index 31eee1b5..0a6a50bf 100755 --- a/client/containers/Project/Interface/InterfaceList/Edit.scss +++ b/client/containers/Project/Interface/InterfaceList/Edit.scss @@ -8,6 +8,9 @@ } .interface-edit-item-content{ margin-bottom: 16px; + .interface-edit-item-content-col{ + padding:0 1px; + } } .interface-edit-del-icon{ margin-top: 10px; diff --git a/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js b/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js index 24cea49a..dab1c485 100755 --- a/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js +++ b/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js @@ -28,10 +28,10 @@ const InputGroup = Input.Group; const RadioButton = Radio.Button; const RadioGroup = Radio.Group; const dataTpl = { - req_query: { name: "", required: "1", desc: "" }, - req_headers: { name: "", required: "1", desc: "" }, - req_params: { name: "", desc: "" }, - req_body_form: { name: "", type: "text", required: "1", desc: "" } + req_query: { name: "", required: "1", desc: "", example: "" }, + req_headers: { name: "", required: "1", desc: "", example: "" }, + req_params: { name: "", desc: "", example: "" }, + req_body_form: { name: "", type: "text", required: "1", desc: "", example: "" } } const mockEditor = require('./mockEditor.js'); @@ -107,8 +107,8 @@ class InterfaceEditForm extends Component { desc: '', res_body_mock: '', jsonType: 'tpl', - mockUrl: this.props.mockUrl - + mockUrl: this.props.mockUrl, + req_radio_type: 'req-query' }, curdata) } @@ -180,7 +180,26 @@ class InterfaceEditForm extends Component { }); } + onChangeMethod = (val) => { + let radio = []; + if(HTTP_METHOD[val].request_body){ + radio = ['req', 'body']; + }else{ + radio = ['req', 'query']; + } + this.setState({ + req_radio_type: radio.join("-") + }) + + this.setState({ method: val }, ()=>{ + this._changeRadioGroup(radio[0] , radio[1]) + }) + } + componentDidMount() { + this.setState({ + req_radio_type: HTTP_METHOD[this.state.method].request_body ? 'req-body' : 'req-query' + }) let that = this, mockPreview, resBodyEditor; mockEditor({ container: 'req_body_json', @@ -269,19 +288,28 @@ class InterfaceEditForm extends Component { } // 点击切换radio - changeRadioGroup = (e) => { + changeRadioGroup = (e) => { const res = e.target.value.split('-'); + if(res[0] === 'req'){ + this.setState({ + req_radio_type: e.target.value + }) + } + this._changeRadioGroup(res[0], res[1]); + } + + _changeRadioGroup = (group, item) => { const obj = {} // 先全部隐藏 - for (let key in this.state.hideTabs[res[0]]) { + for (let key in this.state.hideTabs[group]) { obj[key] = 'hide'; } // 再取消选中项目的隐藏 - obj[res[1]] = ''; + obj[item] = ''; this.setState({ hideTabs: { ...this.state.hideTabs, - [res[0]]: obj + [group]: obj } }) } @@ -295,14 +323,14 @@ class InterfaceEditForm extends Component { const queryTpl = (data, index) => { return - + {getFieldDecorator('req_query[' + index + '].name', { initialValue: data.name })( )} - + {getFieldDecorator('req_query[' + index + '].required', { initialValue: data.required })( @@ -312,14 +340,21 @@ class InterfaceEditForm extends Component { )} - + + {getFieldDecorator('req_query[' + index + '].example', { + initialValue: data.example + })( + + )} + + {getFieldDecorator('req_query[' + index + '].desc', { initialValue: data.desc })( )} - + this.delParams(index, 'req_query')} /> @@ -328,7 +363,7 @@ class InterfaceEditForm extends Component { const headerTpl = (data, index) => { return - + {getFieldDecorator('req_headers[' + index + '].name', { initialValue: data.name })( @@ -339,21 +374,28 @@ class InterfaceEditForm extends Component { /> )} - + {getFieldDecorator('req_headers[' + index + '].value', { initialValue: data.value })( - + )} - + + {getFieldDecorator('req_headers[' + index + '].example', { + initialValue: data.example + })( + + )} + + {getFieldDecorator('req_headers[' + index + '].desc', { initialValue: data.desc })( )} - + this.delParams(index, 'req_headers')} /> @@ -362,14 +404,14 @@ class InterfaceEditForm extends Component { const requestBodyTpl = (data, index) => { return - + {getFieldDecorator('req_body_form[' + index + '].name', { initialValue: data.name })( )} - + {getFieldDecorator('req_body_form[' + index + '].type', { initialValue: data.type })( @@ -379,7 +421,7 @@ class InterfaceEditForm extends Component { )} - + {getFieldDecorator('req_body_form[' + index + '].required', { initialValue: data.required })( @@ -389,14 +431,21 @@ class InterfaceEditForm extends Component { )} - + + {getFieldDecorator('req_body_form[' + index + '].example', { + initialValue: data.example + })( + + )} + + {getFieldDecorator('req_body_form[' + index + '].desc', { initialValue: data.desc })( )} - + this.delParams(index, 'req_body_form')} /> @@ -404,14 +453,21 @@ class InterfaceEditForm extends Component { const paramsTpl = (data, index) => { return - + {getFieldDecorator('req_params[' + index + '].name', { initialValue: data.name })( )} - + + {getFieldDecorator('req_params[' + index + '].example', { + initialValue: data.desc + })( + + )} + + {getFieldDecorator('req_params[' + index + '].desc', { initialValue: data.desc })( @@ -441,7 +497,7 @@ class InterfaceEditForm extends Component { return (
-

基本设置

+

基本设置

- {HTTP_METHOD_KEYS.map(item => { return })} @@ -508,7 +564,7 @@ class InterfaceEditForm extends Component { )} - + {paramsList} @@ -535,7 +591,7 @@ class InterfaceEditForm extends Component {

Request 设置

- + {HTTP_METHOD[this.state.method].request_body ? Body : null} Query Headers @@ -570,7 +626,7 @@ class InterfaceEditForm extends Component { {HTTP_METHOD[this.state.method].request_body ?
{getFieldDecorator('req_body_type', { initialValue: this.state.req_body_type @@ -585,7 +641,7 @@ class InterfaceEditForm extends Component { - + @@ -604,7 +660,7 @@ class InterfaceEditForm extends Component { : null} - + @@ -717,7 +773,7 @@ class InterfaceEditForm extends Component { diff --git a/client/containers/Project/Interface/interface.scss b/client/containers/Project/Interface/interface.scss index 59a9c28c..6f17039c 100755 --- a/client/containers/Project/Interface/interface.scss +++ b/client/containers/Project/Interface/interface.scss @@ -177,7 +177,7 @@ margin-bottom: .16rem; } .panel-sub { - background: #eceef1; + background: rgba(236, 238, 241, 0.67); padding: .16rem; } .ant-radio-button-wrapper-checked { diff --git a/client/containers/Project/Setting/ProjectData/ProjectData.js b/client/containers/Project/Setting/ProjectData/ProjectData.js index 98506fcd..444a45ac 100755 --- a/client/containers/Project/Setting/ProjectData/ProjectData.js +++ b/client/containers/Project/Setting/ProjectData/ProjectData.js @@ -1,5 +1,5 @@ import React, { Component } from 'react' -import { Upload, Icon, message, Select } from 'antd'; +import { Upload, Icon, message, Select, Tooltip } from 'antd'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import './ProjectData.scss'; @@ -136,7 +136,9 @@ class ProjectData extends Component {
-

数据导入 

+

数据导入  + +