From 3cc5daac9bf4a5ad5887d7a0405b76d2b5ca6b27 Mon Sep 17 00:00:00 2001 From: zwjamnsss Date: Tue, 19 Sep 2017 15:24:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../InterfaceCol/InterfaceCaseContent.js | 73 +++++++++++++++---- .../InterfaceCol/InterfaceCaseContent.scss | 33 +++++++++ 2 files changed, 93 insertions(+), 13 deletions(-) create mode 100644 client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.scss diff --git a/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js b/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js index cda5c26c..0d5a84a4 100755 --- a/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js +++ b/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.js @@ -4,10 +4,12 @@ import PropTypes from 'prop-types' import { withRouter } from 'react-router' import { Link } from 'react-router-dom' import axios from 'axios' -import { message } from 'antd' -import { fetchInterfaceColList, setColData, fetchCaseData } from '../../../../reducer/modules/interfaceCol' +import { message, Tooltip, Input } from 'antd' +import { fetchInterfaceColList, setColData, fetchCaseData, fetchCaseList } from '../../../../reducer/modules/interfaceCol' import { Postman } from '../../../../components' +import './InterfaceCaseContent.scss' + @connect( state => { return { @@ -22,7 +24,8 @@ import { Postman } from '../../../../components' { fetchInterfaceColList, fetchCaseData, - setColData + setColData, + fetchCaseList } ) @withRouter @@ -34,6 +37,7 @@ export default class InterfaceCaseContent extends Component { fetchInterfaceColList: PropTypes.func, fetchCaseData: PropTypes.func, setColData: PropTypes.func, + fetchCaseList: PropTypes.func, history: PropTypes.object, currColId: PropTypes.number, currCaseId: PropTypes.number, @@ -42,6 +46,11 @@ export default class InterfaceCaseContent extends Component { currProject: PropTypes.object } + state = { + isEditingCasename: true, + editCasename: '' + } + constructor(props) { super(props) } @@ -66,17 +75,19 @@ export default class InterfaceCaseContent extends Component { currCaseId = +actionId || +currCaseId || result.payload.data.data[0].caseList[0]._id; let currColId = this.getColId(result.payload.data.data, currCaseId); this.props.history.push('/project/' + params.id + '/interface/case/' + currCaseId) - this.props.fetchCaseData(currCaseId) + await this.props.fetchCaseData(currCaseId) this.props.setColData({currCaseId: +currCaseId, currColId, isShowCol: false}) + this.setState({editCasename: this.props.currCase.casename}) } - componentWillReceiveProps(nextProps) { + async componentWillReceiveProps(nextProps) { const oldCaseId = this.props.match.params.actionId const newCaseId = nextProps.match.params.actionId if (oldCaseId !== newCaseId) { let currColId = this.getColId(this.props.interfaceColList, newCaseId); - this.props.fetchCaseData(newCaseId); + await this.props.fetchCaseData(newCaseId); this.props.setColData({currCaseId: +newCaseId, currColId, isShowCol: false}) + this.setState({editCasename: this.props.currCase.casename}) } } @@ -96,7 +107,8 @@ export default class InterfaceCaseContent extends Component { bodyForm: req_body_form, bodyOther: req_body_other } = this.postman.state; - const {_id: id, casename} = this.props.currCase; + const {editCasename: casename} = this.state; + const {_id: id} = this.props.currCase; const res = await axios.post('/api/col/up_case', { id, casename, @@ -110,6 +122,9 @@ export default class InterfaceCaseContent extends Component { req_body_form, req_body_other }); + if (this.props.currCase.casename !== casename) { + this.props.fetchInterfaceColList(this.props.match.params.id); + } if (res.data.errcode) { message.error(res.data.errmsg) } else { @@ -118,17 +133,49 @@ export default class InterfaceCaseContent extends Component { } } + triggerEditCasename = () => { + this.setState({ + isEditingCasename: true, + editCasename: this.props.currCase.casename + }) + } + cancelEditCasename = () => { + this.setState({ + isEditingCasename: false, + editCasename: this.props.currCase.casename + }) + } + render() { const { currCase, currProject } = this.props; + const { isEditingCasename, editCasename } = this.state; const data = Object.assign({}, currCase, currProject, {_id: currCase._id}); return ( -
-

- {currCase.casename} - - 对应接口 +
+
+ {!isEditingCasename &&
+ {currCase.casename} +
} + + {isEditingCasename &&
+ this.setState({editCasename: e.target.value})} style={{fontSize: 18}} /> + {/* + */} +
} + + 对应接口 -

+
diff --git a/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.scss b/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.scss new file mode 100644 index 00000000..60831c54 --- /dev/null +++ b/client/containers/Project/Interface/InterfaceCol/InterfaceCaseContent.scss @@ -0,0 +1,33 @@ +.case-content { + padding: 6px 0; + .case-title { + display: flex; + .case-name { + margin-left: 8px; + border-radius: 4px; + border: 1px solid transparent; + padding: 0 5px; + background-color: #eee; + font-size: 20px; + flex-grow: 1; + cursor: pointer; + } + .case-name:hover { + color: rgba(0,0,0,.65); + border: 1px solid #d9d9d9; + } + .edit-case-name { + margin-left: 8px; + display: flex; + flex-grow: 1; + } + .inter-link { + flex-basis: 50px; + position: relative; + } + .inter-link .text { + position: absolute; + bottom: 4px; + } + } +} \ No newline at end of file