mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-21 05:19:42 +08:00
opti: case_env
This commit is contained in:
parent
de840ae7c4
commit
e2b72aa49f
@ -34,6 +34,7 @@ export default class Run extends Component {
|
|||||||
bodyForm: [],
|
bodyForm: [],
|
||||||
headers: [],
|
headers: [],
|
||||||
currDomain: '',
|
currDomain: '',
|
||||||
|
caseEnv: '',
|
||||||
bodyType: '',
|
bodyType: '',
|
||||||
bodyOther: '',
|
bodyOther: '',
|
||||||
isDidMount: false
|
isDidMount: false
|
||||||
@ -75,37 +76,37 @@ export default class Run extends Component {
|
|||||||
req_body_form = [],
|
req_body_form = [],
|
||||||
basepath = '',
|
basepath = '',
|
||||||
env = [],
|
env = [],
|
||||||
domain = ''
|
case_env = ''
|
||||||
} = data;
|
} = data;
|
||||||
// case 任意编辑 pathname,不管项目的 basepath
|
// case 任意编辑 pathname,不管项目的 basepath
|
||||||
const pathname = (type === 'inter' ? (basepath + url) : url).replace(/\/+/g, '/');
|
const pathname = (type === 'inter' ? (basepath + url) : url).replace(/\/+/g, '/');
|
||||||
|
|
||||||
let hasContentType = false;
|
// let hasContentType = false;
|
||||||
req_headers.forEach(headerItem => {
|
// req_headers.forEach(headerItem => {
|
||||||
// TODO 'Content-Type' 排除大小写不同格式影响
|
// // TODO 'Content-Type' 排除大小写不同格式影响
|
||||||
if (headerItem.name === 'Content-Type'){
|
// if (headerItem.name === 'Content-Type'){
|
||||||
hasContentType = true;
|
// hasContentType = true;
|
||||||
headerItem.value = headerItem.value || 'application/x-www-form-urlencoded';
|
// headerItem.value = headerItem.value || 'application/x-www-form-urlencoded';
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
if (!hasContentType) {
|
// if (!hasContentType) {
|
||||||
req_headers.push({name: 'Content-Type', value: 'application/x-www-form-urlencoded'});
|
// req_headers.push({name: 'Content-Type', value: 'application/x-www-form-urlencoded'});
|
||||||
}
|
// }
|
||||||
const domains = env.concat();
|
// const domains = env.concat();
|
||||||
if (domain && !env.find(item => item.domain === domain)) {
|
// if (domain && !env.find(item => item.domain === domain)) {
|
||||||
domains.push({name: 'default', domain})
|
// domains.push({name: 'default', domain})
|
||||||
}
|
// }
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
method,
|
method,
|
||||||
domains,
|
domains: env.concat(),
|
||||||
pathParam: req_params.concat(),
|
pathParam: req_params.concat(),
|
||||||
pathname,
|
pathname,
|
||||||
query: req_query.concat(),
|
query: req_query.concat(),
|
||||||
bodyForm: req_body_form.concat(),
|
bodyForm: req_body_form.concat(),
|
||||||
headers: req_headers.concat(),
|
headers: req_headers.concat(),
|
||||||
bodyOther: req_body_other,
|
bodyOther: req_body_other,
|
||||||
currDomain: domain || (env[0] && env[0].domain),
|
caseEnv: case_env || (env[0] && env[0].name),
|
||||||
bodyType: req_body_type || 'form',
|
bodyType: req_body_type || 'form',
|
||||||
loading: false
|
loading: false
|
||||||
}, () => {
|
}, () => {
|
||||||
@ -169,7 +170,7 @@ export default class Run extends Component {
|
|||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
selectDomain(value) {
|
selectDomain(value) {
|
||||||
this.setState({ currDomain: value });
|
this.setState({ caseEnv: value });
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
@ -404,7 +405,7 @@ export default class Run extends Component {
|
|||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
|
||||||
const { method, domains, pathParam, pathname, query, headers, bodyForm, currDomain, bodyType, resHeader } = this.state;
|
const { method, domains, pathParam, pathname, query, headers, bodyForm, caseEnv, bodyType, resHeader } = this.state;
|
||||||
const hasPlugin = this.hasCrossRequestPlugin();
|
const hasPlugin = this.hasCrossRequestPlugin();
|
||||||
const isResJson = resHeader && resHeader['content-type'] && resHeader['content-type'].indexOf('application/json') !== -1
|
const isResJson = resHeader && resHeader['content-type'] && resHeader['content-type'].indexOf('application/json') !== -1
|
||||||
let path = pathname;
|
let path = pathname;
|
||||||
@ -452,9 +453,9 @@ export default class Run extends Component {
|
|||||||
<Option value="GET">GET</Option>
|
<Option value="GET">GET</Option>
|
||||||
<Option value="POST">POST</Option>
|
<Option value="POST">POST</Option>
|
||||||
</Select>
|
</Select>
|
||||||
<Select disabled value={currDomain} mode="combobox" filterOption={() => true} style={{flexBasis: 180, flexGrow: 1}} onChange={this.changeDomain} onSelect={this.selectDomain}>
|
<Select value={caseEnv} style={{flexBasis: 180, flexGrow: 1}} onSelect={this.selectDomain}>
|
||||||
{
|
{
|
||||||
domains.map((item, index) => (<Option value={item.domain} key={index}>{item.name + ':' + item.domain}</Option>))
|
domains.map((item, index) => (<Option value={item.name} key={index}>{item.name + ':' + item.domain}</Option>))
|
||||||
}
|
}
|
||||||
</Select>
|
</Select>
|
||||||
<Input disabled value={path + search} onChange={this.changePath} spellCheck="false" style={{flexBasis: 180, flexGrow: 1}} />
|
<Input disabled value={path + search} onChange={this.changePath} spellCheck="false" style={{flexBasis: 180, flexGrow: 1}} />
|
||||||
|
@ -85,7 +85,7 @@ export default class InterfaceCaseContent extends Component {
|
|||||||
|
|
||||||
updateCase = async () => {
|
updateCase = async () => {
|
||||||
const {
|
const {
|
||||||
currDomain: domain,
|
caseEnv: case_env,
|
||||||
pathname: path,
|
pathname: path,
|
||||||
method,
|
method,
|
||||||
pathParam: req_params,
|
pathParam: req_params,
|
||||||
@ -99,7 +99,7 @@ export default class InterfaceCaseContent extends Component {
|
|||||||
const res = await axios.post('/api/col/up_case', {
|
const res = await axios.post('/api/col/up_case', {
|
||||||
id,
|
id,
|
||||||
casename,
|
casename,
|
||||||
domain,
|
case_env,
|
||||||
path,
|
path,
|
||||||
method,
|
method,
|
||||||
req_params,
|
req_params,
|
||||||
|
@ -49,7 +49,7 @@ export default class Run extends Component {
|
|||||||
const project_id = this.props.match.params.id;
|
const project_id = this.props.match.params.id;
|
||||||
const interface_id = this.props.currInterface._id;
|
const interface_id = this.props.currInterface._id;
|
||||||
const {
|
const {
|
||||||
currDomain: domain,
|
caseEnv: case_env,
|
||||||
pathname: path,
|
pathname: path,
|
||||||
method,
|
method,
|
||||||
pathParam: req_params,
|
pathParam: req_params,
|
||||||
@ -64,7 +64,7 @@ export default class Run extends Component {
|
|||||||
casename: caseName,
|
casename: caseName,
|
||||||
col_id: colId,
|
col_id: colId,
|
||||||
project_id,
|
project_id,
|
||||||
domain,
|
case_env,
|
||||||
path,
|
path,
|
||||||
method,
|
method,
|
||||||
req_params,
|
req_params,
|
||||||
|
Loading…
Reference in New Issue
Block a user