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
|