king
2022-10-18 a8507cc8c42d17d4fb854594dbf1e084d61912ac
src/menu/tableshell/card.jsx
@@ -1,5 +1,5 @@
import React from 'react'
import { useDrag, useDrop } from 'react-dnd'
import { useDrop } from 'react-dnd'
import asyncComponent from '@/utils/asyncComponent'
import './index.scss'
@@ -7,48 +7,24 @@
const AntvTabs = asyncComponent(() => import('@/menu/components/tabs/antv-tabs'))
const BaseTable = asyncComponent(() => import('@/menu/components/table/base-table'))
const Card = ({ id, card, moveCard, findCard, delCard, updateConfig }) => {
  const originalIndex = findCard(id).index
  const [{ isDragging }, drag] = useDrag({
    item: { type: 'menu', id, originalIndex },
    collect: monitor => ({
      isDragging: monitor.isDragging(),
    }),
  })
const Card = ({ id, card, delCard, updateConfig }) => {
  const [, drop] = useDrop({
    accept: 'menu',
    canDrop: () => true,
    drop: (item) => {
      const { id: draggedId, originalIndex } = item
      if (originalIndex === undefined) {
        item.dropTargetId = id
      } else if (draggedId) {
        if (draggedId === id) return
        const { index: originIndex } = findCard(draggedId)
        if (originIndex === -1) return
        const { index: overIndex } = findCard(id)
        moveCard(draggedId, overIndex)
      }
      item.dropTargetId = id
    }
  })
  let style = { opacity: 1}
  if (isDragging) {
    style = { opacity: 0.3}
  }
  const getCardComponent = () => {
    if (card.type === 'table') {
      return (<BaseTable card={card} updateConfig={updateConfig} deletecomponent={delCard}/>)
      return (<BaseTable card={card} updateConfig={updateConfig}/>)
    } else if (card.type === 'tabs') {
      return (<AntvTabs tabs={card} updateConfig={updateConfig} deletecomponent={delCard}/>)
    }
  }
  return (
    <div className={'ant-col mk-component-card ant-col-' + (card.width || 24)} ref={node => drag(drop(node))} style={style}>
    <div className={'ant-col mk-component-card ant-col-' + (card.width || 24)} ref={node => drop(node)}>
      {getCardComponent()}
    </div>
  )