From 4e570c993e66a47ead0f83de76b63b0a2f8c5446 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 05 六月 2023 17:28:16 +0800
Subject: [PATCH] 2023-06-05

---
 src/tabviews/zshare/actionList/excelInbutton/index.jsx |  357 ++++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 229 insertions(+), 128 deletions(-)

diff --git a/src/tabviews/zshare/actionList/excelInbutton/index.jsx b/src/tabviews/zshare/actionList/excelInbutton/index.jsx
index e943949..2abe56f 100644
--- a/src/tabviews/zshare/actionList/excelInbutton/index.jsx
+++ b/src/tabviews/zshare/actionList/excelInbutton/index.jsx
@@ -1,9 +1,8 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import moment from 'moment'
-import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { Button, Modal, notification, message, Icon } from 'antd'
+import { Button, Modal, notification, message } from 'antd'
 
 import ExcelIn from './excelin'
 import Utils, { getExcelInSql } from '@/utils/utils.js'
@@ -12,38 +11,37 @@
 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 ExcelInButton extends Component {
   static propTpyes = {
-    show: PropTypes.any,              // 鏄剧ず鏍峰紡
-    position: PropTypes.any,          // 鎸夐挳浣嶇疆锛屽伐鍏锋爮涓簍oolbar
     BID: PropTypes.string,            // 涓昏〃ID
+    BData: PropTypes.any,             // 涓昏〃鏁版嵁
     selectedData: PropTypes.any,      // 瀛愯〃涓�夋嫨鏁版嵁
-    Tab: PropTypes.any,               // 濡傛灉褰撳墠鍏冪礌涓烘爣绛炬椂锛宼ab涓烘爣绛句俊鎭�
     btn: PropTypes.object,            // 鎸夐挳
     setting: PropTypes.any,           // 椤甸潰閫氱敤璁剧疆
+    disabled: PropTypes.any,          // 琛屾寜閽鐢�
   }
 
   state = {
     dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     loading: false,
+    selines: null,
     disabled: false,
+    hidden: false,
     primaryId: '',
   }
 
   UNSAFE_componentWillMount () {
-    const { btn, selectedData } = this.props
-    let disabled = false
+    const { btn, selectedData, BData, disabled } = this.props
 
-    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})
+    if (btn.controlField) {
+      this.setStatus(btn, selectedData || [], BData, disabled)
+    } else if (disabled) {
+      this.setState({disabled: true})
     }
   }
 
@@ -52,28 +50,16 @@
   }
 
   componentDidMount () {
-    const { position } = this.props
-
-    if (position === 'toolbar') {
-      MKEmitter.addListener('triggerBtnId', this.actionTrigger)
-    }
+    MKEmitter.addListener('triggerBtnId', this.actionTrigger)
   }
 
   UNSAFE_componentWillReceiveProps (nextProps) {
-    const { btn, selectedData } = this.props
+    const { btn } = 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})
+    if (btn.controlField) {
+      this.setStatus(btn, nextProps.selectedData || [], nextProps.BData, nextProps.disabled)
+    } else {
+      this.setState({disabled: nextProps.disabled === true})
     }
   }
 
@@ -84,36 +70,61 @@
     MKEmitter.removeListener('triggerBtnId', this.actionTrigger)
   }
 
-  /**
-   * @description 鎸夐挳鐘舵�佹敼鍙�
-   */
-  updateStatus = (type) => {
-    if (type === 'start') {
-      this.setState({
-        loading: true
-      })
-    } else if (type === 'over') {
-      this.setState({
-        loading: false
-      })
+  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) || item.$lock) {
+            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, Tab, BID, btn, selectedData } = this.props
-    const { loading } = this.state
+  actionTrigger = (triggerId, record, type) => {
+    const { setting, BID, btn, selectedData } = 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 (((Tab && Tab.supMenu) || setting.supModule) && !BID) {
+    if (setting.supModule && !BID) {
       notification.warning({
         top: 92,
         message: '闇�瑕佷笂绾т富閿�硷紒',
         duration: 5
       })
+      return
+    } else if (type === 'linkbtn' && !btn.$toolbtn && !is(fromJS(selectedData || []), fromJS(record))) {
       return
     }
 
@@ -142,6 +153,7 @@
     }
 
     this.setState({
+      selines: data,
       primaryId: primaryId
     }, () => {
       this.refs.excelIn.exceltrigger()
@@ -163,7 +175,7 @@
   execSuccess = (res) => {
     const { btn } = this.props
 
-    if (res && res.ErrCode === 'S') { // 鎵ц鎴愬姛
+    if (res && (res.ErrCode === 'S' || !res.ErrCode)) { // 鎵ц鎴愬姛
       notification.success({
         top: 92,
         message: res.ErrMesg || this.state.dict['main.action.confirm.success'],
@@ -181,8 +193,28 @@
       loading: false
     })
 
-    if (btn.execSuccess !== 'never') {
-      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn)
+    if (btn.execSuccess === 'closepoptab') {
+      MKEmitter.emit('popclose')
+    } else if (btn.execSuccess !== 'never') {
+      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execSuccess, btn, '', this.state.selines)
+    }
+    
+    if (btn.syncComponentId) {
+      if (btn.syncComponentId === 'multiComponent') {
+        btn.syncComponentIds.forEach((id, i) => {
+          setTimeout(() => {
+            MKEmitter.emit('reloadData', id)
+          }, 20 * i)
+        })
+      } else {
+        MKEmitter.emit('reloadData', btn.syncComponentId)
+      }
+    }
+
+    if (btn.switchTab && btn.switchTab.length > 0) {
+      let id = btn.switchTab[btn.switchTab.length - 1]
+      let node = document.getElementById('tab' + id)
+      node && node.click()
     }
   }
 
@@ -220,8 +252,10 @@
       loading: false
     })
 
-    if (btn.execError !== 'never') {
-      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn)
+    if (btn.execError === 'closepoptab') {
+      MKEmitter.emit('popclose')
+    } else if (btn.execError !== 'never') {
+      MKEmitter.emit('refreshByButtonResult', btn.$menuId, btn.execError, btn, '', this.state.selines)
     }
   }
 
@@ -252,7 +286,7 @@
         })
       }
 
-      this.updateStatus('over')
+      this.setState({ loading: false })
       return
     }
 
@@ -262,7 +296,7 @@
         message: '鏈幏鍙栧埌宸ヤ綔琛ㄣ��' + sheetName + '銆嬫暟鎹紒',
         duration: 5
       })
-      this.updateStatus('over')
+      this.setState({ loading: false })
       return
     } else if (data.length * btn.verify.columns.length > 30000) {
       notification.warning({
@@ -272,7 +306,7 @@
       })
     }
 
-    let result = getExcelInSql(btn, data, this.state.dict, (this.props.BID || ''))
+    let result = getExcelInSql(btn, data, (this.props.BID || ''), this.state.primaryId)
 
     if (result.errors) {
       notification.warning({
@@ -280,7 +314,7 @@
         message: result.errors,
         duration: 5
       })
-      this.updateStatus('over')
+      this.setState({ loading: false })
       return
     }
 
@@ -308,25 +342,86 @@
       
       param.excel_in_type = 'true'
       param.LText1 = Utils.formatOptions(result.insert)
-      param.LText2 = Utils.formatOptions(result.bottom)
-      param.LText = Utils.formatOptions(result.sql)
       param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
+      param.LText2 = result.bottom
+      param.LText = result.sql
+
+      let unCheckParam = null
+
+      if (/\$check@|@check\$/ig.test(param.LText2) || /\$check@|@check\$/ig.test(param.LText)) {
+        unCheckParam = fromJS(param).toJS()
+        param.LText = param.LText.replace(/\$check@|@check\$/ig, '')
+        param.LText2 = param.LText2.replace(/\$check@|@check\$/ig, '')
+      }
+
+      param.LText2 = Utils.formatOptions(param.LText2)
+      param.LText = Utils.formatOptions(param.LText)
       param.secretkey = Utils.encrypt(param.LText, param.timestamp)
-      if (this.props.menuType === 'HS' && param.timestamp) { // 浜戠楠岃瘉
+      if (window.GLOB.mkHS && param.timestamp) { // 浜戠楠岃瘉
         param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp)
       }
 
       param.menuname = btn.logLabel
+      
+      if (window.GLOB.probation) {
+        param.s_debug_type = 'Y'
+      }
 
-      Api.genericInterface(param).then((res) => {
-        if (res.status) {
-          this.execSuccess(res)
-        } else {
-          this.execError(res)
+      if (unCheckParam) {
+        unCheckParam.LText = unCheckParam.LText.replace(/\$check@/ig, '/*').replace(/@check\$/ig, '*/')
+        unCheckParam.LText = Utils.formatOptions(unCheckParam.LText)
+        unCheckParam.LText2 = unCheckParam.LText2.replace(/\$check@/ig, '/*').replace(/@check\$/ig, '*/')
+        unCheckParam.LText2 = Utils.formatOptions(unCheckParam.LText2)
+
+        unCheckParam.secretkey = Utils.encrypt(unCheckParam.LText, unCheckParam.timestamp)
+
+        unCheckParam.menuname = btn.logLabel
+
+        if (window.GLOB.probation) {
+          unCheckParam.s_debug_type = 'Y'
         }
-      }, () => {
-        this.execError({})
-      })
+
+        Api.genericInterface(param).then(res => {
+          if (res.status) {
+            this.execSuccess(res)
+          } else if (res.ErrCode === 'C') {
+            const _this = this
+            confirm({
+              title: '缁х画鎵ц锛�',
+              content: res.message,
+              onOk() {
+                return new Promise(resolve => {
+                  Api.genericInterface(unCheckParam).then(result => {
+                    if (result.status) {
+                      _this.execSuccess(result)
+                    } else {
+                      _this.execError(result)
+                    }
+                    resolve()
+                  })
+                })
+              },
+              onCancel() {
+                _this.execError(res)
+              }
+            })
+          } else {
+            this.execError(res)
+          }
+        }, () => {
+          this.execError({})
+        })
+      } else {
+        Api.genericInterface(param).then((res) => {
+          if (res.status) {
+            this.execSuccess(res)
+          } else {
+            this.execError(res)
+          }
+        }, () => {
+          this.execError({})
+        })
+      }
     } else if (btn.intertype === 'inner' && btn.innerFunc) { // 鑷畾涔夊瓨鍌ㄨ繃绋�
       param.func = btn.innerFunc
 
@@ -341,6 +436,7 @@
       })
     } else if (btn.intertype === 'outer') { // 澶栭儴鎺ュ彛
       let _outParam = null
+      let ver_token = false
 
       new Promise(resolve => {
         // 鍐呴儴璇锋眰
@@ -375,9 +471,11 @@
         // 澶栭儴璇锋眰
         _outParam = fromJS(res).toJS()
 
-        if (this.props.menuType === 'HS') {
+        if (window.GLOB.mkHS) {
           if (btn.sysInterface === 'true' && options.cloudServiceApi) {
             param.rduri = options.cloudServiceApi
+            param.userid = sessionStorage.getItem('CloudUserID') || ''
+            param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
           } else if (btn.sysInterface !== 'true') {
             if (window.GLOB.systemType === 'production' && btn.proInterface) {
               param.rduri = btn.proInterface
@@ -386,13 +484,26 @@
             }
           }
         } else {
-          if (btn.sysInterface === 'true' && window.GLOB.mainSystemApi) {
-            param.rduri = window.GLOB.mainSystemApi
-          } else if (btn.sysInterface !== 'true') {
+          if (btn.sysInterface === 'true') {
+            if (window.GLOB.mainSystemApi) {
+              param.rduri = window.GLOB.mainSystemApi
+            }
+          } else if (btn.sysInterface === 'external') {
+            if (window.GLOB.systemType === 'production') {
+              param.$token = btn.exProInterface || ''
+            } else {
+              param.$token = btn.exInterface || ''
+            }
+            ver_token = true
+          } else {
             if (window.GLOB.systemType === 'production' && btn.proInterface) {
               param.rduri = btn.proInterface
             } else {
               param.rduri = btn.interface
+            }
+            let host = window.GLOB.baseurl.replace(/http(s):\/\//, '')
+            if (param.rduri.indexOf(host) === -1 && /\/dostars/.test(param.rduri)) {
+              param.$login = true
             }
           }
         }
@@ -401,7 +512,7 @@
           res.func = btn.outerFunc
         }
         
-        if (this.props.menuType === 'HS' && res.func === 's_sDataDictb_excelIn') { // s_sDataDictb_excelIn 浜戠楠岃瘉
+        if (window.GLOB.mkHS && res.func === 's_sDataDictb_excelIn') { // s_sDataDictb_excelIn 浜戠楠岃瘉
           param.LText = Utils.formatOptions(result.sql)
           param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
           param.secretkey = Utils.encrypt(param.LText, param.timestamp)
@@ -412,7 +523,9 @@
       }).then(response => {
         if (!response) return
         // 鍥炶皟璇锋眰
-        if (btn.callbackFunc) {
+        if (ver_token && response.ErrMesg === 'token_error') {
+          this.execError(response)
+        } else if (btn.callbackFunc ) {
           // 瀛樺湪鍥炶皟鍑芥暟鏃讹紝璋冪敤
           delete response.message
           delete response.status
@@ -441,61 +554,49 @@
   }
 
   render() {
-    const { btn, show } = this.props
-    const { loading, disabled } = this.state
+    const { btn } = this.props
+    const { loading, disabled, hidden } = this.state
 
-    if (show === 'actionList') {
-      return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}>
-        <Button
-          icon={btn.icon}
-          loading={loading}
-          disabled={disabled}
-          className={'mk-btn mk-' + btn.class}
-          onClick={() => {this.actionTrigger()}}
-        >{btn.label}</Button>
-        <ExcelIn btn={btn} triggerExcelIn={() => this.updateStatus('start')} returndata={this.getexceldata} ref="excelIn" />
-      </div>
-    } else { // icon銆乼ext銆� all 鍗$墖
-      let label = ''
-      let icon = ''
+    if (hidden) return null
 
-      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 || 'upload'
-      // } else if (show === 'text') {
-      } else {
-        label = btn.label
-      }
+    let label = ''
+    let icon = ''
+    let type = 'link'
+    let className = ''
 
-      return <div style={{display: 'inline-block'}} onClick={(e) => e.stopPropagation()}>
-        <Button
-          type="link"
-          title={show === 'icon' ? btn.label : ''}
-          loading={loading}
-          disabled={disabled}
-          style={btn.style}
-          icon={icon}
-          onClick={() => {this.actionTrigger()}}
-        >{label}</Button>
-        <ExcelIn btn={btn} triggerExcelIn={() => this.updateStatus('start')} returndata={this.getexceldata} ref="excelIn" />
-      </div>
+    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 || 'upload'
+    } 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 : '')}
+        loading={loading}
+        disabled={disabled}
+        style={btn.style}
+        icon={icon}
+        className={className}
+        onClick={(e) => {e.stopPropagation(); this.actionTrigger()}}
+      >{label}</Button>
+      <ExcelIn btn={btn} triggerExcelIn={() => this.setState({ loading: true })} returndata={this.getexceldata} ref="excelIn" />
+    </>
   }
 }
 
-const mapStateToProps = (state) => {
-  return {
-    menuType: state.editLevel
-  }
-}
-
-const mapDispatchToProps = () => {
-  return {}
-}
-
-export default connect(mapStateToProps, mapDispatchToProps)(ExcelInButton)
\ No newline at end of file
+export default ExcelInButton
\ No newline at end of file

--
Gitblit v1.8.0