yapi/client/containers/Interface/Interface.js

88 lines
2.1 KiB
JavaScript
Raw Normal View History

2017-07-11 19:12:13 +08:00
import './Interface.scss'
import React, { Component } from 'react'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'
2017-07-20 15:38:25 +08:00
import axios from 'axios'
2017-07-11 19:12:13 +08:00
import InterfaceList from './InterfaceList/InterfaceList.js'
import InterfaceTable from './InterfaceTable/InterfaceTable.js'
2017-07-13 20:09:04 +08:00
import InterfaceMode from './InterfaceMode/InterfaceMode.js'
2017-07-24 10:59:17 +08:00
import moment from 'moment'
2017-07-18 18:25:53 +08:00
import {
2017-07-13 20:09:04 +08:00
fetchInterfaceData,
projectMember,
2017-07-14 11:27:34 +08:00
closeProjectMember
2017-07-13 20:09:04 +08:00
} from '../../actions/interfaceAction.js'
2017-07-11 19:12:13 +08:00
@connect(
state => {
return {
2017-07-13 20:09:04 +08:00
interfaceData: state.Interface.interfaceData,
modalVisible: state.Interface.modalVisible,
2017-07-14 11:27:34 +08:00
closeProjectMember: state.Interface.closeProjectMember
2017-07-11 19:12:13 +08:00
}
},
{
2017-07-13 20:09:04 +08:00
fetchInterfaceData,
projectMember,
2017-07-14 11:27:34 +08:00
closeProjectMember
2017-07-11 19:12:13 +08:00
}
)
2017-07-13 20:09:04 +08:00
2017-07-11 19:12:13 +08:00
class Interface extends Component {
static propTypes = {
2017-07-13 20:09:04 +08:00
fetchInterfaceData: PropTypes.func,
interfaceData: PropTypes.array,
projectMember: PropTypes.func,
closeProjectMember: PropTypes.func,
2017-07-14 11:27:34 +08:00
modalVisible: PropTypes.bool
2017-07-11 19:12:13 +08:00
}
constructor(props) {
super(props)
}
componentWillMount () {
2017-07-25 17:41:58 +08:00
const interfaceId = this.getInterfaceId()
2017-07-20 15:38:25 +08:00
const params = {
2017-07-20 16:34:46 +08:00
params: {
2017-07-25 17:41:58 +08:00
project_id: interfaceId
2017-07-20 16:34:46 +08:00
}
2017-07-20 15:38:25 +08:00
}
axios.get('/interface/list', params)
2017-07-24 10:59:17 +08:00
.then(result => {
result = result.data.data
result.map(value => {
value.add_time = moment(value.add_time).format('YYYY-MM-DD HH:mm:ss')
return value
})
this.props.fetchInterfaceData(result)
2017-07-20 15:38:25 +08:00
})
.catch(e => {
console.log(e)
})
2017-07-11 19:12:13 +08:00
}
2017-07-25 17:41:58 +08:00
getInterfaceId () {
const reg = /Interface\/(\d+)/g
const url = location.href
url.match(reg)
return RegExp.$1
}
2017-07-11 19:12:13 +08:00
render () {
2017-07-13 20:09:04 +08:00
const { interfaceData, projectMember, modalVisible } = this.props
2017-07-11 19:12:13 +08:00
return (
2017-07-14 14:44:32 +08:00
<div>
<section className="interface-box">
<InterfaceList projectMember={projectMember} />
<InterfaceMode modalVisible={modalVisible} closeProjectMember={this.props.closeProjectMember} />
<InterfaceTable data={interfaceData} />
</section>
</div>
2017-07-11 19:12:13 +08:00
)
}
}
2017-07-24 10:59:17 +08:00
export default Interface