From 2e5908bf05c200e12aa0fdfe5db5e21cbe7d014a Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 16 九月 2020 09:38:21 +0800
Subject: [PATCH] 2020-09-16

---
 src/menu/menushell/index.jsx |   35 +++++++++++++++++++++++++----------
 1 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/src/menu/menushell/index.jsx b/src/menu/menushell/index.jsx
index 61edf52..81e2bbb 100644
--- a/src/menu/menushell/index.jsx
+++ b/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}

--
Gitblit v1.8.0