king
2021-01-29 d62c168d0656fac4242581609c3c5c0d88cf6a48
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
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