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
|
}
|
|
transConfig = (config, type) => {
|
if (type === 'menucell') {
|
config.setting.type = 'linkmenu'
|
config.setting.linkMenuId = ''
|
config.setting.copyMenuId = ''
|
} else if (type === 'mobnavbar') {
|
delete config.open_edition
|
delete config.dataName
|
|
config.menus.forEach(item => {
|
item.property = 'menu'
|
item.open = 'self'
|
|
delete item.copyMenuId
|
delete item.clearMenu
|
delete item.linkMenuId
|
})
|
} else if (config.type === 'menubar' && config.subtype === 'menubar') {
|
let cell = config.subMenus[0]
|
config.subMenus = []
|
|
if (cell) {
|
cell.setting.type = 'menu'
|
cell.setting.linkMenuId = ''
|
cell.setting.copyMenuId = ''
|
|
config.subMenus.push(cell)
|
}
|
} else if (['normaltable', 'editable', 'basetable'].includes(type)) {
|
config.action = config.action.filter(item => !item.origin)
|
config.cols = config.cols.filter(item => !item.origin)
|
config.search = config.search.filter(item => !item.origin)
|
delete config.isNew
|
}
|
}
|
|
trigger = () => {
|
const { card, type } = this.props
|
let _val = fromJS(card).toJS()
|
_val.copyType = type
|
|
this.transConfig(_val, type)
|
|
try {
|
_val = window.btoa(window.encodeURIComponent(JSON.stringify(_val)))
|
} catch (e) {
|
console.warn(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
|