import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Button } from 'antd'
|
import { CloseOutlined } from '@ant-design/icons'
|
import './index.scss'
|
|
class Preview extends Component {
|
static propTpyes = {
|
preview: PropTypes.any,
|
cancel: PropTypes.func,
|
confirm: PropTypes.func,
|
template: PropTypes.object
|
}
|
|
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 () {
|
const { template } = this.props
|
let type = 'sys'
|
if (!template || !template.isSystem) {
|
type = 'user'
|
}
|
|
return (
|
<div>
|
{this.state.url && this.props.template &&
|
<div className={'preview-box ' + (this.state.show ? 'active' : '')} onClick={this.close}>
|
<Button shape="circle"><CloseOutlined /></Button>
|
<Button type="primary" onClick={() => {this.props.confirm(this.props.template, type)}}>使用模板</Button>
|
{this.state.url && <img src={this.state.url} alt=""/>}
|
</div>
|
}
|
</div>
|
)
|
}
|
}
|
|
export default Preview
|