From a24beb36feaa46f39cbb26ce5277e84f91241ce8 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 26 三月 2020 01:30:05 +0800
Subject: [PATCH] 2020-03-26

---
 src/tabviews/commontable/index.jsx |  202 ++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 152 insertions(+), 50 deletions(-)

diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx
index ca5f5ff..24c0f60 100644
--- a/src/tabviews/commontable/index.jsx
+++ b/src/tabviews/commontable/index.jsx
@@ -13,12 +13,14 @@
 import {refreshTabView, modifyTabview} from '@/store/action'
 
 import MainTable from '@/tabviews/zshare/normalTable'
-import MainAction from '@/tabviews/zshare/actionList'
-import VerifyCard from '@/tabviews/zshare/verifycard'
+// import MainAction from '@/tabviews/zshare/actionList'
+// import VerifyCard from '@/tabviews/zshare/verifycard'
 import MainSearch from '@/tabviews/zshare/topSearch'
 import NotFount from '@/components/404'
 import './index.scss'
 
+const VerifyCard = asyncLoadComponent(() => import('@/tabviews/zshare/verifycard'))
+const MainAction = asyncLoadComponent(() => import('@/tabviews/zshare/actionList'))
 const SubTable = asyncLoadComponent(() => import('@/tabviews/subtable'))
 const SubTabTable = asyncLoadComponent(() => import('@/tabviews/subtabtable'))
 const FormTab = asyncLoadComponent(() => import('@/tabviews/formtab'))
@@ -42,6 +44,8 @@
     viewlost: false,      // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤
     lostmsg: '',          // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅
     config: {},           // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷寜閽�佹悳绱€�佹樉绀哄垪銆佹爣绛剧瓑
+    userConfig: null,     // 鐢ㄦ埛鑷畾涔夎缃�
+    userParam: null,      // 淇濆瓨鐢ㄦ埛缂栬緫涓殑閰嶇疆
     searchlist: null,     // 鎼滅储鏉′欢
     actions: null,        // 鎸夐挳闆�
     columns: null,        // 鏄剧ず鍒�
@@ -65,7 +69,8 @@
     tabParam: null,       // 琛ㄥ崟鏍囩鍙傛暟
     refreshtabs: null,    // 闇�瑕佸埛鏂扮殑鏍囩闆�
     confirmLoading: false,// 鑷畾涔夎缃ā鎬佹鍔犺浇涓�
-    settingVisible: false // 鑷畾涔夎缃ā鎬佹
+    settingVisible: false,// 鑷畾涔夎缃ā鎬佹
+    triggerBtn: null      // 鐐瑰嚮琛ㄦ牸涓垨蹇嵎閿Е鍙戠殑鎸夐挳
   }
 
   /**
@@ -82,7 +87,8 @@
 
     if (result.status) {
       let config = ''
-      let userConfig = ''
+      let userConfig = null
+      let _curUserConfig = ''
 
       try { // 閰嶇疆淇℃伅瑙f瀽
         config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
@@ -94,9 +100,10 @@
       if (result.LongParamUser) {
         try { // 閰嶇疆淇℃伅瑙f瀽
           userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser)))
+          _curUserConfig = userConfig[this.props.MenuID]
         } catch (e) {
           console.warn('Parse Failure')
-          userConfig = ''
+          userConfig = null
         }
       }
 
@@ -156,16 +163,27 @@
         }
       })
 
-      if (userConfig) {
-        config.setting = {...config.setting, ...userConfig.setting}
-        let _actions = {}
-        userConfig.action.forEach(item => {
-          _actions[item.uuid] = item
-        })
+      if (_curUserConfig) {
+        config.setting = {...config.setting, ..._curUserConfig.setting}
 
         config.action = config.action.map(item => {
-          if (_actions[item.uuid]) {
-            item = {...item, ..._actions[item.uuid]}
+          if (item.execMode) {
+            item.OpenType = 'funcbutton'
+          }
+
+          if (_curUserConfig.action[item.uuid]) {
+            item = {...item, ..._curUserConfig.action[item.uuid]}
+          }
+          
+          if (item.OpenType === 'funcbutton' && item.funcType === 'print' && item.verify && item.printer) {
+            item.verify.defaultPrinter = item.printer.defaultPrinter || ''
+            if (item.verify.printerTypeList && item.printer.printerList) {
+              item.verify.printerTypeList = item.verify.printerTypeList.map(cell => {
+                cell.printer = item.printer.printerList[cell.Value] || ''
+
+                return cell
+              })
+            }
           }
 
           return item
@@ -199,7 +217,6 @@
           operations: _operations
         })
       }
-
 
       // 1銆佺瓫閫夊瓧娈甸泦锛�2銆佽繃婊ら殣钘忓垪鍙婂悎骞跺垪涓殑瀛楁uuid
       config.columns.forEach(col => {
@@ -242,9 +259,24 @@
         }
       })
 
+      if (_curUserConfig) {
+        _columns = _columns.map(item => {
+          if (_curUserConfig.columns[item.uuid]) {
+            item = {...item, ..._curUserConfig.columns[item.uuid]}
+          }
+
+          return item
+        })
+
+        _columns.sort((pre, next) => {
+          return pre.sort - next.sort
+        })
+      }
+
       this.setState({
         loadingview: false,
         config: config,
+        userConfig: userConfig,
         setting: config.setting,
         searchlist: config.search,
         actions: _actions,
@@ -273,8 +305,8 @@
   }
 
   setShortcut = () => {
-    const { actions } = this.state
-    if (!actions) return
+    const { actions, userConfig } = this.state
+    if (!userConfig) return
 
     document.onkeydown = (event) => {
       let e = event || window.event
@@ -288,8 +320,11 @@
       } else if (e.altKey) {
         preKey = 'alt'
       }
-      
+
+      if (!preKey) return
+
       let istrigger = false
+
       actions.forEach(item => {
         if (!item.shortcut || typeof(item.shortcut) !== 'object' || item.shortcut.length === 0 || istrigger) return
 
@@ -297,8 +332,43 @@
           e.preventDefault()
           istrigger = true
 
-          this.refs.mainButton.actionTrigger(item)
+          this.setState({
+            triggerBtn: {
+              uuid: new Date().getTime(),
+              parentId: this.props.MenuID,
+              button: item,
+              data: null
+            }
+          })
         }
+      })
+
+      if (istrigger) return
+
+      Object.keys(userConfig).forEach(key => {
+        if (key === this.props.MenuID || !userConfig[key].action || istrigger) return
+
+        let _actions = userConfig[key].action
+
+        Object.keys(_actions).forEach(btnkey => {
+          let item = _actions[btnkey]
+
+          if (!item.shortcut || typeof(item.shortcut) !== 'object' || item.shortcut.length === 0 || istrigger) return
+
+          if (preKey === item.shortcut[0] && keyCode === item.shortcut[1]) {
+            e.preventDefault()
+            istrigger = true
+
+            this.setState({
+              triggerBtn: {
+                uuid: new Date().getTime(),
+                parentId: key,
+                button: item,
+                data: null
+              }
+            })
+          }
+        })
       })
     }
   }
@@ -624,6 +694,8 @@
       viewlost: false,
       lostmsg: '',
       config: {},
+      userConfig: null,
+      userParam: null,
       searchlist: null,
       actions: null,
       columns: null,
@@ -734,7 +806,14 @@
    * @description 琛ㄦ牸涓紝鎸夐挳瑙﹀彂浜嬩欢浼犻��
    */
   buttonTrigger = (btn, record) => {
-    this.refs.mainButton.actionTrigger(btn, record)
+    this.setState({
+      triggerBtn: {
+        uuid: new Date().getTime(),
+        parentId: this.props.MenuID,
+        button: btn,
+        data: record
+      }
+    })
   }
 
   /**
@@ -906,39 +985,53 @@
     })
   }
 
-  settingSubmit = () => {
-    this.verifyRef.handleConfirm().then(res => {
-      let _LongParam = ''
+  changeMenuParam = (param) => {
+    this.setState({userParam: param})
+  }
 
-      try {
-        _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(res)))
-      } catch (e) {
+  settingSubmit = () => {
+    const { userParam } = this.state
+    let _LongParam = ''
+
+    try {
+      _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(userParam)))
+    } catch (e) {
+      notification.warning({
+        top: 92,
+        message: '缂栬瘧閿欒',
+        duration: 10
+      })
+      return
+    }
+
+    let param = {
+      func: 'sPC_TrdMenu_UserParam',
+      MenuID: this.props.MenuID,
+      LongParam: _LongParam
+    }
+
+    this.setState({
+      confirmLoading: true
+    })
+
+    Api.getSystemConfig(param).then(result => {
+      if (!result.status) {
+        this.setState({
+          confirmLoading: false
+        })
         notification.warning({
           top: 92,
-          message: '缂栬瘧閿欒',
+          message: result.message,
           duration: 10
         })
         return
       }
-
-      let param = {
-        func: 'sPC_TrdMenu_UserParam',
-        MenuID: this.props.MenuID,
-        LongParam: _LongParam
-      }
-
       this.setState({
-        confirmLoading: true
-      })
-
-      Api.getSystemConfig(param).then(result => {
-        this.setState({
-          settingVisible: false,
-          confirmLoading: false
-        }, () => {
-          window.GLOB.CacheMap = new Map()
-          this.reloadview()
-        })
+        settingVisible: false,
+        confirmLoading: false
+      }, () => {
+        window.GLOB.CacheMap = new Map()
+        this.reloadview()
       })
     })
   }
@@ -964,16 +1057,17 @@
   }
 
   /**
-   * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
+   * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊锛屾竻闄ゅ揩鎹烽敭璁剧疆
    */
   componentWillUnmount () {
     this.setState = () => {
       return
     }
+    document.onkeydown = () => {}
   }
 
   render() {
-    const { view, setting, searchlist, actions, columns, loadingview, viewlost, pickup, config } = this.state
+    const { view, setting, searchlist, actions, columns, loadingview, viewlost, pickup, config, triggerBtn, userConfig } = this.state
 
     return (
       <div>
@@ -990,12 +1084,12 @@
           {actions && setting.onload !== 'false' ?
             <div style={{minHeight: '25px'}}>
               <MainAction
-                ref="mainButton"
                 BID=""
                 type="main"
                 menuType="main"
                 setting={setting}
                 actions={actions}
+                triggerBtn={triggerBtn}
                 dict={this.state.dict}
                 MenuID={this.props.MenuID}
                 permRoles={this.props.permRoles}
@@ -1050,6 +1144,8 @@
                             Tab={_tab}
                             menuType="main"
                             MenuID={_tab.linkTab}
+                            userConfig={userConfig ? userConfig[_tab.linkTab] : null}
+                            triggerBtn={triggerBtn}
                             SupMenuID={this.props.MenuID}
                             refreshtabs={this.state.refreshtabs}
                             ContainerId={this.state.ContainerId}
@@ -1119,17 +1215,23 @@
             wrapClassName="common-table-custom-modal"
             title={'鑷畾涔夎缃�'}
             maskClosable={false}
-            width={850}
+            width={950}
             visible={this.state.settingVisible}
             onOk={this.settingSubmit}
             onCancel={() => { this.setState({ settingVisible: false }) }}
             confirmLoading={this.state.confirmLoading}
             destroyOnClose
           >
-            {this.state.config ?
+            {this.state.settingVisible ?
               <VerifyCard
+                MenuID={this.props.MenuID}
+                MenuName={this.props.MenuName}
+                permAction={this.props.permAction}
+                permRoles={this.props.permRoles}
                 config={this.state.config}
-                wrappedComponentRef={(inst) => this.verifyRef = inst}
+                userConfig={this.state.userConfig}
+                columns={this.state.columns}
+                handleParam={this.changeMenuParam}
               /> : null
             }
           </Modal>

--
Gitblit v1.8.0