king
2020-07-01 9a16cb432ed0a597caf9ba78c9dda63ad2134207
src/mob/mobshell/index.jsx
@@ -2,13 +2,13 @@
import { useDrop } from 'react-dnd'
import { is, fromJS } from 'immutable'
import update from 'immutability-helper'
import { message } from 'antd'
import { message, Empty } from 'antd'
import Utils from '@/utils/utils.js'
import Card from './card'
import './index.scss'
const Container = ({config, handleList, handleMenu, deleteMenu, doubleClickCard }) => {
const Container = ({config, editId, handleList, editCard, deleteCard, doubleClickCard }) => {
  let target = null
  const [cards, setCards] = useState(config.components)
@@ -16,7 +16,6 @@
    const { card, index } = findCard(id)
    const _cards = update(cards, { $splice: [[index, 1], [atIndex, 0, card]] })
    handleList({...config, components: _cards})
    console.log(_cards)
  }
  if (!is(fromJS(cards), fromJS(config.components))) {
@@ -31,23 +30,12 @@
    }
  }
  // const doubleClickBtn = id => {
  //   const { card } = findCard(id)
  //   doubleClickCard(card)
  // }
  // const editCard = id => {
  //   const { card } = findCard(id)
  //   handleMenu(card)
  // }
  // const delCard = id => {
  //   const { card } = findCard(id)
  //   deleteMenu(card)
  // }
  const hasDrop = (item) => {
    target = item
  }
  const updateConfig = (element) => {
    handleList({...config, components: cards.map(item => item.uuid === element.uuid ? element : item)})
  }
  const [, drop] = useDrop({
@@ -63,6 +51,11 @@
      }
      let newcard = fromJS(item.param).toJS()
      Object.keys(newcard).forEach(key => {
        if (newcard[key].editable) {
          newcard[key].uuid = Utils.getuuid()
        }
      })
      newcard.uuid = Utils.getuuid()
      
      let targetId = cards.length > 0 ? cards[cards.length - 1].uuid : 0
@@ -89,19 +82,19 @@
          id={card.uuid}
          key={card.uuid}
          card={card}
          editId={editId}
          moveCard={moveCard}
          // editCard={editCard}
          // delCard={delCard}
          editCard={editCard}
          delCard={deleteCard}
          findCard={findCard}
          hasDrop={hasDrop}
          // doubleClickCard={doubleClickBtn}
          updateConfig={updateConfig}
          doubleClickCard={doubleClickCard}
        />
      ))}
      {/* {cards.length === 0 ?
        <div className="common-drawarea-placeholder">
          {placeholder}
        </div> : null
      } */}
      {cards.length === 0 ?
        <Empty description="请添加组件" /> : null
      }
    </div>
  )
}