yapi/client/containers/Interface/InterfaceTable/InterfaceTable.js

107 lines
2.5 KiB
JavaScript
Raw Normal View History

2017-07-11 19:12:13 +08:00
import React, { Component } from 'react'
2017-07-26 17:22:12 +08:00
import { Table, Popconfirm, message } from 'antd'
2017-07-11 19:12:13 +08:00
import PropTypes from 'prop-types'
2017-07-24 10:59:17 +08:00
import axios from 'axios'
2017-07-26 17:22:12 +08:00
import { autobind } from 'core-decorators'
2017-07-24 10:59:17 +08:00
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,
2017-07-26 16:25:34 +08:00
projectId: PropTypes.string,
2017-07-24 10:59:17 +08:00
deleteInterfaceData: PropTypes.func
2017-07-11 19:12:13 +08:00
}
constructor(props) {
super(props)
}
2017-07-26 17:22:12 +08:00
@autobind
confirm (interfaceId) {
this.deleteInterface(interfaceId)
message.success('删除成功!');
}
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) => {
2017-07-26 17:22:12 +08:00
// const deleteInterface = this.deleteInterface.bind(this, data._id)
const confirm = this.confirm.bind(this, data._id)
2017-07-11 19:12:13 +08:00
return (
<span>
2017-07-26 15:38:34 +08:00
<Link to={`/AddInterface/edit/${data._id}`}><span>编辑</span></Link>
<span className="ant-divider" />
<Link to={`/AddInterface/edit/${data._id}`}><span>测试</span></Link>
<span className="ant-divider" />
2017-07-26 17:22:12 +08:00
<Popconfirm title="是否删除接口!" onConfirm={confirm} okText="Yes" cancelText="No">
<a href="">删除</a>
</Popconfirm>
2017-07-11 19:12:13 +08:00
</span>
)
}
}]
const data = this.props.data;
return (
<section className="interface-table">
2017-07-26 15:38:34 +08:00
<Table bordered={true} columns={columns} dataSource={data} />
2017-07-11 19:12:13 +08:00
</section>
)
}
}
2017-07-12 14:18:17 +08:00
export default InterfaceTable