From 290f8c5505a0c8ada4360e265c317d06f2d2111d Mon Sep 17 00:00:00 2001 From: suxiaoxin Date: Thu, 7 Dec 2017 14:29:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20pathname=20=E5=85=81=E8=AE=B8=E5=8F=AA?= =?UTF-8?q?=E6=9C=89=E4=B8=80=E4=B8=AA=20/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + .../ModalPostman/VariablesSelect.js | 34 ++++++++++++++----- client/components/ModalPostman/index.js | 5 +-- client/components/Postman/Postman.js | 1 + package.json | 2 +- server/utils/commons.js | 2 +- 6 files changed, 33 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89ab904e..fd302a1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ 1. Api 路径兼容 postman {varible} 2. View Response Height 问题 +3. pathname 允许只有一个 / ### v1.2.8 diff --git a/client/components/ModalPostman/VariablesSelect.js b/client/components/ModalPostman/VariablesSelect.js index 5dd17b1a..b1950577 100644 --- a/client/components/ModalPostman/VariablesSelect.js +++ b/client/components/ModalPostman/VariablesSelect.js @@ -3,6 +3,8 @@ import PropTypes from 'prop-types' import { Tree } from 'antd'; import { connect } from 'react-redux'; import { fetchVariableParamsList } from '../../reducer/modules/interfaceCol.js' + + const TreeNode = Tree.TreeNode; const CanSelectPathPrefix = 'CanSelectPath-'; @@ -29,26 +31,42 @@ class VariablesSelect extends Component { static propTypes = { click: PropTypes.func, currColId: PropTypes.number, - fetchVariableParamsList: PropTypes.func - + fetchVariableParamsList: PropTypes.func, + id: PropTypes.number } state = { records: [], expandedKeys: [] } + handleRecordsData(id){ + let newRecords = []; + this.id = id; + for(let i=0; i< this.records.length; i++){ + if(this.records[i]._id === id){ + break; + } + newRecords.push(this.records[i]) + } + this.setState({ + records: newRecords + }) + } + async componentDidMount() { const { currColId, fetchVariableParamsList } = this.props - let result = await fetchVariableParamsList(currColId); + let result = await fetchVariableParamsList(currColId); let records = result.payload.data.data; - records = records.sort((a, b)=>{ + this.records = records.sort((a, b)=>{ return a.index - b.index }) - this.setState({ - records - }) - + this.handleRecordsData(this.props.id) + } + async componentWillReceiveProps(nextProps){ + if(this.records && nextProps.id &&this.id !== nextProps.id ){ + this.handleRecordsData(nextProps.id) + } } handleSelect = (key) => { diff --git a/client/components/ModalPostman/index.js b/client/components/ModalPostman/index.js index 87ab1fc6..ab95fa73 100644 --- a/client/components/ModalPostman/index.js +++ b/client/components/ModalPostman/index.js @@ -37,7 +37,8 @@ class ModalPostman extends Component { handleCancel: PropTypes.func, handleOk: PropTypes.func, inputValue: PropTypes.any, - envType: PropTypes.string + envType: PropTypes.string, + id: PropTypes.number } constructor(props) { @@ -191,7 +192,7 @@ class ModalPostman extends Component { envType === 'case' && 变量 } key="3"> - + } diff --git a/client/components/Postman/Postman.js b/client/components/Postman/Postman.js index e71bd4d9..87e0f707 100755 --- a/client/components/Postman/Postman.js +++ b/client/components/Postman/Postman.js @@ -248,6 +248,7 @@ export default class Run extends Component { handleOk={this.handleModalOk} inputValue={inputValue} envType={this.props.type} + id={+this.state._id} > diff --git a/package.json b/package.json index 291912f0..2e085ebe 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yapi", - "version": "1.2.8", + "version": "1.2.9", "description": "YAPI", "main": "index.js", "scripts": { diff --git a/server/utils/commons.js b/server/utils/commons.js index 960dfe2c..1c5a1800 100755 --- a/server/utils/commons.js +++ b/server/utils/commons.js @@ -192,7 +192,7 @@ exports.handleVarPath = (pathname, params)=>{ * path第一位必需为 /, path 只允许由 字母数字-/_:.{}= 组成 */ exports.verifyPath = (path) => { - if (/^\/[a-zA-Z0-9\-\/_:\.\{\}\=]+$/.test(path)) { + if (/^\/[a-zA-Z0-9\-\/_:\.\{\}\=]*$/.test(path)) { return true; } else { return false;