From 28d65cf7ebfe0dd30ade6973e0634e1c8f663b63 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 28 十月 2020 16:12:20 +0800
Subject: [PATCH] 2020-10-28

---
 src/tabviews/zshare/actionList/excelInbutton/index.jsx |   68 ++++++++++++++++++----------------
 1 files changed, 36 insertions(+), 32 deletions(-)

diff --git a/src/tabviews/zshare/actionList/excelInbutton/index.jsx b/src/tabviews/zshare/actionList/excelInbutton/index.jsx
index 53fd47f..9080770 100644
--- a/src/tabviews/zshare/actionList/excelInbutton/index.jsx
+++ b/src/tabviews/zshare/actionList/excelInbutton/index.jsx
@@ -11,6 +11,7 @@
 import Api from '@/api'
 import zhCN from '@/locales/zh-CN/main.js'
 import enUS from '@/locales/en-US/main.js'
+import MKEmitter from '@/utils/events.js'
 import './index.scss'
 
 class ExcelInButton extends Component {
@@ -22,7 +23,6 @@
     btn: PropTypes.object,            // 鎸夐挳
     setting: PropTypes.any,           // 椤甸潰閫氱敤璁剧疆
     updateStatus: PropTypes.func,     // 鎸夐挳鐘舵�佹洿鏂�
-    triggerBtn: PropTypes.any,
   }
 
   state = {
@@ -31,17 +31,23 @@
     primaryId: '',
   }
 
-  /**
-   * @description 澶栭儴瑙﹀彂鎸夐挳鐐瑰嚮
-   */
-  UNSAFE_componentWillReceiveProps(nextProps) {
-    if (nextProps.triggerBtn && !is(fromJS(this.props.triggerBtn), fromJS(nextProps.triggerBtn)) && nextProps.triggerBtn.button.uuid === this.props.btn.uuid) {
-      this.actionTrigger(nextProps.triggerBtn.data)
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
+  }
+
+  componentDidMount () {
+    const { show } = this.props
+
+    if (show === 'actionList') {
+      MKEmitter.addListener('triggerBtnId', this.actionTrigger)
     }
   }
 
-  shouldComponentUpdate (nextProps, nextState) {
-    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
+  componentWillUnmount () {
+    this.setState = () => {
+      return
+    }
+    MKEmitter.removeListener('triggerBtnId', this.actionTrigger)
   }
 
   /**
@@ -52,20 +58,21 @@
       this.setState({
         loading: true
       })
-      this.props.updateStatus('start')
     } else if (type === 'over') {
       this.setState({
         loading: false
       })
-      this.props.updateStatus('over')
     }
   }
   
   /**
    * @description 瑙﹀彂鎸夐挳鎿嶄綔
    */
-  actionTrigger = (record) => {
+  actionTrigger = (triggerId) => {
     const { setting, Tab, BID, btn, selectedData } = this.props
+    const { loading } = this.state
+
+    if ((triggerId && btn.uuid !== triggerId) || loading) return
 
     if (Tab && Tab.supMenu && !BID) {
       notification.warning({
@@ -76,13 +83,7 @@
       return
     }
 
-    let data = []
-    
-    if (record) { // 琛ㄦ牸涓Е鍙戞寜閽�
-      data = [record]
-    } else {
-      data = selectedData || []
-    }
+    let data = selectedData || []
     
     if (btn.Ot === 'requiredSgl' && data.length !== 1) {
       // 闇�瑕侀�夋嫨鍗曡鏃讹紝鏍¢獙鏁版嵁
@@ -392,24 +393,27 @@
     const { btn, show } = this.props
     const { loading } = this.state
 
-    return (
-      <div className="mk-btn-wrap">
-        {!show ? <Button
-          className={'mk-btn mk-' + btn.class}
+    if (show === 'actionList') {
+      return <div style={{display: 'inline-block'}}>
+        <Button
           icon={btn.icon}
-          onClick={() => {this.actionTrigger()}}
           loading={loading}
-        >{btn.label}</Button> : null}
-        {show === 'icon' ? <Button
-          className="import-icon"
-          icon="upload"
+          className={'mk-btn mk-' + btn.class}
           onClick={() => {this.actionTrigger()}}
-          loading={loading}
-          title={btn.label}
-        ></Button> : null}
+        >{btn.label}</Button>
         <ExcelIn btn={btn} triggerExcelIn={() => this.updateStatus('start')} returndata={this.getexceldata} ref="excelIn" />
       </div>
-    )
+    } else { // icon銆乼ext銆� all 鍗$墖
+      return <div style={{display: 'inline-block'}}>
+        <Button
+          type="link"
+          loading={loading}
+          icon={show === 'text' ? '' : (show === 'icon' ? (btn.icon || 'upload') : (btn.icon || ''))}
+          onClick={() => {this.actionTrigger()}}
+        >{show === 'icon' ? '' : btn.label}</Button>
+        <ExcelIn btn={btn} triggerExcelIn={() => this.updateStatus('start')} returndata={this.getexceldata} ref="excelIn" />
+      </div>
+    }
   }
 }
 

--
Gitblit v1.8.0