king
2020-09-16 2e5908bf05c200e12aa0fdfe5db5e21cbe7d014a
src/menu/menushell/index.jsx
@@ -8,18 +8,18 @@
import Card from './card'
import './index.scss'
const Container = ({config, handleList, deleteCard, doubleClickCard }) => {
const Container = ({menu, handleList, deleteCard, doubleClickCard }) => {
  let target = null
  const [cards, setCards] = useState(config.components)
  const [cards, setCards] = useState(menu.components)
  const moveCard = (id, atIndex) => {
    const { card, index } = findCard(id)
    const _cards = update(cards, { $splice: [[index, 1], [atIndex, 0, card]] })
    handleList({...config, components: _cards})
    handleList({...menu, components: _cards})
  }
  if (!is(fromJS(cards), fromJS(config.components))) {
    setCards(config.components)
  if (!is(fromJS(cards), fromJS(menu.components))) {
    setCards(menu.components)
  }
  
  const findCard = id => {
@@ -35,16 +35,15 @@
  }
  const updateConfig = (element) => {
    handleList({...config, components: cards.map(item => item.uuid === element.uuid ? element : item)})
    handleList({...menu, components: cards.map(item => item.uuid === element.uuid ? element : item)})
  }
  const [, drop] = useDrop({
    accept: 'menu',
    drop(item) {
      if (item.hasOwnProperty('originalIndex')) {
      if (item.hasOwnProperty('originalIndex') || item.added) {
        return
      }
      if (item.component === 'search') { // 搜索组件不可重复添加
        if (cards.filter(card => card.type === 'search').length > 0) {
          notification.warning({
@@ -54,6 +53,22 @@
          })
          return
        }
      }
      let name = ''
      let names = {
        bar: '柱状图',
        line: '折线图',
        tabs: '标签组'
      }
      let i = 1
      while (!name && names[item.component]) {
        let _name = names[item.component] + i
        if (menu.components.filter(com => com.setting && com.setting.name === _name).length === 0) {
          name = _name
        }
        i++
      }
      let newcard = {
@@ -76,7 +91,7 @@
      const _cards = update(cards, { $splice: [[targetIndex, 0, newcard]] })
      handleList({...config, components: _cards})
      handleList({...menu, components: _cards})
      target = null
    }
  })
@@ -87,7 +102,7 @@
        <Card
          id={card.uuid}
          key={card.uuid}
          config={config}
          menu={menu}
          card={card}
          moveCard={moveCard}
          delCard={deleteCard}