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

108 lines
2.4 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'
2017-08-08 10:07:55 +08:00
import { deleteInterfaceData } from '../../../reducer/modules/interface.js'
2017-07-24 10:59:17 +08:00
@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('/api/interface/del', params)
2017-07-24 10:59:17 +08:00
.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-26 18:24:51 +08:00
},{
2017-07-11 19:12:13 +08:00
title: '接口URL',
2017-07-24 10:59:17 +08:00
dataIndex: 'path',
key: 'path'
},{
2017-07-26 18:24:51 +08:00
title: '请求方式',
dataIndex: 'method',
key: 'method'
},{
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 confirm = this.confirm.bind(this, data._id)
2017-07-11 19:12:13 +08:00
return (
<span>
2017-07-28 17:30:56 +08:00
<Link to={`/add-interface/edit/${data._id}`}><span>编辑</span></Link>
2017-07-26 15:38:34 +08:00
<span className="ant-divider" />
2017-07-31 13:59:18 +08:00
<Popconfirm title="你确定要删除接口吗!" onConfirm={confirm} okText="Yes" cancelText="No">
2017-07-26 17:22:12 +08:00
<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