| | |
| | | import './index.scss' |
| | | |
| | | const AntvBar = asyncComponent(() => import('@/menu/components/chart/antv-bar')) |
| | | const AntvTabs = asyncComponent(() => import('@/menu/components/tabs/antv-tabs')) |
| | | |
| | | const Card = ({ id, card, moveCard, findCard, editId, editCard, delCard, hasDrop, doubleClickCard, updateConfig }) => { |
| | | const Card = ({ id, menu, card, moveCard, findCard, delCard, hasDrop, doubleClickCard, updateConfig }) => { |
| | | const originalIndex = findCard(id).index |
| | | const [{ isDragging }, drag] = useDrag({ |
| | | item: { type: 'menu', id, originalIndex }, |
| | | item: { type: 'menu', id, originalIndex, floor: card.floor }, |
| | | collect: monitor => ({ |
| | | isDragging: monitor.isDragging(), |
| | | }), |
| | |
| | | const [, drop] = useDrop({ |
| | | accept: 'menu', |
| | | canDrop: () => true, |
| | | drop: (item) => { |
| | | if (!item.hasOwnProperty('originalIndex')) { |
| | | drop: ({ id: draggedId, originalIndex, floor }) => { |
| | | if (originalIndex === undefined) { |
| | | hasDrop(card) |
| | | } else if (draggedId && floor === card.floor) { |
| | | if (draggedId !== id) { |
| | | const { index: overIndex } = findCard(id) |
| | | moveCard(draggedId, overIndex) |
| | | } |
| | | } |
| | | }, |
| | | hover({ id: draggedId }) { |
| | | if (!draggedId) return |
| | | if (draggedId !== id) { |
| | | const { index: overIndex } = findCard(id) |
| | | moveCard(draggedId, overIndex) |
| | | } |
| | | }, |
| | | } |
| | | }) |
| | | |
| | | let style = { opacity: 1} |
| | |
| | | } |
| | | |
| | | const getCardComponent = () => { |
| | | if (card.type === 'bar') { |
| | | return (<AntvBar card={card} triggerEdit={editCard} editId={editId} onDoubleClick={doubleClickCard} updateConfig={updateConfig} />) |
| | | if (card.type === 'bar' || card.type === 'line') { |
| | | return (<AntvBar menu={menu} card={card} updateConfig={updateConfig} />) |
| | | } else if (card.type === 'tabs') { |
| | | return (<AntvTabs menu={menu} tabs={card} updateConfig={updateConfig} />) |
| | | } |
| | | } |
| | | |
| | | return ( |
| | | <div className="mk-component-card" ref={node => drag(drop(node))} style={style}> |
| | | <div className={'ant-col mk-component-card ant-col-' + (card.setting ? card.setting.span : 12)} ref={node => drag(drop(node))} style={style}> |
| | | {getCardComponent()} |
| | | <Icon className="remove-component" title="delete" type="delete" onClick={() => delCard(id)} /> |
| | | </div> |