yapi/client/containers/Group/ProjectList/ProjectList.js

134 lines
3.7 KiB
JavaScript
Raw Normal View History

2017-08-10 21:20:57 +08:00
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
2017-09-13 19:25:20 +08:00
import { Row, Col, Button, Tooltip } from 'antd';
import { Link } from 'react-router-dom';
import { addProject, fetchProjectList, delProject, changeUpdateModal } from '../../../reducer/modules/project';
2017-08-11 19:30:12 +08:00
import ProjectCard from '../../../components/ProjectCard/ProjectCard.js';
2017-08-17 23:00:32 +08:00
import ErrMsg from '../../../components/ErrMsg/ErrMsg.js';
2017-08-10 21:20:57 +08:00
import { autobind } from 'core-decorators';
2017-09-13 19:25:20 +08:00
import { setBreadcrumb } from '../../../reducer/modules/user';
2017-08-10 21:20:57 +08:00
import './ProjectList.scss'
2017-09-13 19:25:20 +08:00
@connect(
2017-08-10 21:20:57 +08:00
state => {
return {
projectList: state.project.projectList,
userInfo: state.project.userInfo,
tableLoading: state.project.tableLoading,
currGroup: state.group.currGroup,
currPage: state.project.currPage
}
},
{
fetchProjectList,
addProject,
delProject,
2017-08-28 17:49:22 +08:00
changeUpdateModal,
setBreadcrumb
2017-08-10 21:20:57 +08:00
}
)
class ProjectList extends Component {
constructor(props) {
super(props);
this.state = {
visible: false,
protocol: 'http:\/\/',
projectData: []
}
}
static propTypes = {
form: PropTypes.object,
fetchProjectList: PropTypes.func,
addProject: PropTypes.func,
delProject: PropTypes.func,
changeUpdateModal: PropTypes.func,
projectList: PropTypes.array,
userInfo: PropTypes.object,
tableLoading: PropTypes.bool,
currGroup: PropTypes.object,
2017-08-28 17:49:22 +08:00
setBreadcrumb: PropTypes.func,
2017-08-10 21:20:57 +08:00
currPage: PropTypes.number
}
// 取消修改
@autobind
handleCancel() {
this.props.form.resetFields();
this.setState({
visible: false
});
}
// 修改线上域名的协议类型 (http/https)
@autobind
protocolChange(value) {
this.setState({
protocol: value
})
}
2017-08-22 20:04:15 +08:00
// 获取 ProjectCard 组件的关注事件回调,收到后更新数据
@autobind
receiveRes() {
this.props.fetchProjectList(this.props.currGroup._id, this.props.currPage);
}
2017-08-10 21:20:57 +08:00
componentWillReceiveProps(nextProps) {
2017-09-13 19:25:20 +08:00
this.props.setBreadcrumb([{ name: '' + (nextProps.currGroup.group_name || '') }]);
2017-08-28 17:49:22 +08:00
2017-08-10 21:20:57 +08:00
// 切换分组
if (this.props.currGroup !== nextProps.currGroup) {
if (nextProps.currGroup._id) {
2017-08-17 22:19:58 +08:00
this.props.fetchProjectList(nextProps.currGroup._id, this.props.currPage)
2017-08-10 21:20:57 +08:00
}
}
// 切换项目列表
if (this.props.projectList !== nextProps.projectList) {
// console.log(nextProps.projectList);
const data = nextProps.projectList.map((item, index) => {
item.key = index;
return item;
});
this.setState({
projectData: data
});
}
}
render() {
2017-08-11 19:30:12 +08:00
const projectData = this.state.projectData;
2017-09-13 19:25:20 +08:00
return (
<div style={{ paddingTop: '20px' }} className="m-panel card-panel card-panel-s project-list" >
2017-09-13 17:09:06 +08:00
<Row className="project-list-header">
2017-09-13 19:25:20 +08:00
<Col span={16} style={{ textAlign: 'left' }}>
2017-09-13 17:09:06 +08:00
{this.props.currGroup.group_name}分组 {projectData.length} 个项目
</Col>
<Col>
2017-09-13 19:25:20 +08:00
<Tooltip title="您没有权限,请联系该分组组长或管理员">
{this.props.currGroup.role ?
<Button type="primary" ><Link to="/add-project">添加项目</Link></Button> :
<Button type="primary" disabled >添加项目</Button>}
</Tooltip>
2017-09-13 17:09:06 +08:00
</Col>
2017-09-13 19:25:20 +08:00
</Row>
2017-08-22 17:26:53 +08:00
<Row gutter={16}>
2017-08-17 12:09:08 +08:00
{projectData.length ? projectData.map((item, index) => {
2017-08-11 19:30:12 +08:00
return (
2017-09-15 17:20:30 +08:00
<Col span={6} key={index}>
2017-08-22 20:04:15 +08:00
<ProjectCard projectData={item} callbackResult={this.receiveRes} />
2017-08-11 19:30:12 +08:00
</Col>);
2017-09-13 19:25:20 +08:00
}) : <ErrMsg type="noProject" />}
2017-08-11 19:30:12 +08:00
</Row>
2017-08-10 21:20:57 +08:00
</div>
);
}
}
2017-08-11 17:47:25 +08:00
export default ProjectList;