mock平台

ProjectList.js 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import React, { PureComponent as Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { connect } from 'react-redux';
  4. import { Row, Col, Button, Tooltip } from 'antd';
  5. import { Link } from 'react-router-dom';
  6. import {
  7. addProject,
  8. fetchProjectList,
  9. delProject,
  10. changeUpdateModal
  11. } from '../../../reducer/modules/project';
  12. import ProjectCard from '../../../components/ProjectCard/ProjectCard.js';
  13. import ErrMsg from '../../../components/ErrMsg/ErrMsg.js';
  14. import { autobind } from 'core-decorators';
  15. import { setBreadcrumb } from '../../../reducer/modules/user';
  16. import './ProjectList.scss';
  17. @connect(
  18. state => {
  19. return {
  20. projectList: state.project.projectList,
  21. userInfo: state.project.userInfo,
  22. tableLoading: state.project.tableLoading,
  23. currGroup: state.group.currGroup,
  24. currPage: state.project.currPage
  25. };
  26. },
  27. {
  28. fetchProjectList,
  29. addProject,
  30. delProject,
  31. changeUpdateModal,
  32. setBreadcrumb
  33. }
  34. )
  35. class ProjectList extends Component {
  36. constructor(props) {
  37. super(props);
  38. this.state = {
  39. visible: false,
  40. protocol: 'http://',
  41. projectData: []
  42. };
  43. }
  44. static propTypes = {
  45. form: PropTypes.object,
  46. fetchProjectList: PropTypes.func,
  47. addProject: PropTypes.func,
  48. delProject: PropTypes.func,
  49. changeUpdateModal: PropTypes.func,
  50. projectList: PropTypes.array,
  51. userInfo: PropTypes.object,
  52. tableLoading: PropTypes.bool,
  53. currGroup: PropTypes.object,
  54. setBreadcrumb: PropTypes.func,
  55. currPage: PropTypes.number,
  56. studyTip: PropTypes.number,
  57. study: PropTypes.bool
  58. };
  59. // 取消修改
  60. @autobind
  61. handleCancel() {
  62. this.props.form.resetFields();
  63. this.setState({
  64. visible: false
  65. });
  66. }
  67. // 修改线上域名的协议类型 (http/https)
  68. @autobind
  69. protocolChange(value) {
  70. this.setState({
  71. protocol: value
  72. });
  73. }
  74. // 获取 ProjectCard 组件的关注事件回调,收到后更新数据
  75. receiveRes = () => {
  76. this.props.fetchProjectList(this.props.currGroup._id, this.props.currPage);
  77. };
  78. componentWillReceiveProps(nextProps) {
  79. this.props.setBreadcrumb([{ name: '' + (nextProps.currGroup.group_name || '') }]);
  80. // 切换分组
  81. if (this.props.currGroup !== nextProps.currGroup && nextProps.currGroup._id) {
  82. this.props.fetchProjectList(nextProps.currGroup._id, this.props.currPage);
  83. }
  84. // 切换项目列表
  85. if (this.props.projectList !== nextProps.projectList) {
  86. // console.log(nextProps.projectList);
  87. const data = nextProps.projectList.map((item, index) => {
  88. item.key = index;
  89. return item;
  90. });
  91. this.setState({
  92. projectData: data
  93. });
  94. }
  95. }
  96. render() {
  97. let projectData = this.state.projectData;
  98. let noFollow = [];
  99. let followProject = [];
  100. for (var i in projectData) {
  101. if (projectData[i].follow) {
  102. followProject.push(projectData[i]);
  103. } else {
  104. noFollow.push(projectData[i]);
  105. }
  106. }
  107. followProject = followProject.sort((a, b) => {
  108. return b.up_time - a.up_time;
  109. });
  110. noFollow = noFollow.sort((a, b) => {
  111. return b.up_time - a.up_time;
  112. });
  113. projectData = [...followProject, ...noFollow];
  114. const isShow = /(admin)|(owner)|(dev)/.test(this.props.currGroup.role);
  115. const Follow = () => {
  116. return followProject.length ? (
  117. <Row>
  118. <h3 className="owner-type">我的关注</h3>
  119. {followProject.map((item, index) => {
  120. return (
  121. <Col xs={8} lg={6} xxl={4} key={index}>
  122. <ProjectCard projectData={item} callbackResult={this.receiveRes} />
  123. </Col>
  124. );
  125. })}
  126. </Row>
  127. ) : null;
  128. };
  129. const NoFollow = () => {
  130. return noFollow.length ? (
  131. <Row style={{ borderBottom: '1px solid #eee', marginBottom: '15px' }}>
  132. <h3 className="owner-type">我的项目</h3>
  133. {noFollow.map((item, index) => {
  134. return (
  135. <Col xs={8} lg={6} xxl={4} key={index}>
  136. <ProjectCard projectData={item} callbackResult={this.receiveRes} isShow={isShow} />
  137. </Col>
  138. );
  139. })}
  140. </Row>
  141. ) : null;
  142. };
  143. const OwnerSpace = () => {
  144. return projectData.length ? (
  145. <div>
  146. <NoFollow />
  147. <Follow />
  148. </div>
  149. ) : (
  150. <ErrMsg type="noProject" />
  151. );
  152. };
  153. return (
  154. <div style={{ paddingTop: '24px' }} className="m-panel card-panel card-panel-s project-list">
  155. <Row className="project-list-header">
  156. <Col span={16} style={{ textAlign: 'left' }}>
  157. {this.props.currGroup.group_name} 分组共 ({projectData.length}) 个项目
  158. </Col>
  159. <Col span={8}>
  160. {isShow ? (
  161. <Link to="/add-project">
  162. <Button type="primary">添加项目</Button>
  163. </Link>
  164. ) : (
  165. <Tooltip title="您没有权限,请联系该分组组长或管理员">
  166. <Button type="primary" disabled>
  167. 添加项目
  168. </Button>
  169. </Tooltip>
  170. )}
  171. </Col>
  172. </Row>
  173. <Row>
  174. {/* {projectData.length ? projectData.map((item, index) => {
  175. return (
  176. <Col xs={8} md={6} xl={4} key={index}>
  177. <ProjectCard projectData={item} callbackResult={this.receiveRes} />
  178. </Col>);
  179. }) : <ErrMsg type="noProject" />} */}
  180. {this.props.currGroup.type === 'private' ? (
  181. <OwnerSpace />
  182. ) : projectData.length ? (
  183. projectData.map((item, index) => {
  184. return (
  185. <Col xs={8} lg={6} xxl={4} key={index}>
  186. <ProjectCard
  187. projectData={item}
  188. callbackResult={this.receiveRes}
  189. isShow={isShow}
  190. />
  191. </Col>
  192. );
  193. })
  194. ) : (
  195. <ErrMsg type="noProject" />
  196. )}
  197. </Row>
  198. </div>
  199. );
  200. }
  201. }
  202. export default ProjectList;