import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { is, fromJS } from 'immutable'
|
import { Popover, Button, Icon } from 'antd'
|
|
import PopSource from './popsource'
|
import './index.scss'
|
|
class CopyComponent extends Component {
|
static propTpyes = {
|
type: PropTypes.string,
|
placement: PropTypes.any,
|
onChange: PropTypes.func
|
}
|
|
state = {
|
url: this.props.value
|
}
|
|
UNSAFE_componentWillMount () {
|
|
}
|
|
shouldComponentUpdate (nextProps, nextState) {
|
return !is(fromJS(this.state), fromJS(nextState))
|
}
|
|
deleteUrl = () => {
|
this.setState({url: ''})
|
this.props.onChange('')
|
}
|
|
changePopover = (visible) => {
|
if (!visible && this.SourceWrap.state.url) {
|
this.setState({url: this.SourceWrap.state.url})
|
this.props.onChange(this.SourceWrap.state.url)
|
} else if (visible && this.SourceWrap) {
|
this.SourceWrap.init()
|
}
|
}
|
|
render () {
|
const { url } = this.state
|
const { type, placement } = this.props
|
let name = url ? url.slice(url.lastIndexOf('/') + 1) : ''
|
|
return (
|
<div className="mk-source-wrap">
|
{!url ? <Popover overlayClassName="mk-source-manage" placement={placement || 'top'} content={<PopSource type={type} ref={dom => { this.SourceWrap = dom }} />} trigger="click" onVisibleChange={this.changePopover}>
|
<Button icon="upload">点击添加</Button>
|
</Popover> : null}
|
{url ? <div className="mk-source-item-info">
|
<Icon type="paper-clip" />
|
<a target="_blank" rel="noopener noreferrer" href={url}>{name}</a>
|
<Icon title="删除文件" type="delete" onClick={this.deleteUrl}/>
|
</div> : null}
|
</div>
|
)
|
}
|
}
|
|
export default CopyComponent
|