From 23cb54bbb041413ba327d046a4b396267ef2ecfe Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 13 一月 2021 19:31:56 +0800
Subject: [PATCH] 2021-01-13

---
 src/tabviews/custom/index.jsx |  108 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 102 insertions(+), 6 deletions(-)

diff --git a/src/tabviews/custom/index.jsx b/src/tabviews/custom/index.jsx
index 9c63e10..ac068c0 100644
--- a/src/tabviews/custom/index.jsx
+++ b/src/tabviews/custom/index.jsx
@@ -26,6 +26,7 @@
 const MainSearch = asyncComponent(() => import('@/tabviews/zshare/topSearch'))
 const NormalTable = asyncComponent(() => import('./components/table/normal-table'))
 const NormalGroup = asyncComponent(() => import('./components/group/normal-group'))
+const SettingComponent = asyncComponent(() => import('@/tabviews/zshare/settingcomponent'))
 const PagemsgComponent = asyncComponent(() => import('@/tabviews/zshare/pageMessage'))
 
 class CustomPage extends Component {
@@ -51,6 +52,7 @@
     loading: false,       // 鍒楄〃鏁版嵁鍔犺浇涓�
     visible: false,       // 鏍囩椤垫帶鍒�
     treevisible: false,   // 鑿滃崟缁撴瀯鏍戝脊妗嗘樉绀洪殣钘忔帶鍒�
+    shortcuts: null       // 蹇嵎閿�
   }
 
   /**
@@ -67,7 +69,7 @@
 
     if (result.status) {
       let config = ''
-      let userConfig = null
+      let shortcuts = []
 
       try { // 閰嶇疆淇℃伅瑙f瀽
         config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
@@ -79,10 +81,15 @@
       // HS涓嶄娇鐢ㄨ嚜瀹氫箟璁剧疆
       if (result.LongParamUser && this.props.menuType !== 'HS') {
         try { // 閰嶇疆淇℃伅瑙f瀽
-          userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser)))
+          let userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser)))
+          if (userConfig) {
+            shortcuts = userConfig.action
+            userConfig.printers.forEach(item => {
+              window.GLOB.UserCacheMap.set(item.parentId + item.uuid, item)
+            })
+          }
         } catch (e) {
           console.warn('Parse Failure')
-          userConfig = null
         }
       }
 
@@ -154,7 +161,7 @@
 
       this.setState({
         BID: BID,
-        userConfig: userConfig,
+        shortcuts,
         config,
         mainSearch
       }, () => {
@@ -167,6 +174,10 @@
         } else {
           this.loadmaindata(params)
         }
+
+        if (!this.props.Tab) {
+          this.setShortcut()
+        }
       })
     } else {
       this.setState({
@@ -177,6 +188,41 @@
         top: 92,
         message: result.message,
         duration: 5
+      })
+    }
+  }
+
+  setShortcut = () => {
+    const { shortcuts } = this.state
+
+    if (!shortcuts || shortcuts.length === 0) {
+      document.onkeydown = () => {}
+      return
+    }
+
+    document.onkeydown = (event) => {
+      let e = event || window.event
+      let keyCode = e.keyCode || e.which || e.charCode
+      let preKey = ''
+
+      if (e.ctrlKey) {
+        preKey = 'ctrl'
+      } else if (e.shiftKey) {
+        preKey = 'shift'
+      } else if (e.altKey) {
+        preKey = 'alt'
+      }
+
+      if (!preKey || !keyCode) return
+
+      let _shortcut = `${preKey}+${keyCode}`
+
+      shortcuts.some(item => {
+        if (item.$shortcut === _shortcut) {
+          MKEmitter.emit('triggerBtnId', item.uuid)
+          return true
+        }
+        return false
       })
     }
   }
@@ -260,6 +306,10 @@
           cell.$tabId = tabId
           cell.$type = 'CustomPage'
 
+          if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 鎵撳嵃鏈鸿缃�
+            cell = this.getPrinter(cell, item.uuid)
+          }
+
           return isHS || permAction[cell.uuid]
         })
       }
@@ -281,6 +331,10 @@
               cell.$menuId = item.uuid
               cell.$tabId = tabId
               cell.$type = 'CustomPage'
+
+              if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 鎵撳嵃鏈鸿缃�
+                cell = this.getPrinter(cell, item.uuid)
+              }
             } else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height && _hasheight) {
               cell.innerHeight = 'auto'
             }
@@ -296,6 +350,10 @@
               cell.$menuId = item.uuid
               cell.$tabId = tabId
               cell.$type = 'CustomPage'
+
+              if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 鎵撳嵃鏈鸿缃�
+                cell = this.getPrinter(cell, item.uuid)
+              }
             } else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height && _hasheight) {
               cell.innerHeight = 'auto'
             }
@@ -314,6 +372,10 @@
               cell.$menuId = item.uuid
               cell.$tabId = tabId
               cell.$type = 'CustomPage'
+
+              if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 鎵撳嵃鏈鸿缃�
+                cell = this.getPrinter(cell, item.uuid)
+              }
             } else if (['text', 'number', 'link'].includes(cell.eleType) && !cell.height && _hasheight) {
               cell.innerHeight = 'auto'
             }
@@ -331,6 +393,10 @@
             cell.$menuId = item.uuid
             cell.$tabId = tabId
             cell.$type = 'CustomPage'
+
+            if (cell.OpenType === 'funcbutton' && cell.funcType === 'print' && cell.verify) { // 鎵撳嵃鏈鸿缃�
+              cell = this.getPrinter(cell, item.uuid)
+            }
 
             return isHS || permAction[cell.uuid]
           })
@@ -355,6 +421,24 @@
       
       return true
     })
+  }
+
+  getPrinter = (item, parentId) => {
+    let _item = window.GLOB.UserCacheMap.get(parentId + item.uuid)
+
+    if (_item) {
+      item.printer = _item.printer || ''
+      item.verify.defaultPrinter = _item.printer || ''
+      if (item.verify.printerTypeList && _item.printerList) {
+        item.verify.printerTypeList = item.verify.printerTypeList.map(cell => {
+          cell.printer = _item.printerList[cell.Value] || ''
+
+          return cell
+        })
+      }
+    }
+
+    return item
   }
 
   getCols = (cols, roleId, permMenus) => {
@@ -620,6 +704,14 @@
     this.reloadview()
   }
 
+  resetActiveMenu = (menuId) => {
+    const { MenuID, Tab } = this.props
+
+    if (MenuID !== menuId || Tab) return
+
+    this.setShortcut()
+  }
+
   UNSAFE_componentWillMount () {
     // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁
     this.loadconfig()
@@ -631,6 +723,7 @@
 
   componentDidMount () {
     MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
+    MKEmitter.addListener('resetActiveMenu', this.resetActiveMenu)
   }
 
   /**
@@ -641,6 +734,7 @@
       return
     }
     MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
+    MKEmitter.removeListener('resetActiveMenu', this.resetActiveMenu)
   }
 
   reloadview = () => {
@@ -649,7 +743,8 @@
       loadingview: true,    // 椤甸潰鍔犺浇涓�
       viewlost: false,      // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤
       config: null,         // 椤甸潰閰嶇疆淇℃伅锛屽寘鎷粍浠剁瓑
-      loading: false        // 鍒楄〃鏁版嵁鍔犺浇涓�
+      loading: false,       // 鍒楄〃鏁版嵁鍔犺浇涓�
+      shortcuts: null
     }, () => {
       this.loadconfig()
     })
@@ -735,13 +830,14 @@
 
   render() {
     const { menuType } = this.props
-    const { loadingview, viewlost, config, loading } = this.state
+    const { loadingview, viewlost, config, loading, shortcuts } = this.state
 
     return (
       <div className={'custom-page-wrap ' + (loadingview || loading ? 'loading' : '')} id={this.state.ContainerId} style={config ? config.style : null}>
         {(loadingview || loading) ? <Spin className="view-spin" size="large" /> : null}
         <Row>{this.getComponents()}</Row>
         {menuType !== 'HS' ? <PagemsgComponent menu={{MenuName: this.props.MenuName, MenuNo: this.props.MenuNo}} config={config} dict={this.state.dict} /> : null}
+        {menuType !== 'HS' && shortcuts ? <SettingComponent config={config} dict={this.state.dict} shortcuts={shortcuts} permAction={this.props.permAction}/> : null}
         {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
       </div>
     )

--
Gitblit v1.8.0