From ab60d53b67f802878662aaa5a5b52580cca421b8 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 26 九月 2020 08:52:46 +0800
Subject: [PATCH] 2020-09-26

---
 src/menu/components/card/cardcellcomponent/index.jsx |   57 +++++++++++++++++++++++++++++++++------------------------
 1 files changed, 33 insertions(+), 24 deletions(-)

diff --git a/src/menu/components/card/cardcellcomponent/index.jsx b/src/menu/components/card/cardcellcomponent/index.jsx
index 023cf5b..78c0753 100644
--- a/src/menu/components/card/cardcellcomponent/index.jsx
+++ b/src/menu/components/card/cardcellcomponent/index.jsx
@@ -7,6 +7,7 @@
 import enUS from '@/locales/en-US/model.js'
 import { getCardCellForm } from './formconfig'
 
+import MKEmitter from '@/utils/events.js'
 import ElementForm from './elementform'
 import DragElement from './dragaction'
 import './index.scss'
@@ -38,20 +39,42 @@
     })
   }
 
+  componentDidMount () {
+    MKEmitter.addListener('cardAddElement', this.cardAddElement)
+  }
+
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.props.config), fromJS(nextProps.config)) || !is(fromJS(this.state), fromJS(nextState))
+  }
+
   /**
-   * @description 鎸夐挳椤哄簭璋冩暣锛屾垨鎷栨嫿娣诲姞
+   * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊锛屾竻闄ゅ揩鎹烽敭璁剧疆
    */
-  handleList = (list, card) => {
+  componentWillUnmount () {
+    this.setState = () => {
+      return
+    }
+    MKEmitter.removeListener('cardAddElement', this.cardAddElement)
+  }
+
+  cardAddElement = (cardId, element) => {
+    if (cardId !== this.props.config.uuid) return
+
+    const { elements } = this.state
+
+    this.setState({elements: [...elements, element]})
+    this.handleElement(element)
+  }
+
+  /**
+   * @description 鎸夐挳椤哄簭璋冩暣
+   */
+  handleList = (list) => {
     const { config } = this.props
 
-    if (card) {
-      this.setState({elements: list})
-      this.handleElement(card)
-    } else {
-      this.setState({elements: list}, () => {
-        this.props.updateElement({...config, elements: list})
-      })
-    }
+    this.setState({elements: list}, () => {
+      this.props.updateElement({...config, elements: list})
+    })
   }
 
   /**
@@ -132,20 +155,6 @@
       },
       onCancel() {}
     })
-  }
-
-
-  shouldComponentUpdate (nextProps, nextState) {
-    return !is(fromJS(this.props.config), fromJS(nextProps.config)) || !is(fromJS(this.state), fromJS(nextState))
-  }
-
-  /**
-   * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
-   */
-  componentWillUnmount () {
-    this.setState = () => {
-      return
-    }
   }
 
   render() {

--
Gitblit v1.8.0