import React from 'react'
|
import { useDrag, useDrop } from 'react-dnd'
|
import { Icon, Button } from 'antd'
|
import './index.scss'
|
|
const Card = ({ id, card, moveCard, findCard, editCard, delCard, copyCard, profileCard, doubleClickCard }) => {
|
const originalIndex = findCard(id).index
|
const [{ isDragging }, drag] = useDrag({
|
item: { type: 'action', id, originalIndex },
|
collect: monitor => ({
|
isDragging: monitor.isDragging(),
|
}),
|
})
|
const [, drop] = useDrop({
|
accept: 'action',
|
canDrop: () => true,
|
drop: () => {},
|
hover({ id: draggedId }) {
|
if (!draggedId) return
|
if (draggedId !== id) {
|
const { index: overIndex } = findCard(id)
|
moveCard(draggedId, overIndex)
|
}
|
},
|
})
|
const opacity = isDragging ? 0 : 1
|
|
let hasProfile = false
|
if (['pop', 'prompt', 'exec'].includes(card.OpenType)) {
|
hasProfile = true
|
} else if (card.OpenType === 'excelIn' || card.OpenType === 'excelOut') {
|
hasProfile = true
|
} else if (card.funcType === 'print') {
|
hasProfile = true
|
}
|
|
return (
|
<div className="page-card" style={{ opacity: opacity}}>
|
<div ref={node => drag(drop(node))}>
|
<Button
|
className={'mk-btn mk-' + card.class}
|
icon={card.icon}
|
key={card.uuid}
|
onDoubleClick={() => doubleClickCard(id)}
|
>
|
{card.label}{card.position === 'grid' && <Icon type="table" />}
|
</Button>
|
</div>
|
<Icon className="edit" title="edit" type="edit" onClick={() => editCard(id)} />
|
<Icon className="edit copy" title="copy" type="copy" onClick={() => copyCard(id)} />
|
<Icon className="edit close" title="close" type="close" onClick={() => delCard(id)} />
|
{hasProfile ? <Icon className="edit profile" title="setting" type="profile" onClick={() => profileCard(id)} /> : null}
|
</div>
|
)
|
}
|
export default Card
|