mirror of
https://github.com/YMFE/yapi.git
synced 2025-01-18 13:04:46 +08:00
fix: postman功能判断请求body bug
This commit is contained in:
parent
10ddb12845
commit
04980a00ef
@ -1,8 +1,10 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import Mock from 'mockjs'
|
import Mock from 'mockjs'
|
||||||
import { Button, Input, Select, Card, Alert, Spin, Icon, Collapse, Radio, Tooltip, message } from 'antd'
|
import { Button, Input, Select, Card, Alert, Spin, Icon, Collapse, Tooltip, message } from 'antd'
|
||||||
import { autobind } from 'core-decorators';
|
import { autobind } from 'core-decorators';
|
||||||
|
import constants from '../../constants/variable.js'
|
||||||
|
|
||||||
import mockEditor from '../../containers/Project/Interface/InterfaceList/mockEditor'
|
import mockEditor from '../../containers/Project/Interface/InterfaceList/mockEditor'
|
||||||
import URL from 'url';
|
import URL from 'url';
|
||||||
const MockExtra = require('common/mock-extra.js')
|
const MockExtra = require('common/mock-extra.js')
|
||||||
@ -21,8 +23,8 @@ const { TextArea } = Input;
|
|||||||
const InputGroup = Input.Group;
|
const InputGroup = Input.Group;
|
||||||
const Option = Select.Option;
|
const Option = Select.Option;
|
||||||
const Panel = Collapse.Panel;
|
const Panel = Collapse.Panel;
|
||||||
const RadioButton = Radio.Button;
|
|
||||||
const RadioGroup = Radio.Group;
|
const HTTP_METHOD = constants.HTTP_METHOD;
|
||||||
|
|
||||||
export default class Run extends Component {
|
export default class Run extends Component {
|
||||||
|
|
||||||
@ -479,12 +481,12 @@ export default class Run extends Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { method, domains, pathParam, pathname, query, headers, bodyForm, caseEnv, bodyType, resHeader, loading, validRes } = this.state;
|
const { method, domains, pathParam, pathname, query, headers, bodyForm, caseEnv, bodyType, resHeader, loading, validRes } = this.state;
|
||||||
|
|
||||||
const hasPlugin = this.state.hasPlugin;
|
const hasPlugin = this.state.hasPlugin;
|
||||||
let isResJson = false;
|
let isResJson = false;
|
||||||
|
|
||||||
if(resHeader && typeof resHeader === 'object'){
|
if (resHeader && typeof resHeader === 'object') {
|
||||||
Object.keys(resHeader).map(key => {
|
Object.keys(resHeader).map(key => {
|
||||||
console.log(key)
|
|
||||||
if (/content-type/i.test(key) && /application\/json/i.test(resHeader[key])) {
|
if (/content-type/i.test(key) && /application\/json/i.test(resHeader[key])) {
|
||||||
isResJson = true;
|
isResJson = true;
|
||||||
}
|
}
|
||||||
@ -501,7 +503,7 @@ export default class Run extends Component {
|
|||||||
validResView = '请定义返回json'
|
validResView = '请定义返回json'
|
||||||
}
|
}
|
||||||
if (Array.isArray(validRes) && validRes.length > 0) {
|
if (Array.isArray(validRes) && validRes.length > 0) {
|
||||||
validResView = validRes.map((item,index)=>{
|
validResView = validRes.map((item, index) => {
|
||||||
return <div key={index}>{item.message}</div>
|
return <div key={index}>{item.message}</div>
|
||||||
})
|
})
|
||||||
} else if (Array.isArray(validRes)) {
|
} else if (Array.isArray(validRes)) {
|
||||||
@ -622,33 +624,21 @@ export default class Run extends Component {
|
|||||||
<Panel
|
<Panel
|
||||||
header={
|
header={
|
||||||
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
|
||||||
<div>BODY</div>
|
<div>BODY</div>
|
||||||
<div onClick={e => e.stopPropagation()} style={{ marginRight: 5 }}>
|
|
||||||
<Select disabled value={bodyType !== 'form' && bodyType !== 'file' ? 'text' : bodyType} onChange={this.changeBodyType} className={method === 'POST' ? '' : 'none'}>
|
|
||||||
<Option value="text">Text</Option>
|
|
||||||
<Option value="file">File</Option>
|
|
||||||
<Option value="form">Form</Option>
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
key="3"
|
key="3"
|
||||||
className={method === 'POST' ? '' : 'hidden'}
|
className={HTTP_METHOD[method].request_body?'POST':'hidden'}
|
||||||
>
|
>
|
||||||
{method === 'POST' && bodyType !== 'form' && bodyType !== 'file' &&
|
|
||||||
<div>
|
<div style={{ display: HTTP_METHOD[method].request_body && bodyType !== 'form' && bodyType !== 'file'? 'block': 'none' }}>
|
||||||
<RadioGroup disabled value={bodyType} onChange={(e) => this.changeBodyType(e.target.value)}>
|
<div id="body-other-edit" style={{ marginTop: 10 }} className="pretty-editor"></div>
|
||||||
<RadioButton value="json">JSON</RadioButton>
|
</div>
|
||||||
<RadioButton value="text">TEXT</RadioButton>
|
|
||||||
<RadioButton value="xml">XML</RadioButton>
|
|
||||||
</RadioGroup>
|
|
||||||
<div id="body-other-edit" style={{ marginTop: 10 }} className="pretty-editor"></div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
method === 'POST' && bodyType === 'form' &&
|
HTTP_METHOD[method].request_body && bodyType === 'form' &&
|
||||||
<div>
|
<div>
|
||||||
{
|
{
|
||||||
bodyForm.map((item, index) => {
|
bodyForm.map((item, index) => {
|
||||||
return (
|
return (
|
||||||
<div key={index} className="key-value-wrap">
|
<div key={index} className="key-value-wrap">
|
||||||
@ -697,7 +687,7 @@ export default class Run extends Component {
|
|||||||
value={this.state.res && this.state.res.toString()}
|
value={this.state.res && this.state.res.toString()}
|
||||||
autosize={{ minRows: 10, maxRows: 20 }}
|
autosize={{ minRows: 10, maxRows: 20 }}
|
||||||
></TextArea>
|
></TextArea>
|
||||||
<h3 style={{marginTop: '15px',display: isResJson ? '' : 'none'}}>返回 Body 验证结果:</h3>
|
<h3 style={{ marginTop: '15px', display: isResJson ? '' : 'none' }}>返回 Body 验证结果:</h3>
|
||||||
<div style={{ display: isResJson ? '' : 'none' }}>
|
<div style={{ display: isResJson ? '' : 'none' }}>
|
||||||
{validResView}
|
{validResView}
|
||||||
</div>
|
</div>
|
||||||
|
@ -65,6 +65,10 @@ class InterfaceEdit extends Component {
|
|||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
let domain = location.hostname + (location.port !== "" ? ":" + location.port : "");
|
let domain = location.hostname + (location.port !== "" ? ":" + location.port : "");
|
||||||
|
this.setState({
|
||||||
|
curdata: this.props.curdata,
|
||||||
|
status: 1
|
||||||
|
})
|
||||||
|
|
||||||
let s = new WebSocket('ws://' + domain + '/api/interface/solve_conflict?id=' + this.props.match.params.actionId);
|
let s = new WebSocket('ws://' + domain + '/api/interface/solve_conflict?id=' + this.props.match.params.actionId);
|
||||||
s.onopen = () => {
|
s.onopen = () => {
|
||||||
@ -87,11 +91,8 @@ class InterfaceEdit extends Component {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.onerror = () => {
|
s.onerror = () => {
|
||||||
this.setState({
|
console.error('websocket connect failed.')
|
||||||
curdata: this.props.curdata,
|
|
||||||
status: 1
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -89,7 +89,6 @@ class InterfaceMenu extends Component {
|
|||||||
|
|
||||||
async getList(){
|
async getList(){
|
||||||
let r = await this.props.fetchInterfaceList(this.props.projectId);
|
let r = await this.props.fetchInterfaceList(this.props.projectId);
|
||||||
console.log(r.payload.data)
|
|
||||||
this.setState({
|
this.setState({
|
||||||
list: JSON.parse(JSON.stringify(r.payload.data))
|
list: JSON.parse(JSON.stringify(r.payload.data))
|
||||||
})
|
})
|
||||||
|
@ -5,7 +5,6 @@ import App from './Application'
|
|||||||
import { Provider } from 'react-redux'
|
import { Provider } from 'react-redux'
|
||||||
import createStore from './reducer/create';
|
import createStore from './reducer/create';
|
||||||
import './styles/theme.less'
|
import './styles/theme.less'
|
||||||
console.log('index.js')
|
|
||||||
const store = createStore();
|
const store = createStore();
|
||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
|
Loading…
Reference in New Issue
Block a user