2017-07-11 19:12:13 +08:00
|
|
|
import React, { Component } from 'react'
|
|
|
|
import { Table, Button } from 'antd'
|
|
|
|
import PropTypes from 'prop-types'
|
2017-07-24 10:59:17 +08:00
|
|
|
import axios from 'axios'
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
import { Link } from 'react-router-dom'
|
|
|
|
import { deleteInterfaceData } from '../../../actions/interfaceAction.js'
|
|
|
|
|
|
|
|
@connect(
|
|
|
|
state => {
|
|
|
|
return {
|
|
|
|
interfaceData: state.Interface.interfaceData
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
deleteInterfaceData
|
|
|
|
}
|
|
|
|
)
|
2017-07-11 19:12:13 +08:00
|
|
|
|
|
|
|
class InterfaceTable extends Component {
|
|
|
|
static propTypes = {
|
2017-07-24 10:59:17 +08:00
|
|
|
interfaceData: PropTypes.array,
|
|
|
|
data: PropTypes.array,
|
|
|
|
deleteInterfaceData: PropTypes.func
|
2017-07-11 19:12:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
}
|
|
|
|
|
2017-07-24 10:59:17 +08:00
|
|
|
deleteInterfaceData (interfaceId) {
|
|
|
|
let interfaceArr = []
|
|
|
|
let { interfaceData } = this.props
|
|
|
|
interfaceData.forEach(value => {
|
|
|
|
if (value._id !== interfaceId) {
|
|
|
|
interfaceArr.push(value)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
this.props.deleteInterfaceData(interfaceArr)
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteInterface (interfaceId) {
|
|
|
|
const params = {
|
|
|
|
id: interfaceId
|
|
|
|
}
|
|
|
|
axios.post('/interface/del', params)
|
|
|
|
.then(() => {
|
|
|
|
this.deleteInterfaceData(interfaceId)
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
console.log(err)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-11 19:12:13 +08:00
|
|
|
render () {
|
|
|
|
const columns = [{
|
|
|
|
title: '接口名称',
|
2017-07-24 10:59:17 +08:00
|
|
|
dataIndex: 'title',
|
|
|
|
key: 'title'
|
2017-07-11 19:12:13 +08:00
|
|
|
}, {
|
|
|
|
title: '接口URL',
|
2017-07-24 10:59:17 +08:00
|
|
|
dataIndex: 'path',
|
|
|
|
key: 'path'
|
|
|
|
},{
|
2017-07-11 19:12:13 +08:00
|
|
|
title: '更新日期',
|
2017-07-24 10:59:17 +08:00
|
|
|
dataIndex: 'add_time',
|
|
|
|
key: 'add_time'
|
2017-07-11 19:12:13 +08:00
|
|
|
}, {
|
|
|
|
title: '功能',
|
|
|
|
'key': 'action',
|
2017-07-24 10:59:17 +08:00
|
|
|
render: (data) => {
|
|
|
|
const deleteInterface = this.deleteInterface.bind(this, data._id)
|
2017-07-11 19:12:13 +08:00
|
|
|
return (
|
|
|
|
<span>
|
2017-07-24 10:59:17 +08:00
|
|
|
<Button type="primary">
|
|
|
|
<Link to={`/AddInterface/edit/${data._id}`}>编辑</Link>
|
|
|
|
</Button>
|
2017-07-25 13:34:48 +08:00
|
|
|
<Button type="primary">
|
|
|
|
<Link to={`/AddInterface/edit/${data._id}`}>测试</Link>
|
|
|
|
</Button>
|
2017-07-24 10:59:17 +08:00
|
|
|
<Button type="danger" onClick={deleteInterface}>删除</Button>
|
2017-07-11 19:12:13 +08:00
|
|
|
</span>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}]
|
|
|
|
|
|
|
|
const data = this.props.data;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<section className="interface-table">
|
|
|
|
<Table columns={columns} dataSource={data} />
|
|
|
|
</section>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-12 14:18:17 +08:00
|
|
|
export default InterfaceTable
|