yapi/client/containers/AddInterface/AddInterface.js

102 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-07-18 12:53:53 +08:00
import './AddInterface.scss'
import React, { Component } from 'react'
2017-07-20 14:48:29 +08:00
import PropTypes from 'prop-types'
import axios from 'axios'
import { connect } from 'react-redux'
import { autobind } from 'core-decorators'
2017-07-20 16:34:46 +08:00
import { Button, Tabs } from 'antd'
2017-07-18 12:53:53 +08:00
import ReqMethod from './ReqMethod/ReqMethod.js'
import ReqHeader from './ReqHeader/ReqHeader.js'
import ReqParams from './ReqParams/ReqParams.js'
import ResParams from './ResParams/ResParams.js'
import Result from './Result/Result.js'
2017-07-20 14:48:29 +08:00
import { saveForms } from '../../actions/addInterface.js'
2017-07-18 12:53:53 +08:00
2017-07-20 14:48:29 +08:00
@connect(
state => {
return {
2017-07-20 16:57:21 +08:00
reqParams: state.addInterface.reqParams,
methode: state.addInterface.method
2017-07-20 14:48:29 +08:00
}
},
{
saveForms
}
)
2017-07-18 12:53:53 +08:00
2017-07-20 14:48:29 +08:00
class AddInterface extends Component {
static propTypes = {
reqParams: PropTypes.string,
2017-07-20 16:57:21 +08:00
methode: PropTypes.string,
2017-07-20 14:48:29 +08:00
saveForms: PropTypes.func
}
2017-07-18 12:53:53 +08:00
constructor (props) {
super(props)
}
2017-07-20 14:48:29 +08:00
@autobind
2017-07-18 12:53:53 +08:00
saveForms () {
2017-07-20 14:48:29 +08:00
// const config = {
// url: '/interface/add',
// method: 'POST',
// headers: {'Content-Type': 'application/json'},
// params: {
// method: 'POST',
// project_id: 8,
// req_headers: [],
// req_params_type: 'json',
// req_params: this.props.reqParams
// }
// }
const params = {
url: '/interface/add',
method: 'POST',
params: {
method: 'POST',
2017-07-20 16:34:46 +08:00
project_id: 558,
2017-07-20 14:48:29 +08:00
req_headers: [],
req_params_type: 'json',
2017-07-20 16:34:46 +08:00
req_params: this.props.reqParams,
title: '接口文档1'
2017-07-20 14:48:29 +08:00
}
}
axios.post('/interface/add', params)
.then(data => {
console.log(data)
2017-07-20 16:57:21 +08:00
console.log(this.props.methode)
2017-07-20 14:48:29 +08:00
})
.catch(e => {
console.log(e)
})
2017-07-18 12:53:53 +08:00
}
render () {
2017-07-20 16:34:46 +08:00
const TabPane = Tabs.TabPane
2017-07-18 12:53:53 +08:00
return (
2017-07-20 16:38:50 +08:00
<section className="add-interface-box">
<div className="content">
<Tabs defaultActiveKey="1">
<TabPane tab="接口详情" key="1">
2017-07-20 16:34:46 +08:00
<Button type="primary" className="save" onClick={this.saveForms}>保存</Button>
<ReqMethod />
<ReqHeader />
<ReqParams />
<ResParams />
<Result />
2017-07-20 16:38:50 +08:00
</TabPane>
<TabPane tab="Mock" key="2">mock</TabPane>
<TabPane tab="测试" key="3">测试</TabPane>
</Tabs>
</div>
</section>
2017-07-18 12:53:53 +08:00
)
}
}
export default AddInterface