king
2021-09-01 31ec63f0419895876cbaba99637a884a32d33d0d
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { Icon, message } from 'antd'
import './index.scss'
 
class CopyComponent extends Component {
  static propTpyes = {
    btnlog: PropTypes.array,
    handlelog: PropTypes.func
  }
 
  trigger = () => {
    const { card, type } = this.props
    let copycard = fromJS(card).toJS()
    copycard.copyType = type
 
    let _val = ''
 
    try {
      _val = window.btoa(window.encodeURIComponent(JSON.stringify(copycard)))
    } catch (e) {
      message.warning('复制失败,请重试!')
      _val = ''
    }
 
    if (_val) {
      let oInput = document.createElement('input')
      oInput.value = _val
      document.body.appendChild(oInput)
      oInput.select()
      document.execCommand('Copy')
      document.body.removeChild(oInput)
 
      message.success('复制成功。')
    }
  }
 
  render () {
    return (
      <Icon type="copy" title="复制" style={{color: '#26C281'}} onClick={this.trigger} />
    )
  }
}
 
export default CopyComponent