forked from nsjcy/frontEnd/nsjcy

liuwh
2020-06-09 69155bb24070e22789fceb34d14fe3311874126f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import React from 'react';
 
import { Layout, Card, Button, Icon } from 'antd';
import AttachmentDisplay from '../view/AttachmentDisplay';
 
export default class Index extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      degree: 0
    };
  }
  rotate = degree => {
    this.setState({ degree: (degree + 360) % 360 });
  }
  componentWillReceiveProps(props) {
    try {
      if (props.location.state.path
        !== this.props.location.state.path) {
        this.setState({ degree: 0 });
 
      }
    } catch (e) { }
  }
  download = () => {
    // 接口
  }
 
  render() {
    if (!this.props.location.state) {
      return null;
    }
    const { degree } = this.state;
    const { path, type, name } = this.props.location.state;
    if (type === 'online') {
      return (
        <iframe src={path} style={{
          width: '100%',
          height: '100%',
          border: 'none',
          overflow: 'auto'
        }}
        />
      );
    }
    if (type === 'offline') {
      return (
        <Card style={{ margin: '8px', textAlign: 'center', width: '100%' }} hoverable bordered>
          <a href={path} title={`下载${name || ''}`} className="ant-btn ant-btn-primary ant-btn-lg">下载</a>
        </Card>
      );
    }
    return (
      <Layout className="h-100" style={{ overflow: 'auto' }}>
        <div>
          <div style={{ padding: '16px', zIndex: '1', backgroundColor: 'white' }}>
            <Button type="primary" onClick={() => this.rotate(degree - 90)}>
              <Icon type="left" />旋转
            </Button>
            {' '}
            <Button type="primary" onClick={() => this.rotate(degree + 90)}>
              旋转<Icon type="right" />
            </Button>
              {/*{' '}
            <Button type="primary" onClick={this.download}>
              一键下载
            </Button>*/}
          </div>
        </div>
        <AttachmentDisplay key={path} path={path} degree={degree} />
      </Layout>
    );
  }
}