king
2024-12-30 81a5ae579e84d7cfe0cda268d4156d4b78a27454
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
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 MenuUtils from '@/utils/utils-custom.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
  }
 
  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 = (cols) => {
        return cols.map(col => {
          col.uuid = Utils.getuuid()
          
          if (col.type === 'action') {
            col.type = 'custom'
          }
 
          if (col.type === 'colspan' && col.subcols) {
            col.subcols = loopCol(col.subcols)
          } else if (col.type === 'custom' && col.elements) {
            col.elements = col.elements.map(cell => {
              cell.uuid = Utils.getuuid()
 
              if (cell.eleType === 'button') {
                MenuUtils.resetBtn(cell, cell.uuid)
              }
              return cell
            })
          }
          return col
        })
      }
 
      res.cols = loopCol(res.cols)
 
      let oriUids = {}
      res.action = res.action.map(cell => {
        let _uuid = Utils.getuuid()
 
        oriUids[cell.uuid] = _uuid
 
        cell.uuid = _uuid
 
        MenuUtils.resetBtn(cell, cell.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 (
      <>
        {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>
      </>
    )
  }
}
 
export default PasteBaseTable