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 = ''
|
}
|
|
_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
|