mock平台

Group.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import React, { PureComponent as Component } from 'react';
  2. import GroupList from './GroupList/GroupList.js';
  3. import ProjectList from './ProjectList/ProjectList.js';
  4. import MemberList from './MemberList/MemberList.js';
  5. import GroupLog from './GroupLog/GroupLog.js';
  6. import GroupSetting from './GroupSetting/GroupSetting.js';
  7. import PropTypes from 'prop-types';
  8. import { connect } from 'react-redux';
  9. import { Route, Switch, Redirect } from 'react-router-dom';
  10. import { Tabs, Layout, Spin } from 'antd';
  11. const { Content, Sider } = Layout;
  12. const TabPane = Tabs.TabPane;
  13. import { fetchNewsData } from '../../reducer/modules/news.js';
  14. import {
  15. setCurrGroup
  16. } from '../../reducer/modules/group';
  17. import './Group.scss';
  18. import axios from 'axios'
  19. @connect(
  20. state => {
  21. return {
  22. curGroupId: state.group.currGroup._id,
  23. curUserRole: state.user.role,
  24. curUserRoleInGroup: state.group.currGroup.role || state.group.role,
  25. currGroup: state.group.currGroup
  26. };
  27. },
  28. {
  29. fetchNewsData: fetchNewsData,
  30. setCurrGroup
  31. }
  32. )
  33. export default class Group extends Component {
  34. constructor(props) {
  35. super(props);
  36. this.state = {
  37. groupId: -1
  38. }
  39. }
  40. async componentDidMount(){
  41. let r = await axios.get('/api/group/get_mygroup')
  42. try{
  43. let group = r.data.data;
  44. this.setState({
  45. groupId: group._id
  46. })
  47. this.props.setCurrGroup(group)
  48. }catch(e){
  49. console.error(e)
  50. }
  51. }
  52. static propTypes = {
  53. fetchNewsData: PropTypes.func,
  54. curGroupId: PropTypes.number,
  55. curUserRole: PropTypes.string,
  56. currGroup: PropTypes.object,
  57. curUserRoleInGroup: PropTypes.string,
  58. setCurrGroup: PropTypes.func
  59. };
  60. // onTabClick=(key)=> {
  61. // // if (key == 3) {
  62. // // this.props.fetchNewsData(this.props.curGroupId, "group", 1, 10)
  63. // // }
  64. // }
  65. render() {
  66. if(this.state.groupId === -1)return <Spin />
  67. const GroupContent = (
  68. <Layout style={{ minHeight: 'calc(100vh - 100px)', marginLeft: '24px', marginTop: '24px' }}>
  69. <Sider style={{ height: '100%' }} width={300}>
  70. <div className="logo" />
  71. <GroupList />
  72. </Sider>
  73. <Layout>
  74. <Content
  75. style={{
  76. height: '100%',
  77. margin: '0 24px 0 16px',
  78. overflow: 'initial',
  79. backgroundColor: '#fff'
  80. }}
  81. >
  82. <Tabs type="card" className="m-tab tabs-large" style={{ height: '100%' }}>
  83. <TabPane tab="项目列表" key="1">
  84. <ProjectList />
  85. </TabPane>
  86. {this.props.currGroup.type === 'public' ? (
  87. <TabPane tab="成员列表" key="2">
  88. <MemberList />
  89. </TabPane>
  90. ) : null}
  91. {['admin', 'owner', 'guest', 'dev'].indexOf(this.props.curUserRoleInGroup) > -1 ||
  92. this.props.curUserRole === 'admin' ? (
  93. <TabPane tab="分组动态" key="3">
  94. <GroupLog />
  95. </TabPane>
  96. ) : (
  97. ''
  98. )}
  99. {(this.props.curUserRole === 'admin' || this.props.curUserRoleInGroup === 'owner') &&
  100. this.props.currGroup.type !== 'private' ? (
  101. <TabPane tab="分组设置" key="4">
  102. <GroupSetting />
  103. </TabPane>
  104. ) : null}
  105. </Tabs>
  106. </Content>
  107. </Layout>
  108. </Layout>
  109. );
  110. return (
  111. <div className="projectGround">
  112. <Switch>
  113. <Redirect exact from="/group" to={"/group/" + this.state.groupId} />
  114. <Route path="/group/:groupId" render={() => GroupContent} />
  115. </Switch>
  116. </div>
  117. );
  118. }
  119. }