mirror of
https://github.com/YMFE/yapi.git
synced 2024-12-09 05:00:30 +08:00
Merge branch 'dev' of http://gitlab.corp.qunar.com/mfe/yapi into dev
This commit is contained in:
commit
d021a06986
@ -181,7 +181,7 @@ export default class HeaderCom extends Component {
|
||||
<Link to="/group">项目广场</Link>
|
||||
</Menu.Item>
|
||||
<Menu.Item key="/doc">
|
||||
<a target="_blank" href="./doc/index.html">文档</a>
|
||||
<a target="_blank" href="./doc/index.html">使用文档</a>
|
||||
</Menu.Item>
|
||||
</Menu>
|
||||
<div className="user-toolbar">
|
||||
|
@ -25,8 +25,8 @@ import {
|
||||
} from '../../actions/addInterface.js'
|
||||
|
||||
let projectId = ''
|
||||
const success = () => {
|
||||
message.success('保存成功!')
|
||||
const success = (text, arg) => {
|
||||
arg ? message.success(text) : message.error(text)
|
||||
}
|
||||
|
||||
@connect(
|
||||
@ -149,8 +149,8 @@ class AddInterface extends Component {
|
||||
const params = {id: project_id}
|
||||
axios.get('/project/get', {params: params}).
|
||||
then( data => {
|
||||
const { protocol, prd_host, basepath } = data.data.data
|
||||
const mockURL = `${protocol}://${prd_host}${basepath}${result.path}`
|
||||
const { prd_host, basepath } = data.data.data
|
||||
const mockURL = `http://${prd_host}${basepath}${result.path}`
|
||||
this.setState({
|
||||
mockURL: mockURL,
|
||||
projectData: data.data.data
|
||||
@ -280,11 +280,16 @@ class AddInterface extends Component {
|
||||
|
||||
axios.post(postURL, params)
|
||||
.then(data => {
|
||||
if(data.data.errcode !== 0){
|
||||
this.setLoading()
|
||||
success(data.data.errmsg, false)
|
||||
return null;
|
||||
}
|
||||
const id = data.data.data._id
|
||||
const _id = id || interfaceId
|
||||
|
||||
this.setLoading()
|
||||
success()
|
||||
success('保存成功!', true)
|
||||
this.changeState(true)
|
||||
// 初始化 mock
|
||||
this.mockData()
|
||||
@ -295,8 +300,10 @@ class AddInterface extends Component {
|
||||
|
||||
this.jumpEditUrl(_id)
|
||||
})
|
||||
.catch(e => {
|
||||
console.log(e)
|
||||
.catch(error => {
|
||||
this.setLoading()
|
||||
success('程序出错,请联系管理员检查!', false)
|
||||
console.log(error)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -103,11 +103,20 @@ export default class InterfaceTest extends Component {
|
||||
}
|
||||
|
||||
const headers = []
|
||||
seqGroup.forEach((headerItem) => {
|
||||
let contentTypeIndex = -1;
|
||||
seqGroup.forEach((headerItem, index) => {
|
||||
if (headerItem.name) {
|
||||
// TODO 'Content-Type' 排除大小写不同格式影响
|
||||
if (headerItem.name === 'Content-Type'){
|
||||
contentTypeIndex = index;
|
||||
headerItem.value = headerItem.value || 'application/x-www-form-urlencoded';
|
||||
}
|
||||
headers.push({name: headerItem.name, value: headerItem.value});
|
||||
}
|
||||
})
|
||||
if (contentTypeIndex === -1) {
|
||||
headers.push({name: 'Content-Type', value: 'application/x-www-form-urlencoded'});
|
||||
}
|
||||
|
||||
this.setState({
|
||||
method,
|
||||
@ -142,6 +151,7 @@ export default class InterfaceTest extends Component {
|
||||
method,
|
||||
headers: this.getHeadersObj(headers),
|
||||
data: this.arrToObj(params),
|
||||
files: this.getFiles(params),
|
||||
success: (res) => {
|
||||
try {
|
||||
res = JSON.parse(res)
|
||||
@ -189,6 +199,12 @@ export default class InterfaceTest extends Component {
|
||||
const { headers } = this.state;
|
||||
this.setState({headers: headers.filter((item, i) => +index !== +i)});
|
||||
}
|
||||
@autobind
|
||||
setContentType(type) {
|
||||
const headersObj = this.getHeadersObj(this.state.headers);
|
||||
headersObj['Content-Type'] = type;
|
||||
this.setState({headers: this.objToArr(headersObj, 'name')})
|
||||
}
|
||||
|
||||
@autobind
|
||||
changeQuery(e, index, isKey) {
|
||||
@ -223,11 +239,18 @@ export default class InterfaceTest extends Component {
|
||||
params[index].type = e
|
||||
break;
|
||||
case 'value':
|
||||
params[index].value = e.target.value
|
||||
if (params[index].type === 'file') {
|
||||
params[index].value = e.target.id
|
||||
} else {
|
||||
params[index].value = e.target.value
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (type === 'type' && e === 'file') {
|
||||
this.setContentType('multipart/form-data')
|
||||
}
|
||||
this.setState({ params });
|
||||
}
|
||||
@autobind
|
||||
@ -266,15 +289,35 @@ export default class InterfaceTest extends Component {
|
||||
return dom.getAttribute('key') === 'yapi';
|
||||
}
|
||||
|
||||
objToArr(obj, key, value) {
|
||||
const keyName = key || 'key';
|
||||
const valueName = value || 'value';
|
||||
const arr = []
|
||||
Object.keys(obj).forEach((_key) => {
|
||||
if (_key) {
|
||||
arr.push({[keyName]: _key, [valueName]: obj[_key]});
|
||||
}
|
||||
})
|
||||
return arr;
|
||||
}
|
||||
arrToObj(arr) {
|
||||
const obj = {};
|
||||
arr.forEach(item => {
|
||||
if (item.key) {
|
||||
if (item.key && item.type !== 'file') {
|
||||
obj[item.key] = item.value || '';
|
||||
}
|
||||
})
|
||||
return obj;
|
||||
}
|
||||
getFiles(params) {
|
||||
const files = {};
|
||||
params.forEach(item => {
|
||||
if (item.key && item.type === 'file') {
|
||||
files[item.key] = item.value
|
||||
}
|
||||
})
|
||||
return files;
|
||||
}
|
||||
getQueryObj(query) {
|
||||
const queryObj = {};
|
||||
query.forEach(item => {
|
||||
@ -294,6 +337,12 @@ export default class InterfaceTest extends Component {
|
||||
return headersObj;
|
||||
}
|
||||
|
||||
@autobind
|
||||
fileChange(e, index) {
|
||||
console.log(e)
|
||||
console.log(index)
|
||||
}
|
||||
|
||||
render () {
|
||||
|
||||
const { interfaceName } = this.props;
|
||||
@ -418,7 +467,7 @@ export default class InterfaceTest extends Component {
|
||||
<Option value="text">Text</Option>
|
||||
</Select>]{' = '}
|
||||
{item.type === 'file' ?
|
||||
<Input type="file" style={{display: 'inline-block', width: 200, margin: 10}} /> :
|
||||
<Input type="file" id={'file_' + index} onChange={e => this.changeParams(e, index, 'value')} multiple style={{display: 'inline-block', width: 200, margin: 10}} /> :
|
||||
<Input value={item.value} onChange={e => this.changeParams(e, index, 'value')} style={{display: 'inline-block', width: 200, margin: 10}} />
|
||||
}
|
||||
</div>
|
||||
|
@ -42,7 +42,8 @@ class ReqHeader extends Component {
|
||||
addSeqGroup () {
|
||||
let newSeqGroup = []
|
||||
let seqGroup = this.props.seqGroup
|
||||
let id = seqGroup[seqGroup.length-1].id
|
||||
let length = seqGroup.length
|
||||
let id = length ? seqGroup[length-1].id : 0
|
||||
let list = {
|
||||
id: ++id,
|
||||
value: '',
|
||||
|
Loading…
Reference in New Issue
Block a user