import React, { Component } from 'react'; import { Image } from 'antd'; import './ShowImage.less'; import FullScreen from '../../../assets/quanping.svg'; export default class ShowImg extends Component { constructor(props) { super(props); this.state = { f: this.props.firstIndex, R: 0, S: 1, i: 0, SS: 1, data: this.props.data, fullScreen: false, // eslint-disable-next-line react/no-unused-state showimgs: this.props.showimgs, maxNum: this.props.data !== undefined ? this.props.data.length - 1 : 0, imgVisible: false, }; } componentDidMount() { } componentWillReceiveProps(props) { this.setState({ f: props.firstIndex }); } // 向左预览 leftshow = () => { const { maxNum } = this.state; if (this.state.f === 0) { this.setState({ f: maxNum, R: 0, S: 1, i: 0, SS: 1, }); } else { this.setState({ f: this.state.f - 1, R: 0, S: 1, i: 0, SS: 1, }); } // eslint-disable-next-line react/no-string-refs this.refs.imgstyle.setAttribute('src', this.props.data[this.state.f]); } // 向右预览 rightshow = () => { const { maxNum } = this.state; if (this.state.f === maxNum) { this.setState({ f: 0, R: 0, S: 1, i: 0, SS: 1, }); } else { this.setState({ f: this.state.f + 1, R: 0, S: 1, i: 0, SS: 1, }); } // eslint-disable-next-line react/no-string-refs this.refs.imgstyle.setAttribute('src', this.props.data[this.state.f]); } // 顺时针旋转 rotateright = () => { this.setState({ R: this.state.R + 90 }); // eslint-disable-next-line react/no-string-refs this.refs.imgstyle.style.transform = `rotate(${this.state.R}deg) scale(${this.state.SS},${this.state.SS})`; } // 逆时针旋转 rotateleft = () => { this.setState({ R: this.state.R - 90 }); // eslint-disable-next-line react/no-string-refs this.refs.imgstyle.style.transform = `rotate(${this.state.R}deg) scale(${this.state.SS},${this.state.SS})`; } // 放大 showbig = () => { if (this.state.i >= 0) { this.setState({ S: this.state.S + 1, i: this.state.i + 1, SS: 1 * (this.state.S + 0.1) }); } else { this.setState({ S: this.state.S - 1, i: this.state.i + 1, SS: 1 / (this.state.S - 1) }); } // eslint-disable-next-line react/no-string-refs this.refs.imgstyle.style.transform = `rotate(${this.state.R}deg) scale(${this.state.SS},${this.state.SS})`; } // 缩小 showmin = () => { if (this.state.i <= 0) { this.setState({ S: this.state.S + 1, i: this.state.i - 1, SS: 1 / (this.state.S + 1) }); } else { this.setState({ S: this.state.S - 1, i: this.state.i - 1, SS: 1 * (this.state.S - 1) }); } // eslint-disable-next-line react/no-string-refs this.refs.imgstyle.style.transform = `rotate(${this.state.R}deg) scale(${this.state.SS},${this.state.SS})`; } // 全屏 fullScreen = () => { this.setState({ imgVisible: true, }); // this.setState({ fullScreen: !this.state.fullScreen }); } render() { const { toggleshow, showimgs, imgOffsetWidth, imgOffsetHeight, bFullScreen, } = this.props; const { data, f, R, SS, fullScreen, } = this.state; const bigWidth = imgOffsetWidth !== undefined && imgOffsetWidth !== null ? imgOffsetWidth : '950'; const bigHeight = imgOffsetHeight !== undefined && imgOffsetHeight !== null ? imgOffsetHeight : '600'; return (
{ showimgs ?
预览图片
{/* eslint-disable-next-line react/no-string-refs */} 无图片 { this.setState({ imgVisible: value, }); }, }} />
: null }
); } }