import React, {Component} from 'react'
|
import PropTypes from 'prop-types'
|
import { Modal, notification } from 'antd'
|
import { SnippetsOutlined } from '@ant-design/icons'
|
|
import asyncComponent from '@/utils/asyncComponent'
|
|
const PasteForm = asyncComponent(() => import('@/templates/zshare/pasteform'))
|
|
class PasteController extends Component {
|
static propTpyes = {
|
options: PropTypes.array,
|
updateConfig: PropTypes.func
|
}
|
|
state = {
|
visible: false
|
}
|
|
pasteSubmit = () => {
|
const { options } = this.props
|
this.pasteFormRef.handleConfirm().then(res => {
|
if (!options.includes(res.copyType)) {
|
notification.warning({ top: 92, message: '配置信息格式错误!', duration: 5 })
|
return
|
}
|
this.props.updateConfig(res, (result) => {
|
if (result.status) {
|
notification.success({
|
top: 92,
|
message: '粘贴成功!',
|
duration: 2
|
})
|
this.setState({visible: false})
|
} else {
|
notification.success({
|
top: 92,
|
message: result.message,
|
duration: 2
|
})
|
}
|
})
|
})
|
}
|
|
render() {
|
const { visible } = this.state
|
|
return (
|
<div style={{display: 'inline-block'}}>
|
<SnippetsOutlined style={{color: 'purple'}} onClick={() => {this.setState({visible: true})}} />
|
<Modal
|
title="粘贴"
|
visible={visible}
|
width={600}
|
maskClosable={false}
|
onOk={this.pasteSubmit}
|
onCancel={() => {this.setState({visible: false})}}
|
destroyOnClose
|
>
|
<PasteForm wrappedComponentRef={(inst) => this.pasteFormRef = inst} inputSubmit={this.pasteSubmit}/>
|
</Modal>
|
</div>
|
)
|
}
|
}
|
|
export default PasteController
|