quality_frontend/platform/example/src/component/step/http/Options.tsx

87 lines
3.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {ChangeEvent, Component} from "react";
import {Input, InputNumber, Switch} from "antd";
import style from "./Http.module.less"
const defaultData:OptionsData = {
code: "UTF-8",
redirect: false,
requestSwitch: true,
timeout: 5000,
uploadType: "HttpClient4"
}
class Options extends Component<HttpProps<OptionsData>,HttpState<OptionsData>>{
constructor(props:HttpProps<OptionsData>) {
super(props);
this.state = {
options:Object.assign({},defaultData,this.props.data)
}
}
domChange(e:ChangeEvent<HTMLInputElement>,key:OptionsDataType){
const value = e.target.value
const options = this.state.options
options[key] =value
this.setState({options:Object.assign({},{...this.state.options},options)})
this.change()
}
valueChange(value:string|number|boolean,key:string){
const options = this.state.options
options[key] =value
this.setState({options:Object.assign({},{...this.state.options},options)})
this.change()
}
change(){
this.props.onchange("options",this.state.options)
}
render() {
return <div className={style.HttpContentFlex}>
<div className={style.HttpOptionFlex}>
<div>
<div className={style.HttpTitle}></div>
<p></p>
</div>
<div>
<Input value={this.state.options.code} onChange={(e)=>this.domChange(e,"code")} defaultValue="UTF-8" />
</div>
</div>
<div className={style.HttpOptionFlex}>
<div>
<div className={style.HttpTitle}></div>
<p></p>
</div>
<div>
<Input value={this.state.options.uploadType} onChange={(e)=>this.domChange(e,"uploadType")} defaultValue="HttpClient4" />
</div>
</div>
<div className={style.HttpOptionFlex}>
<div>
<div className={style.HttpTitle}></div>
<p>POST使用multipart/from-data</p>
</div>
<div>
<Switch checkedChildren="开启" unCheckedChildren="关闭" onChange={(e)=>this.valueChange(e,"requestSwitch")} defaultChecked checked={this.state.options.requestSwitch} />
</div>
</div>
<div className={style.HttpOptionFlex}>
<div>
<div className={style.HttpTitle}></div>
<p></p>
</div>
<div>
<InputNumber addonAfter="ms" defaultValue={5000} onChange={(e)=>this.valueChange(e,"timeout")} value={this.state.options.timeout} />
</div>
</div>
<div className={style.HttpOptionFlex}>
<div>
<div className={style.HttpTitle}></div>
<p></p>
</div>
<div>
<Switch checkedChildren="开启" unCheckedChildren="关闭" defaultChecked checked={this.state.options.redirect} />
</div>
</div>
</div>;
}
}
export default Options