From b69b5f6329ca5f87932436b7a6c1ddfc3377e10f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 16 五月 2024 10:56:41 +0800
Subject: [PATCH] 2024-05-16

---
 src/tabviews/zshare/actionList/changeuserbutton/index.jsx |  168 +++++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 119 insertions(+), 49 deletions(-)

diff --git a/src/tabviews/zshare/actionList/changeuserbutton/index.jsx b/src/tabviews/zshare/actionList/changeuserbutton/index.jsx
index 0dee01e..06cb05f 100644
--- a/src/tabviews/zshare/actionList/changeuserbutton/index.jsx
+++ b/src/tabviews/zshare/actionList/changeuserbutton/index.jsx
@@ -4,26 +4,37 @@
 import { Button, notification, Modal } from 'antd'
 
 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'
+import MkIcon from '@/components/mk-icon'
+// import './index.scss'
 
 const { confirm } = Modal
 
 class NewPageButton extends Component {
   static propTpyes = {
-    show: PropTypes.any,              // 鎸夐挳鏄剧ず鏍峰紡鎺у埗
-    position: PropTypes.any,          // 鎸夐挳浣嶇疆锛屽伐鍏锋爮涓簍oolbar
+    MenuID: PropTypes.any,            // 鑿滃崟ID
+    BData: PropTypes.any,             // 涓昏〃鏁版嵁
     BID: 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,
     loading: false
+  }
+
+  UNSAFE_componentWillMount () {
+    const { btn, selectedData, BData, disabled } = this.props
+
+    if (btn.controlField) {
+      this.setStatus(btn, selectedData || [], BData, disabled)
+    } else if (disabled) {
+      this.setState({disabled: true})
+    }
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -31,10 +42,16 @@
   }
 
   componentDidMount () {
-    const { position } = this.props
+    MKEmitter.addListener('triggerBtnId', this.actionTrigger)
+  }
 
-    if (position === 'toolbar') {
-      MKEmitter.addListener('triggerBtnId', this.actionTrigger)
+  UNSAFE_componentWillReceiveProps (nextProps) {
+    const { btn } = this.props
+
+    if (btn.controlField) {
+      this.setStatus(btn, nextProps.selectedData || [], nextProps.BData, nextProps.disabled)
+    } else {
+      this.setState({disabled: nextProps.disabled === true})
     }
   }
 
@@ -44,15 +61,63 @@
     }
     MKEmitter.removeListener('triggerBtnId', this.actionTrigger)
   }
+
+  setStatus = (btn, data, BData, disprop) => {
+    let disabled = false
+    let hidden = false
+
+    if (btn.control !== 'parent') {
+      if (data.length > 0) {
+        data.forEach(item => {
+          let s = item[btn.controlField] !== undefined ? item[btn.controlField] + '' : ''
+          if (btn.controlVals.includes(s)) {
+            disabled = true
+          }
+        })
+      } else if (btn.controlVals.includes('')) {
+        disabled = true
+      }
+    } else {
+      if (!BData || !BData.hasOwnProperty(btn.controlField)) {
+        hidden = true
+      } else {
+        let s = BData[btn.controlField] + ''
+        if (btn.controlVals.includes(s)) {
+          hidden = true
+        }
+      }
+    }
+
+    if (disabled && btn.control === 'hidden') {
+      hidden = true
+    }
+
+    if (disprop) {
+      disabled = true
+    }
+
+    this.setState({hidden, disabled})
+  }
   
   /**
    * @description 瑙﹀彂鎸夐挳鎿嶄綔
    */
-  actionTrigger = (triggerId, record) => {
-    const { setting, selectedData, btn } = this.props
-    const { loading } = this.state
+  actionTrigger = (triggerId, record, type, lid) => {
+    const { setting, selectedData, btn, MenuID, LID } = this.props
+    const { loading, disabled } = this.state
     
-    if ((triggerId && btn.uuid !== triggerId) || loading) return
+    if (loading || disabled) return
+    if (triggerId && btn.uuid !== triggerId) return
+    if (type === 'linkbtn' && !btn.$toolbtn && LID !== lid) return
+
+    if (btn.funcType === 'closetab') {
+      MKEmitter.emit('closeTabView', MenuID || btn.$MenuID)
+
+      if (btn.refreshTab && btn.refreshTab.length > 0) {
+        MKEmitter.emit('reloadMenuView', btn.refreshTab[btn.refreshTab.length - 1], 'table')
+      }
+      return
+    }
     
     let data = record || selectedData || []
 
@@ -60,15 +125,7 @@
       // 闇�瑕侀�夋嫨鍗曡鏃讹紝鏍¢獙鏁版嵁
       notification.warning({
         top: 92,
-        message: this.state.dict['main.action.confirm.selectSingleLine'],
-        duration: 5
-      })
-      return
-    } else if (!setting.primaryKey) {
-      // 闇�瑕侀�夋嫨琛屾椂锛屾牎楠屾槸鍚﹁缃富閿�
-      notification.warning({
-        top: 92,
-        message: '鏈缃富閿紒',
+        message: '璇烽�夋嫨鍗曡鏁版嵁锛�',
         duration: 5
       })
       return
@@ -88,7 +145,10 @@
     let _this = this
 
     let param = {
-      func: 'webapi_ChangeUser'
+      func: 'webapi_ChangeUser',
+      login_city: sessionStorage.getItem('city') || '',
+      login_id_address: sessionStorage.getItem('ipAddress') || '',
+      domain_name: window.btoa(window.encodeURIComponent(window.GLOB.host)),
     }
 
     if (this.props.BID) {
@@ -102,7 +162,7 @@
     param[setting.primaryKey] = primaryId
 
     confirm({
-      title: this.state.dict['main.action.confirm.tip'],
+      title: '纭畾瑕佹墽琛屽悧?',
       onOk() {
         return new Promise(resolve => {
           Api.genericInterface(param).then(res => {
@@ -114,10 +174,18 @@
               sessionStorage.setItem('Full_Name', res.FullName)
               sessionStorage.setItem('avatar', res.icon || '')
               sessionStorage.setItem('dataM', res.dataM ? 'true' : '')
-              sessionStorage.setItem('localDataM', res.dataM ? 'true' : '')
               sessionStorage.setItem('debug', res.debug || '')
               sessionStorage.setItem('role_id', res.role_id || '')
-              sessionStorage.setItem('localRole_id', res.role_id || '')
+              sessionStorage.setItem('departmentcode', res.departmentcode || '')
+              sessionStorage.setItem('organization', res.organization || '')
+              sessionStorage.setItem('mk_user_type', res.mk_user_type || '')
+
+              if (res.paas_externalDatabase) {
+                sessionStorage.setItem('externalDatabase', res.paas_externalDatabase)
+                window.GLOB.externalDatabase = `[${res.paas_externalDatabase}]..`
+              } else {
+                sessionStorage.removeItem('externalDatabase')
+              }
               
               sessionStorage.removeItem('CloudAvatar')
               sessionStorage.removeItem('cloudDataM')
@@ -130,7 +198,7 @@
             } else {
               notification.error({
                 top: 92,
-                message: res.message || res.ErrMesg,
+                message: res.message || '鎵ц澶辫触锛�',
                 duration: btn.verify && btn.verify.ntime ? btn.verify.ntime : 10
               })
               _this.setState({loading: false})
@@ -148,30 +216,32 @@
   }
 
   render() {
-    const { btn, show } = this.props
-    const { loading } = this.state
+    const { btn } = this.props
+    const { loading, disabled, hidden } = this.state
 
-    if (show === 'actionList') {
-      return (
-        <Button
-          icon={btn.icon}
-          loading={loading}
-          className={'mk-btn mk-' + btn.class}
-          onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
-        >{btn.label}</Button>
-      )
-    } else { // icon銆乼ext銆� all 鍗$墖
-      return (
-        <Button
-          type="link"
-          title={show === 'icon' ? btn.label : ''}
-          loading={loading}
-          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 = ''
+
+    if (btn.show === 'link') {
+      label = <span>{btn.label}{btn.icon ? <MkIcon style={{marginLeft: '8px'}} type={btn.icon} /> : ''}</span>
+    } else if (btn.show === 'icon') {
+      label = !loading ? <MkIcon type={btn.icon} /> : null
+    } else {
+      label = <span>{!loading && btn.icon ? <MkIcon style={{marginRight: '8px'}} type={btn.icon} /> : ''}{btn.label}</span>
     }
+
+    return (
+      <Button
+        type="link"
+        title={disabled ? (btn.reason || '') : (btn.show === 'icon' ? btn.label : '')}
+        loading={loading}
+        disabled={disabled}
+        style={btn.style}
+        className={btn.hover || ''}
+        onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
+      >{label}</Button>
+    )
   }
 }
 

--
Gitblit v1.8.0