Center.js 6.26 KB
Newer Older
ddcat1115's avatar
ddcat1115 committed
1 2
import React, { PureComponent } from 'react';
import { connect } from 'dva';
zinkey's avatar
zinkey committed
3 4
import Link from 'umi/link';
import router from 'umi/router';
ddcat1115's avatar
ddcat1115 committed
5
import { Card, Row, Col, Icon, Avatar, Tag, Divider, Spin, Input } from 'antd';
6
import GridContent from '@/components/PageHeaderWrapper/GridContent';
ddcat1115's avatar
ddcat1115 committed
7 8
import styles from './Center.less';

afc163's avatar
afc163 committed
9
export default
ๆ„š้“'s avatar
ๆ„š้“ committed
10
@connect(({ loading, user, project }) => ({
ddcat1115's avatar
ddcat1115 committed
11 12 13 14 15 16
  listLoading: loading.effects['list/fetch'],
  currentUser: user.currentUser,
  currentUserLoading: loading.effects['user/fetchCurrent'],
  project,
  projectLoading: loading.effects['project/fetchNotice'],
}))
afc163's avatar
afc163 committed
17
class Center extends PureComponent {
ddcat1115's avatar
ddcat1115 committed
18 19 20 21
  state = {
    newTags: [],
    inputVisible: false,
    inputValue: '',
jim's avatar
jim committed
22
  };
ddcat1115's avatar
ddcat1115 committed
23 24 25

  componentDidMount() {
    const { dispatch } = this.props;
้™ˆๅธ…'s avatar
้™ˆๅธ… committed
26
    dispatch({
ddcat1115's avatar
ddcat1115 committed
27 28 29 30 31 32 33 34 35 36 37 38 39
      type: 'user/fetchCurrent',
    });
    dispatch({
      type: 'list/fetch',
      payload: {
        count: 8,
      },
    });
    dispatch({
      type: 'project/fetchNotice',
    });
  }

jim's avatar
jim committed
40
  onTabChange = key => {
zinkey's avatar
zinkey committed
41
    const { match } = this.props;
ddcat1115's avatar
ddcat1115 committed
42 43
    switch (key) {
      case 'articles':
zinkey's avatar
zinkey committed
44
        router.push(`${match.url}/articles`);
ddcat1115's avatar
ddcat1115 committed
45 46
        break;
      case 'applications':
zinkey's avatar
zinkey committed
47
        router.push(`${match.url}/applications`);
ddcat1115's avatar
ddcat1115 committed
48 49
        break;
      case 'projects':
zinkey's avatar
zinkey committed
50
        router.push(`${match.url}/projects`);
ddcat1115's avatar
ddcat1115 committed
51 52 53 54
        break;
      default:
        break;
    }
jim's avatar
jim committed
55
  };
ddcat1115's avatar
ddcat1115 committed
56 57 58

  showInput = () => {
    this.setState({ inputVisible: true }, () => this.input.focus());
jim's avatar
jim committed
59
  };
ddcat1115's avatar
ddcat1115 committed
60

jim's avatar
jim committed
61
  saveInputRef = input => {
ddcat1115's avatar
ddcat1115 committed
62
    this.input = input;
jim's avatar
jim committed
63
  };
ddcat1115's avatar
ddcat1115 committed
64

jim's avatar
jim committed
65
  handleInputChange = e => {
ddcat1115's avatar
ddcat1115 committed
66
    this.setState({ inputValue: e.target.value });
jim's avatar
jim committed
67
  };
ddcat1115's avatar
ddcat1115 committed
68 69 70 71 72 73 74 75 76 77 78 79 80

  handleInputConfirm = () => {
    const { state } = this;
    const { inputValue } = state;
    let { newTags } = state;
    if (inputValue && newTags.filter(tag => tag.label === inputValue).length === 0) {
      newTags = [...newTags, { key: `new-${newTags.length}`, label: inputValue }];
    }
    this.setState({
      newTags,
      inputVisible: false,
      inputValue: '',
    });
jim's avatar
jim committed
81
  };
ddcat1115's avatar
ddcat1115 committed
82 83 84

  render() {
    const { newTags, inputVisible, inputValue } = this.state;
jim's avatar
jim committed
85 86 87 88 89 90 91 92
    const {
      listLoading,
      currentUser,
      currentUserLoading,
      project: { notice },
      projectLoading,
      match,
      location,
ๆ„š้“'s avatar
ๆ„š้“ committed
93
      children,
jim's avatar
jim committed
94
    } = this.props;
ddcat1115's avatar
ddcat1115 committed
95

jim's avatar
jim committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
    const operationTabList = [
      {
        key: 'articles',
        tab: (
          <span>
            ๆ–‡็ซ  <span style={{ fontSize: 14 }}>(8)</span>
          </span>
        ),
      },
      {
        key: 'applications',
        tab: (
          <span>
            ๅบ”็”จ <span style={{ fontSize: 14 }}>(8)</span>
          </span>
        ),
      },
      {
        key: 'projects',
        tab: (
          <span>
            ้กน็›ฎ <span style={{ fontSize: 14 }}>(8)</span>
          </span>
        ),
      },
    ];
ddcat1115's avatar
ddcat1115 committed
122 123

    return (
124
      <GridContent className={styles.userCenter}>
ddcat1115's avatar
ddcat1115 committed
125 126
        <Row gutter={24}>
          <Col lg={7} md={24}>
jim's avatar
jim committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
            <Card bordered={false} style={{ marginBottom: 24 }} loading={currentUserLoading}>
              {currentUser && Object.keys(currentUser).length ? (
                <div>
                  <div className={styles.avatarHolder}>
                    <img alt="" src={currentUser.avatar} />
                    <div className={styles.name}>{currentUser.name}</div>
                    <div>{currentUser.signature}</div>
                  </div>
                  <div className={styles.detail}>
                    <p>
                      <i className={styles.title} />
                      {currentUser.title}
                    </p>
                    <p>
                      <i className={styles.group} />
                      {currentUser.group}
                    </p>
                    <p>
                      <i className={styles.address} />
                      {currentUser.geographic.province.label}
                      {currentUser.geographic.city.label}
                    </p>
                  </div>
                  <Divider dashed />
                  <div className={styles.tags}>
                    <div className={styles.tagsTitle}>ๆ ‡็ญพ</div>
153 154 155
                    {currentUser.tags.concat(newTags).map(item => (
                      <Tag key={item.key}>{item.label}</Tag>
                    ))}
jim's avatar
jim committed
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
                    {inputVisible && (
                      <Input
                        ref={this.saveInputRef}
                        type="text"
                        size="small"
                        style={{ width: 78 }}
                        value={inputValue}
                        onChange={this.handleInputChange}
                        onBlur={this.handleInputConfirm}
                        onPressEnter={this.handleInputConfirm}
                      />
                    )}
                    {!inputVisible && (
                      <Tag
                        onClick={this.showInput}
                        style={{ background: '#fff', borderStyle: 'dashed' }}
                      >
                        <Icon type="plus" />
                      </Tag>
                    )}
                  </div>
                  <Divider style={{ marginTop: 16 }} dashed />
                  <div className={styles.team}>
                    <div className={styles.teamTitle}>ๅ›ข้˜Ÿ</div>
                    <Spin spinning={projectLoading}>
                      <Row gutter={36}>
                        {notice.map(item => (
                          <Col key={item.id} lg={24} xl={12}>
                            <Link to={item.href}>
                              <Avatar size="small" src={item.logo} />
                              {item.member}
                            </Link>
                          </Col>
                        ))}
                      </Row>
                    </Spin>
                  </div>
                </div>
              ) : (
                'loading...'
              )}
ddcat1115's avatar
ddcat1115 committed
197 198 199 200 201 202 203 204 205 206 207
            </Card>
          </Col>
          <Col lg={17} md={24}>
            <Card
              className={styles.tabsCard}
              bordered={false}
              tabList={operationTabList}
              activeTabKey={location.pathname.replace(`${match.path}/`, '')}
              onTabChange={this.onTabChange}
              loading={listLoading}
            >
ๆ„š้“'s avatar
ๆ„š้“ committed
208
              {children}
ddcat1115's avatar
ddcat1115 committed
209 210 211
            </Card>
          </Col>
        </Row>
212
      </GridContent>
ddcat1115's avatar
ddcat1115 committed
213 214 215
    );
  }
}