king
2022-10-26 fb64bcf1fab18b33d21470c83f28d4cda8d309ce
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Modal, notification, Button } from 'antd'
import { SnippetsOutlined } from '@ant-design/icons'
 
import Utils from '@/utils/utils.js'
import asyncComponent from '@/utils/asyncComponent'
// import './index.scss'
 
const PasteForm = asyncComponent(() => import('@/templates/zshare/pasteform'))
 
class PasteBaseTable extends Component {
  static propTpyes = {
    type: PropTypes.any,
    insert: PropTypes.func
  }
 
  state = {
    visible: false
  }
 
  handleMenuClick = () => {
    this.setState({visible: true})
  }
 
  pasteSubmit = () => {
    this.pasteFormRef.handleConfirm().then(res => {
      if (res.copyType !== 'basetable') {
        notification.warning({
          top: 92,
          message: '配置信息格式错误!',
          duration: 5
        })
        return
      }
 
      delete res.copyType
 
      res.uuid = Utils.getuuid()
 
      res.search = res.search.map(cell => {
        cell.uuid = Utils.getuuid()
        return cell
      })
 
      let loopCol = (col) => {
        col.subcols = col.subcols.map(c => {
          c.uuid = Utils.getuuid()
 
          if (c.type === 'colspan' && c.subcols) {
            c = loopCol(c)
          } else if (c.type === 'custom' && c.elements) {
            c.elements = c.elements.map(cell => {
              cell.uuid = Utils.getuuid()
              return cell
            })
          }
          return c
        })
 
        return col
      }
 
      res.cols = res.cols.map(col => {
        col.uuid = Utils.getuuid()
 
        if (col.type === 'colspan' && col.subcols) {
          col = loopCol(col)
        } else if (col.type === 'custom' && col.elements) {
          col.elements = col.elements.map(cell => {
            cell.uuid = Utils.getuuid()
            return cell
          })
        } else if (col.type === 'action' && col.elements) {
          col.elements = col.elements.map(cell => {
            cell.uuid = Utils.getuuid()
            return cell
          })
        }
        return col
      })
 
      let oriUids = {}
      res.action = res.action.map(cell => {
        let _uuid = Utils.getuuid()
 
        oriUids[cell.uuid] = _uuid
 
        cell.uuid = _uuid
 
        return cell
      })
 
      res.setting.supModule = ''
 
      if (res.wrap && res.wrap.doubleClick) {
        res.wrap.doubleClick = oriUids[res.wrap.doubleClick] || ''
      }
      
      this.props.insert(res)
 
      this.setState({visible: false})
 
      notification.success({
        top: 92,
        message: '粘贴成功!',
        duration: 2
      })
    })
  }
 
  render() {
    const { type } = this.props
    const { visible } = this.state
 
    return (
      <div style={{display: 'inline-block'}}>
        {type === 'page' ? <Button icon="snippets" style={{color: '#1890ff', borderColor: '#1890ff'}} onClick={() => {this.setState({visible: true})}} >粘贴</Button> : <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 PasteBaseTable