From 72419e2f826031a158173f46d723a672064e37cd Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 31 八月 2021 22:42:51 +0800
Subject: [PATCH] 2021-08-31

---
 src/tabviews/zshare/actionList/tabbutton/index.jsx |  109 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 78 insertions(+), 31 deletions(-)

diff --git a/src/tabviews/zshare/actionList/tabbutton/index.jsx b/src/tabviews/zshare/actionList/tabbutton/index.jsx
index 881a5b8..db9b04b 100644
--- a/src/tabviews/zshare/actionList/tabbutton/index.jsx
+++ b/src/tabviews/zshare/actionList/tabbutton/index.jsx
@@ -2,7 +2,7 @@
 import PropTypes from 'prop-types'
 import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { Button, notification } from 'antd'
+import { Button, notification, Icon } from 'antd'
 
 import { modifyTabview } from '@/store/action'
 import zhCN from '@/locales/zh-CN/main.js'
@@ -18,12 +18,27 @@
     btn: PropTypes.object,            // 鎸夐挳
     selectedData: PropTypes.any,      // 瀛愯〃涓�夋嫨鏁版嵁
     setting: PropTypes.any,           // 椤甸潰閫氱敤璁剧疆
-    updateStatus: PropTypes.any
   }
 
   state = {
     dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
+    disabled: false,
     primaryId: ''
+  }
+
+  UNSAFE_componentWillMount () {
+    const { btn, selectedData } = this.props
+    let disabled = false
+
+    if (btn.controlField && selectedData && selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒�
+      selectedData.forEach(item => {
+        let s = item[btn.controlField] + ''
+        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
+          disabled = true
+        }
+      })
+      this.setState({disabled})
+    }
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -35,6 +50,24 @@
 
     if (position === 'toolbar') {
       MKEmitter.addListener('triggerBtnId', this.actionTrigger)
+    }
+  }
+
+  UNSAFE_componentWillReceiveProps (nextProps) {
+    const { btn, selectedData } = this.props
+
+    if (btn.controlField && !is(fromJS(nextProps.selectedData || []), fromJS(selectedData || []))) {
+      let disabled = false
+
+      if (nextProps.selectedData && nextProps.selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒�
+        nextProps.selectedData.forEach(item => {
+          let s = item[btn.controlField] + ''
+          if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
+            disabled = true
+          }
+        })
+      }
+      this.setState({disabled})
     }
   }
 
@@ -63,22 +96,12 @@
         duration: 5
       })
       return
-    } else if (!setting.primaryKey) {
-      // 闇�瑕侀�夋嫨琛屾椂锛屾牎楠屾槸鍚﹁缃富閿�
-      notification.warning({
-        top: 92,
-        message: '鏈缃富閿紒',
-        duration: 5
-      })
-      return
     }
 
     let primaryId = ''
-    let _data = null
 
-    if (btn.Ot === 'requiredSgl') {
+    if (btn.Ot === 'requiredSgl' && setting.primaryKey) {
       primaryId = data[0][setting.primaryKey] || ''
-      _data = data[0]
     }
 
     let newtab = {}
@@ -118,8 +141,7 @@
         ...menu,
         selected: true,
         param: {
-          BID: primaryId,
-          data: _data
+          $BID: primaryId
         }
       }
     }
@@ -135,43 +157,68 @@
       return tab.MenuID !== newtab.MenuID
     })
 
-    if (tabviews.length !== tabs.length) {
-      this.props.modifyTabview(fromJS(tabs).toJS())
+    if (['linkage_navigation', 'linkage', 'menu_board'].includes(window.GLOB.navBar)) {
+      this.props.modifyTabview([newtab])
+    } else {
+      if (tabviews.length !== tabs.length) {
+        this.props.modifyTabview(fromJS(tabs).toJS())
+      }
+  
+      this.setState({}, () => {
+        if (MenuID) {
+          tabs.splice(index + 1, 0, newtab)
+        } else {
+          tabs.push(newtab)
+        }
+        this.props.modifyTabview(tabs)
+      })
     }
 
-    this.setState({}, () => {
-      if (MenuID) {
-        tabs.splice(index + 1, 0, newtab)
-      } else {
-        tabs.push(newtab)
-      }
-      this.props.modifyTabview(tabs)
-    })
-
-    if (this.props.updateStatus) {
-      this.props.updateStatus('trigger')
+    MKEmitter.emit('openNewTab')
+    if (window.GLOB.systemType === 'production') {
+      MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: '鏍囩椤�'})
     }
   }
 
   render() {
     const { btn, show } = this.props
+    const { disabled } = this.state
 
     if (show === 'actionList') {
       return (
         <Button
           className={'mk-btn mk-' + btn.class}
           icon={btn.icon}
+          disabled={disabled}
           onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
         >{btn.label}</Button>
       )
     } else { // icon銆乼ext銆� all 鍗$墖
+      let label = ''
+      let icon = ''
+
+      if (show === 'button') {
+        label = btn.label
+        icon = btn.icon || ''
+      } else if (show === 'link') {
+        label = <span>{btn.label}{btn.icon ? <Icon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span>
+        icon = ''
+      } else if (show === 'icon') {
+        icon = btn.icon || ''
+      // } else if (show === 'text') {
+      } else {
+        label = btn.label
+      }
+
       return (
         <Button
           type="link"
-          style={btn.btnstyle}
-          icon={show === 'text' ? '' : (btn.icon || '')}
+          title={show === 'icon' ? btn.label : ''}
+          style={btn.style}
+          disabled={disabled}
+          icon={icon}
           onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
-        >{show === 'icon' && btn.icon ? '' : btn.label}</Button>
+        >{label}</Button>
       )
     }
   }

--
Gitblit v1.8.0