king
2025-05-13 1a176e4bdba485301385caac1a29102e598d25cc
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
75
76
77
78
79
80
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Button, Modal, notification } from 'antd'
 
import asyncComponent from '@/utils/asyncComponent'
// import './index.scss'
 
const PasteForm = asyncComponent(() => import('@/templates/zshare/pasteform'))
 
class PasteController extends Component {
  static propTpyes = {
    config: PropTypes.object,        // 组件配置
    updateConfig: PropTypes.func
  }
 
  state = {
    visible: false
  }
 
  pasteSubmit = () => {
    const { config } = this.props
    this.pasteFormRef.handleConfirm().then(res => {
      if (res.copyType === 'forms') {
        this.props.updateConfig(res, 'forms')
        this.setState({visible: false})
        return
      } else if (res.copyType !== 'form') {
        notification.warning({ top: 92, message: '配置信息格式错误!', duration: 5 })
        return
      }
 
      let keys = config.fields.map(item => item.field ? item.field.toLowerCase() : '$emp_ty$')
 
      if (['multiselect', 'color', 'brafteditor'].includes(res.type)) {
        res.type = 'text'
      }
 
      if (res.field && keys.includes(res.field.toLowerCase())) {
        notification.warning({
          top: 92,
          message: '字段已存在!',
          duration: 5
        })
        return
      }
 
      this.props.updateConfig({...config, fields: [...config.fields, res]})
      this.setState({visible: false})
 
      notification.success({
        top: 92,
        message: '粘贴成功!',
        duration: 2
      })
    })
  }
 
  render() {
    const { visible } = this.state
 
    return (
      <div style={{display: 'inline-block'}}>
        <Button icon="snippets" style={{color: 'purple'}} onClick={() => {this.setState({visible: true})}} >粘贴</Button>
        <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