Skip to content

Commit

Permalink
fix: 针对有特殊字符的常量,新加一个安全常量输入 #28
Browse files Browse the repository at this point in the history
  • Loading branch information
wantong committed Oct 15, 2019
1 parent addd5dc commit 1670000
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 37 deletions.
61 changes: 51 additions & 10 deletions client/components/ModalPostman/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class ModalPostman extends Component {
methodsShowMore: false,
methodsList: [],
constantInput: '',
safeConstantInput: '',
activeKey: '1',
methodsParamsList: [
{
Expand All @@ -63,11 +64,22 @@ class ModalPostman extends Component {

componentWillMount() {
let { inputValue } = this.props;
this.setState({
constantInput: inputValue
});
const decodeInputValue = decodeURIComponent(inputValue);
if (decodeInputValue === inputValue) {
this.setState({
constantInput: inputValue,
safeConstantInput: ''
});
inputValue && this.handleInitList(inputValue);
} else {
this.setState({
constantInput: '',
safeConstantInput: decodeInputValue
});
inputValue && this.handleInitList(decodeInputValue);
}
// this.props.inputValue && this.handleConstantsInput(this.props.inputValue, 0);
inputValue && this.handleInitList(inputValue);
// inputValue && this.handleInitList(inputValue);
}

handleInitList(val) {
Expand Down Expand Up @@ -140,6 +152,14 @@ class ModalPostman extends Component {
this.mockClick(0)(val);
};

handleSafeConstantsInput = val => {
// val = val.replace(/^\{\{(.+)\}\}$/g, '$1');
this.setState({
safeConstantInput: val
});
this.mockClick(0)( encodeURIComponent(val));
};

handleParamsInput = (e, clickIndex, paramsIndex) => {
let newParamsList = deepEqual(this.state.methodsParamsList);
newParamsList[clickIndex].params[paramsIndex] = e;
Expand Down Expand Up @@ -209,7 +229,7 @@ class ModalPostman extends Component {

render() {
const { visible, envType } = this.props;
const { methodsParamsList, constantInput } = this.state;
const { methodsParamsList, constantInput, safeConstantInput } = this.state;

const outputParams = () => {
let str = '';
Expand Down Expand Up @@ -254,11 +274,32 @@ class ModalPostman extends Component {
accordion
>
<Panel header={<h3 className="mock-title">常量</h3>} key="1">
<Input
placeholder="基础参数值"
value={constantInput}
onChange={e => this.handleConstantsInput(e.target.value, index)}
/>
<div className="notice">
注意如果参数值中含有
<b>{"{"}</b>
<b>{"}"}</b>
<b>|</b>
<b>,</b>
<b>:</b>
等符号,请在安全常量内输入,
其余请使用 YAPI 原版常量
</div>
<Row>
<Col>原版常量:</Col>
<Input
placeholder="基础参数值"
value={constantInput}
onChange={e => this.handleConstantsInput(e.target.value, index)}
/>
</Row>
<Row>
<Col>安全常量:</Col>
<Input
placeholder="基础参数值"
value={safeConstantInput}
onChange={e => this.handleSafeConstantsInput(e.target.value, index)}
/>
</Row>
</Panel>
<Panel header={<h3 className="mock-title">mock数据</h3>} key="2">
<MockList click={this.mockClick(index)} clickValue={item.name} />
Expand Down
12 changes: 10 additions & 2 deletions client/components/ModalPostman/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
max-height: 500px;
min-height: 400px;
overflow-y: scroll;

.notice {
background: antiquewhite;
b {
margin:0 0.2em;
}
}

.ant-radio-group{
width:100%;
}
Expand Down Expand Up @@ -42,7 +50,7 @@
}
.modal-postman-preview {
background-color: #f5f5f5;

}
.modal-postman-collapse{
.ant-collapse-item > .ant-collapse-header{
Expand Down Expand Up @@ -139,5 +147,5 @@
}
}


}
2 changes: 1 addition & 1 deletion common/power-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function handleOriginStr(str, handleValueFn) {

function execute(str, curItem, index) {
if (index === 0) {
return new PowerString(curItem);
return new PowerString(decodeURIComponent(curItem));
}
return str[curItem.method].apply(str, curItem.args);
}
Expand Down
27 changes: 3 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1670000

Please sign in to comment.