king
2021-05-24 f267d04e0561a0a20d1f2a9f558a273558ece90d
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Icon } from 'antd'
 
import './index.scss'
 
class ImgScale extends Component {
  static propTpyes = {
    data: PropTypes.object
  }
 
  state = {
    list: [],
    index: 0
  }
 
  UNSAFE_componentWillMount() {
    const { data } = this.props
 
    this.setState({
      list: data.list || [],
      index: data.index || 0
    })
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  /**
   * @description 组件销毁,清除state更新
   */
  componentWillUnmount () {
    this.setState = () => {
      return
    }
  }
 
  reduce = () => {
    const { index } = this.state
 
    this.setState({index: index - 1})
  }
 
  plus = () => {
    const { index } = this.state
 
    this.setState({index: index + 1})
  }
 
  render() {
    const { list, index } = this.state
 
    return (
      <div className="img-scale-wrap">
        <img src={list[index]} alt="" />
        {index > 0 ? <Icon type="left" onClick={this.reduce} /> : null}
        {index < list.length -1 ? <Icon type="right" onClick={this.plus} /> : null}
      </div>
    )
  }
}
 
export default ImgScale