From ac7f1f09f56e58610853a1d4df1ded174ff27f66 Mon Sep 17 00:00:00 2001 From: suxiaoxin Date: Mon, 14 Aug 2017 21:43:06 +0800 Subject: [PATCH] feat: edit interface ci --- .../Project/Interface/InterfaceList/Edit.js | 12 +- .../Project/Interface/InterfaceList/Edit.scss | 6 + .../InterfaceList/InterfaceEditForm.js | 122 ++++++++++++------ .../Interface/InterfaceList/mockEditor.js | 5 +- 4 files changed, 95 insertions(+), 50 deletions(-) create mode 100644 client/containers/Project/Interface/InterfaceList/Edit.scss diff --git a/client/containers/Project/Interface/InterfaceList/Edit.js b/client/containers/Project/Interface/InterfaceList/Edit.js index c677b8bf..dec8220d 100644 --- a/client/containers/Project/Interface/InterfaceList/Edit.js +++ b/client/containers/Project/Interface/InterfaceList/Edit.js @@ -2,7 +2,7 @@ import React,{Component} from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux'; import InterfaceEditForm from './InterfaceEditForm.js' - +import './Edit.scss' @connect( state => { @@ -17,11 +17,13 @@ class InterfaceEdit extends Component{ curdata: PropTypes.object } + onSubmit = (params)=>{ + console.log('edit', params) + } + render(){ - - return
-

Edit

- + return
+
} } diff --git a/client/containers/Project/Interface/InterfaceList/Edit.scss b/client/containers/Project/Interface/InterfaceList/Edit.scss new file mode 100644 index 00000000..ddb4a96f --- /dev/null +++ b/client/containers/Project/Interface/InterfaceList/Edit.scss @@ -0,0 +1,6 @@ +.interface-edit{ + padding:10px; + .interface-edit-item{ + margin-bottom: 10px; + } +} \ No newline at end of file diff --git a/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js b/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js index 2219bddf..f7c875d3 100644 --- a/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js +++ b/client/containers/Project/Interface/InterfaceList/InterfaceEditForm.js @@ -18,40 +18,52 @@ const mockEditor = require('./mockEditor.js'); class InterfaceEditForm extends Component { static propTypes = { - form: PropTypes.object + form: PropTypes.object, + curdata: PropTypes.object, + onSubmit: PropTypes.func } constructor(props) { super(props) - this.state = { - title: 'title', - path: 'path', + const { curdata } = this.props; + if (curdata.query && curdata.query.length === 0) delete curdata.query; + if (curdata.req_headers && curdata.req_headers.length === 0) delete curdata.req_headers; + if (curdata.req_body_form && curdata.req_body_form.length === 0) delete curdata.req_body_form; + + this.state = Object.assign({ + title: '', + path: '', + status: 'undone', method: 'get', query: [{ - name: 'name', - desc: 'desc', + name: '', + desc: '', required: "1" }], req_body_type: 'form', req_headers: [{ - name: 'Content-Type', - value: 'application/x-www-form-urlencoded', required: "1" + name: '', + value: '', required: "1" }], req_body_form: [{ - name: 'id', - type: 'text', - required: '1' + name: '', + type: '', + required: '' }], res_body_type: 'json', - res_body: '' - } + res_body: '', + desc: '', + res_body_mock: '' + }, curdata) } handleSubmit = (e) => { e.preventDefault(); this.props.form.validateFields((err, values) => { if (!err) { - console.log('Received values of form: ', values); + if (values.res_body_type === 'json') values.res_body = this.state.res_body; + values.req_body_json = this.state.res_body; + this.props.onSubmit(values) } }); } @@ -72,8 +84,10 @@ class InterfaceEditForm extends Component { container: 'res_body_json', data: that.state.res_body, onChange: function (d) { + that.setState({ - res_body: d.text + res_body: d.text, + res_body_mock: d.mockText }) } }) @@ -99,8 +113,8 @@ class InterfaceEditForm extends Component { render() { const { getFieldDecorator } = this.props.form; const formItemLayout = { - labelCol: { span: 6 }, - wrapperCol: { span: 14 } + labelCol: { span: 4 }, + wrapperCol: { span: 18 } }; const prefixSelector = getFieldDecorator('method', { initialValue: 'GET' @@ -219,10 +233,12 @@ class InterfaceEditForm extends Component { return (
{getFieldDecorator('title', { + initialValue: this.state.title, rules: [{ required: true, message: '清输入接口名称!' }] @@ -232,10 +248,12 @@ class InterfaceEditForm extends Component { {getFieldDecorator('path', { + initialValue: this.state.path, rules: [{ required: true, message: '清输入接口路径!' }] @@ -245,10 +263,11 @@ class InterfaceEditForm extends Component { - {getFieldDecorator('status', { initialValue: 'undone' })( + {getFieldDecorator('status', { initialValue: this.state.status })(