king
2020-09-18 51a60b5cb00fdeaf9e42c29341242460bf2154e8
src/menu/components/tabs/tabcomponents/index.jsx
@@ -2,13 +2,15 @@
import { useDrop } from 'react-dnd'
import { is, fromJS } from 'immutable'
import update from 'immutability-helper'
import { Empty, notification } from 'antd'
import { Empty, notification, Modal } from 'antd'
import Utils from '@/utils/utils.js'
import Card from './card'
import './index.scss'
const Container = ({menu, parentId, config, handleList, deleteCard, doubleClickCard }) => {
const { confirm } = Modal
const Container = ({menu, config, handleList }) => {
  let target = null
  const [cards, setCards] = useState(config.components)
@@ -38,6 +40,28 @@
    handleList({...config, components: cards.map(item => item.uuid === element.uuid ? element : item)})
  }
  const deleteCard = (id) => {
    const { card } = findCard(id)
    let hasComponent = false
    if (card.type === 'tabs') {
      card.subtabs.forEach(tab => {
        if (tab.components.length > 0) {
          hasComponent = true
        }
      })
    }
    confirm({
      title: `确定删除《${card.setting.name}》吗?`,
      content: hasComponent ? '当前组件中含有子组件!' : '',
      onOk() {
        handleList({...config, components: cards.filter(item => item.uuid !== card.uuid)})
      },
      onCancel() {}
    })
  }
  const [, drop] = useDrop({
    accept: 'menu',
    drop(item) {
@@ -55,15 +79,40 @@
          })
          return
        }
      } else if (item.component === 'tabs' && config.floor === 3) {
        notification.warning({
          top: 92,
          message: '标签页最多为三重结构!',
          duration: 5
        })
        return
      }
      let name = ''
      let names = {
        bar: '柱状图',
        line: '折线图',
        tabs: '标签组'
      }
      let i = 1
      while (!name && names[item.component]) {
        let _name = names[item.component] + i
        if (config.components.filter(com => com.setting && com.setting.name === _name).length === 0) {
          name = _name
        }
        i++
      }
      
      let newcard = {
        uuid: Utils.getuuid(),
        tabId: config.uuid,
        parentId: config.parentId,
        type: item.component,
        subtype: item.subtype,
        parentId: parentId,
        floor: 2,   // 组件的层级
        isNew: true // 新添加标志,用于初始化
        name: name,
        floor: config.floor ? (config.floor + 1) : 2, // 组件的层级
        isNew: true                                   // 新添加标志,用于初始化
      }
      
      let targetId = cards.length > 0 ? cards[cards.length - 1].uuid : 0
@@ -97,7 +146,6 @@
          findCard={findCard}
          hasDrop={hasDrop}
          updateConfig={updateConfig}
          doubleClickCard={doubleClickCard}
        />
      ))}
      {cards.length === 0 ?