king
2021-12-22 5223edbcccfed84a33a706e5637ee65a61f377aa
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
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import { Modal, Button, notification } from 'antd'
import { SnippetsOutlined } from '@ant-design/icons'
 
import MenuUtils from '@/utils/utils-custom.js'
import MKEmitter from '@/utils/events.js'
import asyncComponent from '@/utils/asyncComponent'
// import './index.scss'
 
const PasteForm = asyncComponent(() => import('@/templates/zshare/pasteform'))
 
class PasteController extends Component {
  static propTpyes = {
    insert: PropTypes.func
  }
 
  state = {
    visible: false
  }
 
  resetconfig = (item, copyBtns, uuids = {}) => {
    let appType = sessionStorage.getItem('appType')
    
    if (item.type === 'tabs') {
      uuids[item.uuid] = MenuUtils.getuuid()
      item.uuid = uuids[item.uuid]
      item.setting.name = item.setting.name + MenuUtils.getdataName().toUpperCase().substr(-4)
      item.name = item.setting.name
 
      item.subtabs.forEach(tab => {
        uuids[tab.uuid] = MenuUtils.getuuid()
        tab.uuid = uuids[tab.uuid]
        tab.parentId = item.uuid
 
        if (appType !== 'mob') {
          tab.components = tab.components.filter(cell => cell.type !== 'menubar')
        }
 
        tab.components = tab.components.map(cell => {
          cell.floor = tab.floor + 1
          cell.tabId = tab.uuid
          cell.parentId = tab.parentId
 
          cell = this.resetconfig(cell, copyBtns, uuids)
          return cell
        })
      })
    } else if (item.type === 'group') {
      uuids[item.uuid] = MenuUtils.getuuid()
      item.uuid = uuids[item.uuid]
      item.setting.name = item.setting.name + MenuUtils.getdataName().toUpperCase().substr(-4)
      item.name = item.setting.name
 
      item.components = item.components.map(cell => {
        cell.floor = item.floor
        cell.tabId = item.tabId || ''
        cell.parentId = item.parentId || ''
 
        cell = MenuUtils.resetComponentConfig(cell, copyBtns, uuids)
        return cell
      })
    } else {
      item = MenuUtils.resetComponentConfig(item, copyBtns, uuids)
    }
 
    return item
  }
 
  pasteSubmit = () => {
    let options = ['tabs', 'menubar', 'topbar', 'timeline', 'datacard', 'propcard', 'mainsearch', 'stepform', 'tabform', 'balcony', 'group', 'normaltable', 'tablecard', 'line', 'bar', 'pie', 'dashboard', 'scatter']
 
    this.pasteFormRef.handleConfirm().then(res => {
      if ((res.copyType === 'menubar' || res.copyType === 'topbar') && sessionStorage.getItem('appType') !== 'mob') {
        notification.warning({
          top: 92,
          message: '当前系统不支持菜单组件!',
          duration: 5
        })
        return
      } else if (!options.includes(res.copyType)) {
        notification.warning({
          top: 92,
          message: '配置信息格式错误!',
          duration: 5
        })
        return
      }
 
      let copyBtns = new Map()
 
      res = this.resetconfig(res, copyBtns)
 
      delete res.copyType
      
      this.props.insert(res)
 
      copyBtns = [...copyBtns.values()]
 
      if (copyBtns.length > 0) {
        MKEmitter.emit('copyButtons', copyBtns)
      }
 
      this.setState({visible: false})
    })
  }
 
  render() {
    const { visible } = this.state
 
    return (
      <div style={{display: 'inline-block'}}>
        <Button style={{borderColor: '#40a9ff', color: '#40a9ff'}} onClick={() => {this.setState({visible: true})}}><SnippetsOutlined />粘贴</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