king
2020-05-14 eb31b84962c192de57abbb473cb4733a09bf4363
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
import React from 'react'
import { useDrag, useDrop } from 'react-dnd'
import { Icon } from 'antd'
import './index.scss'
 
const Card = ({ id, card, showfield, moveCard, findCard, editCard, delCard, markCard, hasDrop }) => {
  const originalIndex = findCard(id).index
  const [{ isDragging }, drag] = useDrag({
    item: { type: 'columns', id, originalIndex },
    collect: monitor => ({
      isDragging: monitor.isDragging(),
    }),
  })
  const [, drop] = useDrop({
    accept: 'columns',
    canDrop: () => true,
    drop: (item) => {
      if (!item.hasOwnProperty('originalIndex')) {
        hasDrop(card)
      }
    },
    hover({ id: draggedId }) {
      if (!draggedId) return
      if (draggedId !== id) {
        const { index: overIndex } = findCard(id)
        moveCard(draggedId, overIndex)
      }
    },
  })
  
  const opacity = isDragging ? 0 : 1
 
  return (
    <div className="page-card" style={{ flex: card.Width, opacity: opacity}}>
      <div ref={node => drag(drop(node))}>
        <span className="ant-table-header-column">
          <div className="ant-table-column-sorters" title={card.label} style={{textAlign: card.Align}}>
            <span className="ant-table-column-title">{card.label}</span>
            {card.IsSort === 'true' ?
              <span className="ant-table-column-sorter">
                <Icon type="caret-up" />
                <Icon type="caret-down" />
              </span> : null
            }
          </div>
          {showfield ?
            <div className="ant-table-column-fields">
              <span className="ant-table-column-title">{card.type === 'colspan' ? card.subfield : card.field}</span>
            </div> : null
          }
        </span>
      </div>
      <Icon className="edit" title="edit" type="edit" onClick={() => editCard(id)} />
      <Icon className="edit close" title="delete" type="close" onClick={() => delCard(id)} />
      {['text', 'number'].includes(card.type) && !card.origin ? <Icon className="edit mark" title="mark" type="ant-design" onClick={() => markCard(id)} /> : null}
    </div>
  )
}
export default Card