king
2020-04-05 ecfc80755984fcb4c670c2208282ee93ee8bd1a4
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Button} from 'antd'
import './index.scss'
 
class Preview extends Component {
  static propTpyes = {
    preview: PropTypes.any,
    cancel: PropTypes.func
  }
 
  state = {
    show: false,
    url: ''
  }
 
  UNSAFE_componentWillReceiveProps (nextProps) {
    if (nextProps.preview) {
      this.setState({
        url: nextProps.preview
      })
      setTimeout(() => {
        this.setState({
          show: true
        })
      }, 10)
    } else {
      this.setState({
        show: false
      })
      setTimeout(() => {
        this.setState({
          url: ''
        })
      }, 500)
    }
  }
 
  close = () => {
    this.props.cancel()
  }
 
  render () {
    return (
      <div>
        {this.state.url &&
          <div className={'preview-box ' + (this.state.show ? 'active' : '')} onClick={this.close}>
            <Button shape="circle" icon="close" />
            {this.state.url && <img src={this.state.url} alt=""/>}
          </div>
        }
      </div>
    )
  }
}
 
export default Preview