king
2022-10-28 0a9e69c47dd88f7f2b551ab5b0507d46cb5dc252
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { fromJS } from 'immutable'
import { message } from 'antd'
import { CopyOutlined } from '@ant-design/icons'
import './index.scss'
 
class CopyComponent extends Component {
  static propTpyes = {
    type: PropTypes.string,
    card: PropTypes.object
  }
 
  trigger = () => {
    const { card, type } = this.props
    let _val = fromJS(card).toJS()
    _val.copyType = type
 
    try {
      delete _val.$srcId
    
      let srcid = localStorage.getItem(window.location.href.split('#')[0] + 'srcId')
      if (srcid) {
        _val.$srcId = srcid
      }
 
      if (type === 'menucell') {
        _val.setting.type = 'linkmenu'
        _val.setting.linkMenuId = ''
        _val.setting.copyMenuId = ''
      } else if (_val.type === 'menubar' && _val.subtype === 'menubar') {
        let cell = _val.subMenus[0]
        _val.subMenus = []
 
        if (cell) {
          cell.setting.type = 'menu'
          cell.setting.linkMenuId = ''
          cell.setting.copyMenuId = ''
 
          _val.subMenus.push(cell)
        }
      } else if (['normaltable', 'editable', 'basetable'].includes(type)) {
        _val.action = _val.action.filter(item => !item.origin)
        _val.cols = _val.cols.filter(item => !item.origin)
        _val.search = _val.search.filter(item => !item.origin)
        delete _val.isNew
      }
 
      _val = window.btoa(window.encodeURIComponent(JSON.stringify(_val)))
    } 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 (
      <CopyOutlined title="复制" style={{color: '#26C281'}} onClick={this.trigger} />
    )
  }
}
 
export default CopyComponent