king
2021-07-27 4d08cb2fa0daad4b7593a2b8282466b000194344
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { is, fromJS } from 'immutable'
import { Radio, Icon, Modal } from 'antd'
 
import InputForm from './inputform'
import './index.scss'
 
class CopyComponent extends Component {
  static propTpyes = {
    type: PropTypes.string,
    placement: PropTypes.any,
    onChange: PropTypes.func
  }
 
  state = {
    url: '',
    visible: ''
  }
 
  UNSAFE_componentWillMount () {
    const { value } = this.props
    let val = ''
 
    if (value) {
      val = value
    } else if (this.props['data-__meta']) {
      val = this.props['data-__meta'].initialValue || ''
    }
 
    this.setState({
      url: val,
    })
  }
 
  shouldComponentUpdate (nextProps, nextState) {
    return !is(fromJS(this.state), fromJS(nextState))
  }
 
  deleteUrl = () => {
    this.setState({url: ''})
    this.props.onChange('')
  }
 
  handleChange = (key) => {
    this.setState({visible: key})
  }
 
  popSubmit = () => {
    let url = ''
    if (this.inputWrap && this.inputWrap.state.url) {
      url = this.inputWrap.state.url
    }
 
    this.setState({visible: '', url})
    this.props.onChange(url)
  }
 
  render () {
    const { url, visible } = this.state
    const { type } = this.props
    let name = url ? url.slice(url.lastIndexOf('/') + 1) : ''
 
    return (
      <div className="mk-source-wrap">
        {!url ? <Radio.Group>
          <Radio.Button value="input" size="small" onClick={() => this.handleChange('input')}>输入</Radio.Button>
          <Radio.Button value="upload" size="small" onClick={() => this.handleChange('upload')}>上传</Radio.Button>
          <Radio.Button value="system" size="small" onClick={() => this.handleChange('system')}>系统</Radio.Button>
        </Radio.Group> : 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}
        <Modal
          visible={!!visible}
          width={visible !== 'system' ? 600 : 1000}
          closable={false}
          maskClosable={false}
          okText="确定"
          cancelText="取消"
          onOk={this.popSubmit}
          onCancel={() => {this.setState({visible: ''})}}
          destroyOnClose
        >
          <InputForm type={type === 'picture' ? 'image' : type} keyword={visible} ref={dom => { this.inputWrap = dom }} />
        </Modal>
      </div>
    )
  }
}
 
export default CopyComponent