From 9c6795fd3c44e46cf3955fbfd8f8eeca23acb7a9 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 08 十月 2022 00:31:51 +0800
Subject: [PATCH] 2022-10-08

---
 src/tabviews/zshare/actionList/tabbutton/index.jsx |  217 +++++++++++++++++++++++++++++++++---------------------
 1 files changed, 132 insertions(+), 85 deletions(-)

diff --git a/src/tabviews/zshare/actionList/tabbutton/index.jsx b/src/tabviews/zshare/actionList/tabbutton/index.jsx
index 9223ef1..6158165 100644
--- a/src/tabviews/zshare/actionList/tabbutton/index.jsx
+++ b/src/tabviews/zshare/actionList/tabbutton/index.jsx
@@ -1,28 +1,59 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
 import { Button, notification } from 'antd'
 
-import { modifyTabview } from '@/store/action'
 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'
+import MkIcon from '@/components/mk-icon'
+// import './index.scss'
 
 class TabButton extends Component {
   static propTpyes = {
-    show: PropTypes.any,              // 鎸夐挳鏄剧ず鏍峰紡鎺у埗
-    position: PropTypes.any,          // 鎸夐挳浣嶇疆锛屽伐鍏锋爮涓簍oolbar
+    BData: PropTypes.any,             // 涓昏〃鏁版嵁
     MenuID: PropTypes.string,         // 鑿滃崟ID
     btn: PropTypes.object,            // 鎸夐挳
     selectedData: PropTypes.any,      // 瀛愯〃涓�夋嫨鏁版嵁
     setting: PropTypes.any,           // 椤甸潰閫氱敤璁剧疆
+    disabled: PropTypes.any,          // 琛屾寜閽鐢�
   }
 
   state = {
     dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
+    disabled: false,
+    hidden: false,
     primaryId: ''
+  }
+
+  UNSAFE_componentWillMount () {
+    const { btn, selectedData, BData } = this.props
+    let disabled = false
+
+    if (btn.controlField && selectedData && selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒�
+      selectedData.forEach(item => {
+        let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
+        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
+          disabled = true
+        }
+      })
+      this.setState({hidden: disabled && btn.control === 'hidden'})
+    } else if (btn.control === 'parent') {
+      if (!BData || !BData.hasOwnProperty(btn.controlField)) {
+        this.setState({hidden: true})
+      } else {
+        let s = BData[btn.controlField] + ''
+        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
+          this.setState({hidden: true})
+        } else {
+          this.setState({hidden: false})
+        }
+      }
+    }
+
+    if (this.props.disabled || disabled) {
+      this.setState({disabled: true})
+    }
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -30,10 +61,40 @@
   }
 
   componentDidMount () {
-    const { position } = this.props
+    MKEmitter.addListener('triggerBtnId', this.actionTrigger)
+  }
 
-    if (position === 'toolbar') {
-      MKEmitter.addListener('triggerBtnId', this.actionTrigger)
+  UNSAFE_componentWillReceiveProps (nextProps) {
+    const { btn, selectedData, BData } = this.props
+
+    let disabled = false
+    if (btn.controlField && !is(fromJS(nextProps.selectedData || []), fromJS(selectedData || []))) {
+      if (nextProps.selectedData && nextProps.selectedData.length > 0) { // 琛ㄦ牸涓寜閽殣钘忔帶鍒�
+        nextProps.selectedData.forEach(item => {
+          let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
+          if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
+            disabled = true
+          }
+        })
+      }
+      this.setState({hidden: disabled && btn.control === 'hidden'})
+    } else if (btn.control === 'parent' && !is(fromJS(nextProps.BData || {}), fromJS(BData || {}))) {
+      if (!nextProps.BData || !nextProps.BData.hasOwnProperty(btn.controlField)) {
+        this.setState({hidden: true})
+      } else {
+        let s = nextProps.BData[btn.controlField] + ''
+        if (s === btn.controlVal || (btn.controlVal && btn.controlVal.split(',').includes(s))) {
+          this.setState({hidden: true})
+        } else {
+          this.setState({hidden: false})
+        }
+      }
+    }
+
+    if (nextProps.disabled || disabled) {
+      this.setState({disabled: true})
+    } else {
+      this.setState({disabled: false})
     }
   }
 
@@ -47,10 +108,16 @@
   /**
    * @description 瑙﹀彂鎸夐挳鎿嶄綔
    */
-  actionTrigger = (triggerId, record) => {
-    const { setting, btn, tabviews, MenuID, selectedData } = this.props
+  actionTrigger = (triggerId, record, type) => {
+    const { setting, btn, selectedData } = this.props
+    const { disabled } = this.state
 
+    if (disabled) return
     if (triggerId && btn.uuid !== triggerId) return
+
+    if (type === 'linkbtn' && !btn.$toolbtn && !is(fromJS(selectedData || []), fromJS(record))) {
+      return
+    }
     
     let data = record || selectedData || []
 
@@ -62,22 +129,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 = {}
@@ -88,7 +145,6 @@
         MenuID: btn.uuid,
         MenuName: btn.label,
         type: btn.tabTemplate,
-        selected: true,
         param: {
           parentId: this.props.MenuID,
           btn: btn,
@@ -96,12 +152,17 @@
           primaryId: primaryId
         }
       }
-    } else if (btn.tabTemplate === 'ThdMenu') {
-      let menu = null
+    } else if (btn.MenuID || btn.linkmenu) {
+      let menuId = btn.MenuID || btn.linkmenu.slice(-1)[0]
+      let menu = window.GLOB.mkThdMenus.filter(m => m.MenuID === menuId)[0]
 
-      if (btn.linkmenu && btn.linkmenu.length > 0) {
-        let menu_id = btn.linkmenu.slice(-1)[0]
-        menu = this.props.permMenus.filter(m => m.MenuID === menu_id)[0] || ''
+      if (!menu && btn.MenuName && btn.tabType) {
+        menu = {
+          MenuID: btn.MenuID,
+          MenuName: btn.MenuName,
+          MenuNo: btn.MenuNo,
+          type: btn.tabType
+        }
       }
 
       if (!menu) {
@@ -115,37 +176,17 @@
 
       newtab = {
         ...menu,
-        selected: true,
         param: {
-          BID: primaryId,
-          data: _data
+          $BID: primaryId
         }
       }
     }
 
-    let index = 0
-    let tabs = tabviews.filter((tab, i) => {
-      tab.selected = false
-
-      if (tab.MenuID === MenuID) {
-        index = i
-      }
-
-      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)) {
+      MKEmitter.emit('modifyTabs', newtab, 'replace')
+    } else {
+      MKEmitter.emit('modifyTabs', newtab, 'plus', true)
     }
-
-    this.setState({}, () => {
-      if (MenuID) {
-        tabs.splice(index + 1, 0, newtab)
-      } else {
-        tabs.push(newtab)
-      }
-      this.props.modifyTabview(tabs)
-    })
 
     MKEmitter.emit('openNewTab')
     if (window.GLOB.systemType === 'production') {
@@ -154,41 +195,47 @@
   }
 
   render() {
-    const { btn, show } = this.props
+    const { btn } = this.props
+    const { disabled, hidden } = this.state
 
-    if (show === 'actionList') {
-      return (
-        <Button
-          className={'mk-btn mk-' + btn.class}
-          icon={btn.icon}
-          onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
-        >{btn.label}</Button>
-      )
-    } else { // icon銆乼ext銆� all 鍗$墖
-      return (
-        <Button
-          type="link"
-          title={show === 'icon' ? btn.label : ''}
-          style={btn.btnstyle}
-          icon={show === 'text' ? '' : (btn.icon || '')}
-          onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
-        >{show === 'icon' && btn.icon ? '' : btn.label}</Button>
-      )
+    if (hidden) return null
+
+    let label = ''
+    let icon = ''
+    let type = 'link'
+    let className = ''
+
+    if (btn.show === 'button') {
+      label = btn.label
+      icon = btn.icon || ''
+    } else if (btn.show === 'link') {
+      label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon}/> : ''}</span>
+      icon = ''
+    } else if (btn.show === 'icon') {
+      icon = btn.icon || ''
+    } else if (!btn.$toolbtn) {
+      icon = btn.icon || ''
+      label = btn.label
+      className = 'mk-btn mk-' + btn.class
+    } else {
+      type = ''
+      icon = btn.icon || ''
+      label = btn.label
+      className = 'mk-btn mk-' + btn.class
     }
+
+    return (
+      <Button
+        type={type}
+        title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')}
+        style={btn.style || null}
+        disabled={disabled}
+        icon={icon}
+        className={className}
+        onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
+      >{label}</Button>
+    )
   }
 }
 
-const mapStateToProps = (state) => {
-  return {
-    tabviews: state.tabviews,
-    permMenus: state.permMenus,
-  }
-}
-
-const mapDispatchToProps = (dispatch) => {
-  return {
-    modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews))
-  }
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(TabButton)
\ No newline at end of file
+export default TabButton
\ No newline at end of file

--
Gitblit v1.8.0