king
2020-02-21 063b983daaf51a7f1e8677bde1e9c0e618866c91
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import React, { useState } from 'react'
import { useDrop } from 'react-dnd'
import { is, fromJS } from 'immutable'
import update from 'immutability-helper'
import { Col, Icon } from 'antd'
import Utils from '@/utils/utils.js'
import Card from './card'
import ItemTypes from './itemtypes'
import './index.scss'
 
const Container = ({list, setting, gridBtn, type, placeholder, handleList, handleMenu, deleteMenu, copyElement, profileMenu, handleGridBtn, showfield }) => {
  let target = null
  
  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(type, _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 profileCard = id => {
    const { card } = findCard(id)
    profileMenu(card)
  }
 
  const delCard = id => {
    const { card } = findCard(id)
    deleteMenu({card: card, type: type})
  }
 
  const copyCard = id => {
    const { card } = findCard(id)
    let copycard = JSON.parse(JSON.stringify(card))
    copycard.uuid = Utils.getuuid()
    copycard.origin = false
    copycard.label = copycard.label + '(copy)'
    copycard.focus = true
 
    copycard.originCard = card
 
    copyElement(copycard)
  }
 
  const hasDrop = (item) => {
    target = item
  }
 
  const [, drop] = useDrop({
    accept: ItemTypes[type],
    drop(item) {
      if (item.hasOwnProperty('originalIndex')) {
        return
      }
 
      let newcard = {}
      newcard.uuid = Utils.getuuid()
      newcard.focus = true
      
      if (item.type === 'search') {
        let _match = 'like'
        if (item.subType === 'select' || item.subType === 'link') {
          _match = '='
        } else if (item.subType === 'date' || item.subType === 'datemonth') {
          _match = '>='
        } else if (item.subType === 'dateweek' || item.subType === 'daterange') {
          _match = 'between'
        }
        
        newcard.label = 'label'
        newcard.initval = ''
        newcard.type = item.subType
        newcard.resourceType = '0'
        newcard.options = []
        newcard.setAll = 'false'
        newcard.orderType = 'asc'
        newcard.match = _match
        newcard.display = 'dropdown'
      } else if (item.type === 'action') {
        newcard.label = 'button'
        newcard.sqlType = ''
        newcard.Ot = 'requiredSgl'
        newcard.OpenType = item.subType
        newcard.tabType = 'SubTable'
        newcard.icon = ''
        newcard.class = 'default'
        newcard.intertype = 'inner'
        newcard.method = 'POST'
        newcard.position = 'toolbar'
        newcard.execSuccess = 'grid'
        newcard.execError = 'never'
        newcard.popClose = 'never'
        newcard.errorTime = 15
        newcard.verify = null
 
        if (item.subType === 'excelIn') {
          // 导入和导出excel,按钮名称直接为导入、导出
          newcard.label = item.label
        } else if (item.subType === 'excelOut') {
          newcard.label = item.label
          newcard.intertype = setting.interType
          newcard.innerFunc = setting.innerFunc
          newcard.sysInterface = setting.sysInterface
          newcard.outerFunc = setting.outerFunc
          newcard.interface = setting.interface
        }
      } else if (item.type === 'columns') {
        newcard.Align = 'left'
        newcard.label = 'label'
        newcard.field = ''
        newcard.Hide = 'false'
        newcard.IsSort = 'true'
        newcard.type = item.subType
        newcard.Width = 120
        if (item.subType === 'colspan') {
          newcard.sublist = []
          newcard.subfield = []
          newcard.IsSort = 'false'
          newcard.order = 'vertical'
        }
      }
      
      let targetId = cards.length > 0 ? cards[cards.length - 1].uuid : 0
      if (target) {
        targetId = target.uuid
      }
 
      const { index: overIndex } = findCard(`${targetId}`)
      let targetIndex = overIndex
 
      targetIndex++
 
      const _cards = update(cards, { $splice: [[targetIndex, 0, newcard]] })
 
      handleList(type, _cards, newcard)
      target = null
    }
  })
  let columns = []
  let _colCards = []
 
  // 过滤合并列
  if (type === 'columns') {
    let _hideCol = []
    cards.forEach(col => {
      if (col.type === 'colspan' && col.sublist) {
        _hideCol = _hideCol.concat(col.sublist)
      }
    })
    cards.forEach(col => {
      if (!_hideCol.includes(col.uuid)) {
        _colCards.push(col)
      }
    })
  }
 
  // 显示列分行
  if (type === 'columns' && _colCards.length > 10) {
    let number = Math.ceil(_colCards.length / Math.ceil(_colCards.length / 10))
    for (let i = 0, len = _colCards.length; i < len; i += number) {
      columns.push(_colCards.slice(i, i + number))
    }
  } else if (type === 'columns') {
    columns.push(_colCards)
  }
  
  return (
    <div ref={drop} className="ant-row">
      {type === 'action' && cards.map(card => (
        <Card
          key={card.uuid}
          id={`${card.uuid}`}
          type={type}
          card={card}
          moveCard={moveCard}
          editCard={editCard}
          delCard={delCard}
          copyCard={copyCard}
          profileCard={profileCard}
          findCard={findCard}
          hasDrop={hasDrop}
        />
      ))}
      {type === 'search' && cards.map(card => (
        <Col key={card.uuid} span={6}>
          <Card
            id={`${card.uuid}`}
            type={type}
            card={card}
            moveCard={moveCard}
            editCard={editCard}
            delCard={delCard}
            findCard={findCard}
            hasDrop={hasDrop}
          />
        </Col>
      ))}
      {type === 'columns' && _colCards.length > 0 &&
        columns.map((column, i) => (
          <div key={i} className="column-box">
            {/* 多选 */}
            {i === 0 && setting.tableType === 'checkbox' ?
              <div className="page-card" style={{flex: 60}}>
                <span className="ant-checkbox-inner"></span>
              </div> : null
            }
            {/* 单选 */}
            {i === 0 && setting.tableType === 'radio' ?
              <div className="page-card" style={{flex: 60}}></div> : null
            }
            {column.map(card => (
              <Card
                key={card.uuid}
                id={`${card.uuid}`}
                type={type}
                card={card}
                showfield={showfield}
                moveCard={moveCard}
                editCard={editCard}
                delCard={delCard}
                findCard={findCard}
                hasDrop={hasDrop}
              />
            ))}
            {i === (columns.length - 1) && gridBtn && gridBtn.display ?
              <div className="page-card" style={{flex: gridBtn.Width}}>
                <div style={{cursor: 'default'}}>
                  <span className="ant-table-header-column">
                    <div className="ant-table-column-sorters" title={gridBtn.label} style={{textAlign: gridBtn.Align}}>
                      <span className="ant-table-column-title">{gridBtn.label}</span>
                    </div>
                  </span>
                </div>
                <Icon className="edit" type="edit" onClick={handleGridBtn}/>
              </div> : null
            }
          </div>
        ))
      }
      {cards.length === 0 &&
        <div className="common-drawarea-placeholder">
          {placeholder}
        </div>
      }
    </div>
  )
}
export default Container