king
2024-04-29 50b49c1b760489c3430fc382656d57c5fbbab07c
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
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.warning({
            top: 92,
            message: result.message,
            duration: 5
          })
        }
      })
    })
  }
 
  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