king
2022-11-10 f01086dc94827dbb15811760e5d13683977fcec9
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import React, { useState } from 'react'
import { useDrop } from 'react-dnd'
import { is, fromJS } from 'immutable'
import update from 'immutability-helper'
 
import Card from './card'
import Utils from '@/utils/utils.js'
import Action from './action'
import './index.scss'
 
const Container = ({list, parent, fields, handleList, handleMenu, deleteMenu, profileAction, handleStyle, updateMarks, dropButton, handleSubConfig }) => {
  const [cards, setCards] = useState(list)
  const moveCard = (id, atIndex) => {
    const { card, index } = findCard(id)
    const _cards = update(cards, { $splice: [[index, 1], [atIndex, 0, card]] })
    handleList(_cards)
  }
 
  if (!is(fromJS(cards), fromJS(list))) {
    setCards(list)
  }
  
  const findCard = id => {
    const card = cards.filter(c => `${c.uuid}` === id)[0]
    return {
      card,
      index: cards.indexOf(card),
    }
  }
 
  const editCard = id => {
    const { card } = findCard(id)
    handleMenu(card)
  }
 
  const copyCard = id => {
    const { card } = findCard(id)
    let copycard = fromJS(card).toJS()
    let _cards = fromJS(cards).toJS()
 
    if (card.eleType === 'button') {
      copycard.copyType = 'action'
    } else {
      copycard.copyType = 'customCardElement'
    }
    copycard.focus = true
 
    let _val = fromJS(copycard).toJS()
 
    if (_val.control) {
      delete _val.controlField
      delete _val.controlVal
    }
 
    copycard.uuid = Utils.getuuid()
    copycard.originCard = card
 
    try {
      delete _val.$srcId
    
      let srcid = localStorage.getItem(window.location.href.split('#')[0] + 'srcId')
      if (srcid) {
        _val.$srcId = srcid
      }
      
      _val = window.btoa(window.encodeURIComponent(JSON.stringify(_val)))
    } catch (e) {
      console.warn('Stringify Failure')
      _val = ''
    }
 
    if (_val) {
      let oInput = document.createElement('input')
      oInput.value = _val
      document.body.appendChild(oInput)
      oInput.select()
      document.execCommand('Copy')
      document.body.removeChild(oInput)
    }
 
    _cards.push(copycard)
 
    handleList(_cards)
    handleMenu(copycard)
  }
 
  const changeStyle = id => {
    const { card } = findCard(id)
    handleStyle(card)
  }
 
  const profileCard = id => {
    const { card } = findCard(id)
    profileAction(card)
  }
 
  const doubleClickCard = id => {
    const { card } = findCard(id)
 
    if (card.eleType !== 'button') {
      return
    }
    
    handleSubConfig(card)
  }
 
  const delCard = id => {
    const { card } = findCard(id)
    deleteMenu(card)
  }
 
  const [, drop] = useDrop({
    accept: 'action',
    drop(item) {
      if (item.$init) { // 拖拽添加
        let newcard = {}
        newcard.uuid = Utils.getuuid()
        newcard.focus = true
 
        // 显示列过滤
        if (parent.type === 'custom' && item.class !== 'element') {
          delete item.overIndex
          return
        } else if (parent.type === 'action' && item.class === 'element') {
          delete item.overIndex
          return
        }
        
        if (item.class === 'element') {
          newcard.eleType = item.value
          newcard.datatype = 'dynamic'
          newcard.height = 1
 
          if (item.value === 'splitline') {
            newcard.width = 24
            newcard.color = '#EBE9E9'
          } else if (item.value === 'slider') {
            newcard.width = 24
            newcard.color = '#1890ff'
          }
        } else {
          newcard.eleType = 'button'
          newcard.label = 'button'
          newcard.verify = null
          newcard.show = 'link'
          newcard.Ot = 'requiredSgl'
          newcard.OpenType = item.value
          newcard.class = 'primary'
 
          if (newcard.OpenType === 'excelIn') {
            newcard.label = item.text
            newcard.class = 'dgreen'
            newcard.Ot = 'notRequired'
          } else if (item.subType === 'excelOut') {
            newcard.label = item.text
            newcard.execSuccess = 'never'
            newcard.class = 'dgreen'
          }
        }
 
        if (item.overIndex) {
          const { index } = findCard(item.overIndex)
          const _cards = update(cards, { $splice: [[index + 1, 0, newcard]] })
          handleList(_cards)
        } else {
          handleList([...cards, newcard])
        }
 
        handleMenu(newcard)
 
        delete item.overIndex
        return
      }
 
      const { index } = findCard(item.id)
      if (index > -1) return
      dropButton(item.id)
    }
  })
 
  return (
    <div ref={drop} className="ant-row card-detail-row">
      {cards.map(card => {
        if (card.eleType === 'button') {
          return (
            <Action
              id={card.uuid}
              key={card.uuid}
              card={card}
              copyCard={copyCard}
              moveCard={moveCard}
              editCard={editCard}
              changeStyle={changeStyle}
              profileCard={profileCard}
              doubleClickCard={doubleClickCard}
              delCard={delCard}
              findCard={findCard}
            />
          )
        } else {
          return (
            <Card
              id={card.uuid}
              key={card.uuid}
              card={card}
              parent={parent}
              fields={fields}
              moveCard={moveCard}
              copyCard={copyCard}
              editCard={editCard}
              updateMarks={updateMarks}
              changeStyle={changeStyle}
              delCard={delCard}
              findCard={findCard}
            />
          )
        }
      })}
    </div>
  )
}
export default Container