king
2025-01-02 88290b40164b2e153a59751445b1879b06a9f170
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
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Modal, notification } 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'
 
const PasteForm = asyncComponent(() => import('@/templates/zshare/pasteform'))
 
class PasteController extends Component {
  static propTpyes = {
    options: PropTypes.array,
    updateConfig: PropTypes.func
  }
 
  state = {
    visible: false
  }
 
  resetconfig = (item, appType) => {
    if (item.copyType === 'action') {
      MenuUtils.resetBtn(item, item.uuid)
    } else if (item.copyType === 'cardcell') {
      item.setting = item.setting || {}
      item.setting.width = item.setting.width || 6
      delete item.$cardType
 
      if (item.elements) {
        item.elements = item.elements.map(cell => {
          cell.uuid = Utils.getuuid()
 
          if (cell.eleType === 'button') {
            MenuUtils.resetBtn(cell, item.uuid)
          }
          return cell
        })
        if (appType === 'mob') {
          item.elements = item.elements.filter(cell => {
            if (cell.eleType === 'button' && ['excelIn', 'tab'].includes(cell.OpenType)) {
              return false
            }
            return true
          })
        }
      }
      if (appType === 'mob') {
        item.backElements = []
      } else if (item.backElements) {
        item.backElements = item.backElements.map(cell => {
          cell.uuid = Utils.getuuid()
 
          if (cell.eleType === 'button') {
            MenuUtils.resetBtn(cell, item.uuid)
          }
          return cell
        })
      }
    }
 
    return item
  }
 
  pasteSubmit = () => {
    const { options } = this.props
    this.pasteFormRef.handleConfirm().then(res => {
      if (!options.includes(res.copyType)) {
        notification.warning({ top: 92, message: '配置信息格式错误!', duration: 5 })
        return
      }
 
      let appType = sessionStorage.getItem('appType')
      res.uuid = Utils.getuuid()
 
      res = this.resetconfig(res, appType)
 
      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