From 8eb9303af35b6bee86daaa9ff478b623516fc183 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 16 三月 2020 11:49:29 +0800
Subject: [PATCH] 2020-03-16

---
 src/tabviews/commontable/index.jsx |  795 +++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 521 insertions(+), 274 deletions(-)

diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx
index 699a2b3..1d30b9b 100644
--- a/src/tabviews/commontable/index.jsx
+++ b/src/tabviews/commontable/index.jsx
@@ -2,23 +2,31 @@
 import PropTypes from 'prop-types'
 import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { BackTop, notification, Spin, Tabs, Icon, Switch, Modal, Button} from 'antd'
+import { notification, Spin, Tabs, Icon, Switch, Modal, Button, message, Tree, Typography } from 'antd'
 import moment from 'moment'
+
 import Api from '@/api'
-import MainTable from './mainTable'
-import MainAction from '@/tabviews/tableshare/actionList'
-import MainSearch from '@/tabviews/tableshare/topSearch'
-import SubTable from '@/tabviews/subtable'
-import NotFount from '@/components/404'
-import asyncComponent from '@/utils/asyncLoadComponent'
-import {refreshTabView, modifyTabview} from '@/store/action'
 import zhCN from '@/locales/zh-CN/main.js'
 import enUS from '@/locales/en-US/main.js'
 import Utils from '@/utils/utils.js'
+import asyncComponent from '@/utils/asyncComponent'
+import asyncLoadComponent from '@/utils/asyncLoadComponent'
+import {refreshTabView, modifyTabview} from '@/store/action'
+
+import MainTable from './mainTable'
+import VerifyCard from '@/tabviews/tableshare/verifycard'
+import MainSearch from '@/tabviews/tableshare/topSearch'
+import NotFount from '@/components/404'
 import './index.scss'
 
-const SubTabTable = asyncComponent(() => import('@/tabviews/subtabtable'))
+const MainAction = asyncComponent(() => import('@/tabviews/tableshare/actionList'))
+const SubTable = asyncLoadComponent(() => import('@/tabviews/subtable'))
+const SubTabTable = asyncLoadComponent(() => import('@/tabviews/subtabtable'))
+const FormTab = asyncLoadComponent(() => import('@/tabviews/formtab'))
+
 const { TabPane } = Tabs
+const { TreeNode } = Tree
+const { Paragraph } = Typography
 
 class NormalTable extends Component {
   static propTpyes = {
@@ -29,6 +37,8 @@
 
   state = {
     dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
+    ContainerId: Utils.getuuid(), // 鑿滃崟澶栧眰html Id
+    view: 'commontable',  // 褰撳墠椤甸潰榛樿涓轰富琛�
     loadingview: true,    // 椤甸潰鍔犺浇涓�
     viewlost: false,      // 椤甸潰涓㈠け锛�1銆佹湭鑾峰彇鍒伴厤缃�-椤甸潰涓㈠け锛�2銆侀〉闈㈡湭鍚敤
     lostmsg: '',          // 椤甸潰涓㈠け鏃剁殑鎻愮ず淇℃伅
@@ -36,6 +46,7 @@
     searchlist: null,     // 鎼滅储鏉′欢
     actions: null,        // 鎸夐挳闆�
     columns: null,        // 鏄剧ず鍒�
+    logcolumns: null,     // 鏃ュ織涓樉绀虹殑鍒椾俊鎭� (澧炲姞鑷冲叏閮ㄥ垪锛岄櫎鍘诲悎骞跺垪)
     arr_field: '',        // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆�
     setting: null,        // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑
     data: null,           // 鍒楄〃鏁版嵁闆�
@@ -43,17 +54,19 @@
     loading: false,       // 鍒楄〃鏁版嵁鍔犺浇涓�
     pageIndex: 1,         // 椤电爜
     pageSize: 10,         // 姣忛〉鏁版嵁鏉℃暟
-    orderColumn: '',      // 鎺掑簭瀛楁
-    orderType: 'asc',     // 鎺掑簭鏂瑰紡
+    orderBy: '',          // 鎺掑簭
     search: '',           // 鎼滅储鏉′欢鏁扮粍锛屼娇鐢ㄦ椂闇�鍒嗗満鏅鐞�
-    configMap: {},        // 椤甸潰閰嶇疆淇℃伅锛氫笅鎷夈�佹寜閽瓑
     BIDs: {},             // 涓婄骇琛╥d
-    setsingle: false,     // 涓昏〃鍗曢�夊閫夊垏鎹�
     pickup: false,        // 涓昏〃鏁版嵁闅愯棌鏄剧ず鍒囨崲
-    isLinkMain: false,    // 鏄惁瀛樺湪涓庝富琛ㄥ叧鑱旂殑瀛愯〃
     popAction: false,     // 寮规椤甸潰锛屾寜閽俊鎭�
     popData: false,       // 寮规椤甸潰锛屾墍閫夌殑琛ㄦ牸鏁版嵁
-    visible: false        // 寮规鏄剧ず闅愯棌鎺у埗
+    visible: false,       // 寮规鏄剧ず闅愯棌鎺у埗
+    treevisible: false,   // 鑿滃崟缁撴瀯鏍戝脊妗嗘樉绀洪殣钘忔帶鍒�
+    tabBtn: null,         // 琛ㄥ崟鏍囩鎸夐挳
+    tabParam: null,       // 琛ㄥ崟鏍囩鍙傛暟
+    refreshtabs: null,    // 闇�瑕佸埛鏂扮殑鏍囩闆�
+    confirmLoading: false,// 鑷畾涔夎缃ā鎬佹鍔犺浇涓�
+    settingVisible: false // 鑷畾涔夎缃ā鎬佹
   }
 
   /**
@@ -69,12 +82,22 @@
     let result = await Api.getSystemCacheConfig(param)
     if (result.status) {
       let config = ''
+      let userConfig = ''
 
       try { // 閰嶇疆淇℃伅瑙f瀽
-        config = window.decodeURIComponent(window.atob(result.LongParam))
-        config = JSON.parse(config)
+        config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
       } catch (e) {
+        console.warn('Parse Failure')
         config = ''
+      }
+      
+      if (result.LongParamUser) {
+        try { // 閰嶇疆淇℃伅瑙f瀽
+          userConfig = JSON.parse(window.decodeURIComponent(window.atob(result.LongParamUser)))
+        } catch (e) {
+          console.warn('Parse Failure')
+          userConfig = ''
+        }
       }
 
       // 椤甸潰閰嶇疆瑙f瀽閿欒鏃舵彁绀�
@@ -96,22 +119,69 @@
         return
       }
 
-      let _arrField = []     // 瀛楁闆�
-      let _columns = []      // 鏄剧ず鍒�
-      let _hideCol = []      // 闅愯棌鍙婂悎骞跺垪涓瓧娈电殑uuid闆�
-      let colMap = new Map()
-
       // 鏉冮檺杩囨护
       config.action = config.action.filter(item => permAction[item.uuid])
-      // config.tabgroups.forEach(group => {
-      //   if (!config[group]) return
-      //   config[group] = config[group].filter(tab => permAction[tab.uuid])
-      // })
+      config.tabgroups.forEach(group => {
+        if (!config[group]) return
+
+        config[group] = config[group].filter(tab => permAction[tab.linkTab])
+      })
+
+      if (userConfig) {
+        config.setting = {...config.setting, ...userConfig.setting}
+        let _actions = {}
+        userConfig.action.forEach(item => {
+          _actions[item.uuid] = item
+        })
+
+        config.action = config.action.map(item => {
+          if (_actions[item.uuid]) {
+            item = {...item, ..._actions[item.uuid]}
+          }
+
+          return item
+        })
+      }
+
+      let _arrField = []     // 瀛楁闆�
+      let _columns = []      // 鏄剧ず鍒�
+      let _logcolumns = []   // 鏃ュ織鏄剧ず鍒�
+      let _hideCol = []      // 闅愯棌鍙婂悎骞跺垪涓瓧娈电殑uuid闆�
+      let colMap = new Map() // 鐢ㄤ簬瀛楁杩囨护
+
+      let _actions = []     // 宸ュ叿鏍忔寜閽�
+      let _operations = []  // 鎿嶄綔鍒楁寜閽紙瀛樺湪鏃讹級
+
+      config.action.forEach(item => {
+        if (item.execMode) {
+          item.OpenType = 'funcbutton'
+        }
+
+        if (item.position === 'toolbar') {
+          _actions.push(item)
+        } else if (item.position === 'grid') {
+          _operations.push(item)
+        }
+      })
+
+      if (config.gridBtn && config.gridBtn.display && _operations.length > 0) {
+        _columns.push({
+          ...config.gridBtn,
+          operations: _operations
+        })
+      }
+
 
       // 1銆佺瓫閫夊瓧娈甸泦锛�2銆佽繃婊ら殣钘忓垪鍙婂悎骞跺垪涓殑瀛楁uuid
       config.columns.forEach(col => {
         if (col.field) {
           _arrField.push(col.field)
+
+          // if () { // 鏉冮檺榛戝悕鍗�
+          //   col.Hide = 'true'
+          // }
+
+          _logcolumns.push(col)
         }
         if (col.type === 'colspan' && col.sublist) { // 绛涢�夐殣钘忓垪
           _hideCol = _hideCol.concat(col.sublist)
@@ -140,39 +210,6 @@
         }
       })
 
-      let _actions = config.action.filter(item => item.position === 'toolbar') // 杩囨护宸ュ叿鏍忔寜閽�
-      let _operations = config.action.filter(item => item.position === 'grid') // 娣诲姞鎿嶄綔鍒楋紙瀛樺湪鏃讹級
-
-      if (config.gridBtn && config.gridBtn.display && _operations.length > 0) {
-        _columns.push({
-          ...config.gridBtn,
-          operations: _operations
-        })
-      }
-
-      
-      let _isLinkMain = false // 妫�鏌ユ槸鍚︽湁涓庝富琛ㄥ叧鑱旂殑瀛愯〃
-      let supmenus = {}
-      config.tabgroups.forEach(group => {
-        if (config[group] && config[group].length > 0) {
-          config[group] = config[group].map(tab => {
-            if (tab.subtabs && tab.subtabs.length > 0) {
-              tab.subtabs.forEach(id => {
-                supmenus[id] = tab.uuid
-              })
-            }
-            if (config.setting.subtabs.includes(tab.uuid)) {
-              tab.supMenu = 'mainTable'
-              _isLinkMain = true
-            } else if (supmenus[tab.uuid]) {
-              tab.supMenu = supmenus[tab.uuid]
-            }
-
-            return tab
-          })
-        }
-      })
-
       this.setState({
         loadingview: false,
         config: config,
@@ -180,18 +217,18 @@
         searchlist: config.search,
         actions: _actions,
         columns: _columns,
-        isLinkMain: _isLinkMain,
+        logcolumns: _logcolumns,
         arr_field: _arrField.join(','),
         search: Utils.initMainSearch(config.search) // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級
       }, () => {
         this.improveSearch()
-
         if (config.setting.onload !== 'false') { // 鍒濆鍖栧彲鍔犺浇
           this.setState({
             loading: true
           })
           this.loadmaindata()
         }
+        this.setShortcut()
       })
     } else {
       this.setState({
@@ -202,6 +239,36 @@
         top: 92,
         message: result.message,
         duration: 10
+      })
+    }
+  }
+
+  setShortcut = () => {
+    const { actions } = this.state
+    if (!actions) 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'
+      }
+      
+      let istrigger = false
+      actions.forEach(item => {
+        if (!item.shortcut || istrigger) return
+
+        if (preKey === item.shortcut && keyCode === item.shortcutkey) {
+          e.preventDefault()
+          istrigger = true
+          this.refs.mainButton.actionTrigger(item)
+        }
       })
     }
   }
@@ -225,6 +292,7 @@
       if (item.resourceType === '1' && item.dataSource) {
         let _option = Utils.getSelectQueryOptions(item)
         let _sql = Utils.formatOptions(_option.sql)
+        let isSSO = item.database === 'sso'
 
         let param = {
           func: 'sPC_Get_SelectedList',
@@ -237,7 +305,7 @@
         param.secretkey = Utils.encrypt(param.LText, param.timestamp)
 
         let defer = new Promise(resolve => {
-          Api.getSystemCacheConfig(param).then(res => {
+          Api.getSystemCacheConfig(param, isSSO).then(res => {
             res.search = item
             resolve(res)
           })
@@ -308,7 +376,7 @@
       pickup: false
     })
 
-    this.handleTableId('mainTable', '')
+    this.handleTableId('mainTable', '', '')
 
     if (!param) { // 鏈幏鍙栧弬鏁版椂锛屼笉鍙戣姹�
       return
@@ -344,22 +412,28 @@
    * @description 鑾峰彇鐢ㄦ埛鑷畾涔夊瓨鍌ㄨ繃绋嬩紶鍙�
    */
   getCustomParam = () => {
-    const { pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state
+    const { pageIndex, pageSize, orderBy, search, setting } = this.state
 
     let _search = Utils.formatCustomMainSearch(search)
 
     let param = {
       PageIndex: pageIndex,
       PageSize: pageSize,
-      OrderCol: orderColumn,
-      OrderType: orderType,
+      OrderCol: orderBy || setting.order,
       ..._search
     }
 
     if (setting.interType === 'inner') {
       param.func = setting.innerFunc
     } else {
-      param.rduri = setting.interface
+      if (setting.sysInterface === 'true') {
+        param.rduri = window.GLOB.mainSystemApi || window.GLOB.subSystemApi
+      } else {
+        param.rduri = setting.interface
+      }
+
+      param.appkey = window.GLOB.appkey || '' // 璋冪敤澶栭儴鎺ュ彛澧炲姞appkey
+
       if (setting.outerFunc) {
         param.func = setting.outerFunc
       }
@@ -372,7 +446,7 @@
    * @description 鑾峰彇绯荤粺瀛樺偍杩囩▼ sPC_Get_TableData 鐨勫弬鏁�
    */
   getDefaultParam = () => {
-    const { arr_field, pageIndex, pageSize, orderColumn, orderType, search, setting } = this.state
+    const { arr_field, pageIndex, pageSize, orderBy, search, setting } = this.state
 
     if (!arr_field) {
       notification.warning({
@@ -390,10 +464,11 @@
     let param = {
       func: 'sPC_Get_TableData',
       obj_name: 'data',
-      arr_field: arr_field
+      arr_field: arr_field,
+      appkey: window.GLOB.appkey || ''
     }
     
-    let orderBy = orderColumn ? (orderColumn + ' ' + orderType) : setting.order
+    let _orderBy = orderBy || setting.order
     let _dataresource = setting.dataresource
 
     if (/\s/.test(_dataresource)) {
@@ -426,7 +501,7 @@
       _search = ''
     }
 
-    let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${_dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows`
+    let LText = `select top ${pageSize} ${arr_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${_orderBy}) as rows from ${_dataresource} ${_search}) tmptable where rows > ${pageSize * (pageIndex - 1)} order by tmptable.rows`
     let DateCount = `select count(1) as total from ${_dataresource} ${_search}`
 
     param.LText = Utils.formatOptions(LText)
@@ -482,8 +557,7 @@
       loading: true,
       pageIndex: pagination.current,
       pageSize: pagination.pageSize,
-      orderColumn: sorter.field || this.state.setting.orderColumn,
-      orderType: sorter.order || 'asc'
+      orderBy: (sorter.field && sorter.order) ? `${sorter.field} ${sorter.order}` : ''
     }, () => {
       this.loadmaindata()
     })
@@ -507,6 +581,7 @@
    */
   reloadview = () => {
     this.setState({
+      view: 'commontable',
       loadingview: true,
       viewlost: false,
       lostmsg: '',
@@ -521,14 +596,10 @@
       loading: false,
       pageIndex: 1,
       pageSize: 10,
-      orderColumn: '',
-      orderType: 'asc',
+      orderBy: '',
       search: '',
-      configMap: {},
       BIDs: {},
-      setsingle: false,
-      pickup: false,
-      isLinkMain: false
+      pickup: false
     }, () => {
       this.loadconfig()
     })
@@ -541,80 +612,73 @@
     if (btn.execSuccess === 'grid' && type === 'success') {
       this.reloadtable()
     } else if (btn.execError === 'grid' && type === 'error') {
-      this.reloadview()
-    } else if (btn.execSuccess === 'view' && type === 'success') {
       this.reloadtable()
+    } else if (btn.execSuccess === 'view' && type === 'success') {
+      this.reloadview()
     } else if (btn.execError === 'view' && type === 'error') {
       this.reloadview()
     } else if (btn.popClose === 'view' && type === 'pop') {
       this.reloadview()
     } else if (btn.popClose === 'grid' && type === 'pop') {
       this.reloadtable()
-    } else if (type === 'excelOut') {
-      this.handleDefaultExcelout(btn)
     }
+  }
+
+  /**
+   * @description 琛ㄥ崟鎿嶄綔瀹屾垚鍚庡埛鏂颁富椤甸潰
+   */
+  refreshbyformtab = (type) => {
+    this.setState({
+      view: 'commontable',
+      tabBtn: null,
+      tabParam: null
+    }, () => {
+      if (type === 'grid') {
+        this.reloadtable()
+      } else if (type === 'view') {
+        this.reloadview()
+      }
+    })
   }
 
   /**
    * @description 瀛愯〃鎿嶄綔瀹屾垚鍚庡埛鏂颁富琛�
    */
-  handleMainTable = () => {
-    this.reloadtable()
+  handleMainTable = (type, tab) => {
+    if (type === 'maingrid' && tab.supMenu === 'mainTable') {
+      this.reloadtable()
+    } else if (type === 'maingrid' && tab.supMenu) {
+      this.setState({
+        refreshtabs: [tab.supMenu]
+      }, () => {
+        this.setState({
+          refreshtabs: null
+        })
+      })
+    } else if (type === 'equaltab' && tab.equalTab && tab.equalTab.length > 0) {
+      this.setState({
+        refreshtabs: tab.equalTab
+      }, () => {
+        this.setState({
+          refreshtabs: null
+        })
+      })
+    }
   }
 
   /**
-   * @description 浣跨敤榛樿瀛樺偍杩囩▼ sPC_Get_TableData 瀵煎嚭excel琛ㄦ牸
+   * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁�
    */
-  handleDefaultExcelout = (btn) => {
+  getexceloutparam = () => {
     const { MenuName } = this.props
-    const { arr_field, orderColumn, orderType, search, setting, config } = this.state
+    const { arr_field, orderBy, search, setting} = this.state
 
-    let _arr_labels = []      // 鍒楀悕绉伴泦
-    let _arr_label_field = [] // 鍒楀悕绉板瓧娈甸泦
-
-    config.columns.forEach(col => {
-      if (col.field) {
-        _arr_labels.push(col.label)
-        _arr_label_field.push(`${col.field} as ${col.label}`)
-      }
-    })
-
-    _arr_labels = _arr_labels.join(',')
-    _arr_label_field = _arr_label_field.join(',')
-
-    let _search = Utils.joinMainSearchkey(search)
-    _search = _search ? 'where ' + _search : ''
-
-    // 鑾峰彇excel鏁版嵁锛屼笌鑾峰彇鍒楄〃鏁版嵁涓嶅悓涓烘湭璁剧疆椤电爜绛夊弬鏁�
-    let param = {
-      func: 'sPC_Get_TableData',
-      obj_name: 'data',
-      arr_field: _arr_labels
+    return {
+      arr_field: arr_field,
+      orderBy: orderBy || setting.order,
+      search: search,
+      menuName: MenuName
     }
-
-    let orderBy = orderColumn ? (orderColumn + ' ' + orderType) : setting.order
-    let _dataresource = setting.dataresource
-
-    if (/\s/.test(_dataresource)) {
-      _dataresource = '(' + _dataresource + ') tb'
-    }
-
-    let LText = `select ${_arr_label_field} from (select ${arr_field} ,ROW_NUMBER() over(order by ${orderBy}) as rows from ${_dataresource} ${_search}) tmptable order by tmptable.rows`
-
-    param.LText = Utils.formatOptions(LText)
-    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
-    param.secretkey = Utils.encrypt(param.LText, param.timestamp)
-    param.DateCount = ''
-
-    let name = `${MenuName}${moment().format('YYYYMMDDHHmmss')}.xlsx`
-
-    Api.getExcelOut(param, name).then(res => {
-      if (res && res.status === false) {
-        this.refs.mainButton.execError(res, btn)
-      } else {
-        this.refs.mainButton.execSuccess(btn)
-      }
-    })
   }
 
   /**
@@ -638,30 +702,15 @@
   /**
    * @description 琛ㄦ牸Id鍙樺寲
    */
-  handleTableId = (type, id) => {
+  handleTableId = (type, id, data) => {
     const { BIDs } = this.state
 
     this.setState({
       BIDs: {
         ...BIDs,
-        [type]: id
+        [type]: id,
+        [type + 'data']: data
       }
-    })
-  }
-
-  /**
-   * @description 琛ㄦ牸鍗曢�夊閫夊垏鎹�
-   */
-  checkChange = () => {
-    const { setsingle, BIDs } = this.state
-
-    let _BIDs = JSON.parse(JSON.stringify(BIDs))
-    _BIDs.mainTable = ''
-
-    this.setState({
-      setsingle: !setsingle,
-      pickup: false,
-      BIDs: _BIDs
     })
   }
   
@@ -679,39 +728,70 @@
    * @description 瑙﹀彂鎸夐挳寮圭獥锛堟爣绛鹃〉锛�
    */
   triggerPopview = (btn, data) => {
+    const { setting } = this.state
+
+    let _primaryId = ''
+
+    if (data && data[0] && setting.primaryKey) {
+      _primaryId = data[0][setting.primaryKey] || ''
+    }
+
     if (btn.OpenType === 'popview') {
       this.setState({
         popAction: btn,
-        popData: data[0] ? data[0] : null,
+        popData: data[0] || null,
         visible: true
       })
     } else if (btn.OpenType === 'tab') {
-      // const { tabviews, MenuNo, MenuID } = this.props
-      // let newtab = {
-      //   MenuNo: MenuNo,
-      //   MenuID: btn.uuid,
-      //   MenuName: btn.label,
-      //   type: btn.tabTemplate,
-      //   selected: true,
-      //   param: {
-      //     btn: btn,
-      //     data: data
-      //   }
-      // }
+      const { tabviews, MenuNo, MenuID } = this.props
+      let newtab = {
+        MenuNo: MenuNo,
+        MenuID: btn.uuid,
+        MenuName: btn.label,
+        type: btn.tabTemplate,
+        selected: true,
+        param: {
+          menuType: 'main',
+          parentId: this.props.MenuID,
+          btn: btn,
+          data: data[0] || null,
+          primaryId: btn.Ot !== 'notRequired' ? _primaryId : '',
+          arr_field: this.state.arr_field
+        }
+      }
 
-      // let index = 0
-      // let tabs = tabviews.map((tab, i) => {
-      //   if (tab.MenuID === MenuID) {
-      //     index = i
-      //   }
-      //   tab.selected = false
+      let index = 0
+      let isexit = false
+      let tabs = tabviews.map((tab, i) => {
+        tab.selected = false
 
-      //   return tab
-      // })
+        if (tab.MenuID === MenuID) {
+          index = i
+        } else if (tab.MenuID === btn.uuid) {
+          tab.selected = true
+          isexit = true
+        }
 
-      // tabs.splice(index + 1, 0, newtab)
-      
-      // this.props.modifyTabview(tabs)
+        return tab
+      })
+
+      if (!isexit) {
+        tabs.splice(index + 1, 0, newtab)
+      }
+
+      this.props.modifyTabview(tabs)
+    } else if (btn.OpenType === 'blank') {
+      this.setState({
+        view: 'formtab',
+        tabBtn: btn,
+        tabParam: {
+          menuType: 'main',
+          btn: btn,
+          data: data[0] || null,
+          primaryId: btn.Ot !== 'notRequired' ? _primaryId : '',
+          arr_field: this.state.arr_field
+        }
+      })
     }
   }
 
@@ -722,9 +802,120 @@
     this.refreshbyaction(this.state.popAction, 'pop')
   }
 
+  handleviewconfig = (e) => {
+    e.stopPropagation()
+
+    const { MenuNo } = this.props
+    const { config } = this.state
+
+    if (config && config.funcs && config.funcs.length > 0) {
+      this.setState({
+        treevisible: true
+      })
+    } else {
+      let oInput = document.createElement('input')
+      oInput.value = MenuNo || ''
+      document.body.appendChild(oInput)
+      oInput.select()
+      document.execCommand('Copy')
+      document.body.removeChild(oInput)
+      message.success(this.state.dict['main.copy.success'])
+    }
+  }
+
+  getTreeNode = (data) => {
+    let _type = {
+      view: '椤甸潰',
+      btn: '鎸夐挳',
+      tab: '鏍囩'
+    }
+
+    return data.map(item => {
+      let _title = _type[item.subtype]
+      let _others = []
+
+      _others.push(
+        (item.menuNo ? item.menuNo + '(鑿滃崟鍙傛暟)' : ''),
+        (item.tableName ? item.tableName + '(琛ㄥ悕) ' : ''),
+        (item.innerFunc ? item.innerFunc + '(鍐呴儴鍑芥暟) ' : ''),
+        (item.outerFunc ? item.outerFunc + '(澶栭儴鍑芥暟)' : '')
+      )
+      _others = _others.filter(Boolean)
+      _others = _others.join('銆�')
+
+      if (item.label) {
+        _title = _title + '(' + item.label + ')'
+      }
+      if (_others) {
+        _title = _title + ': ' + _others
+      }
+
+      if (item.subfuncs && item.subfuncs.length > 0) {
+        return (
+          <TreeNode title={_title} key={item.uuid} dataRef={item} selectable={false}>
+            {this.getTreeNode(item.subfuncs)}
+          </TreeNode>
+        )
+      }
+      return <TreeNode key={item.uuid} title={_title} isLeaf selectable={false} />
+    })
+  }
+
+  controlCustomSetting = () => {
+    this.setState({
+      settingVisible: true,
+      confirmLoading: false
+    })
+  }
+
+  settingSubmit = () => {
+    this.verifyRef.handleConfirm().then(res => {
+      let _LongParam = ''
+
+      try {
+        _LongParam = window.btoa(window.encodeURIComponent(JSON.stringify(res)))
+      } 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 => {
+        this.setState({
+          settingVisible: false,
+          confirmLoading: false
+        })
+      })
+    })
+  }
+
   UNSAFE_componentWillMount () {
     // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁
     this.loadconfig()
+  }
+
+  UNSAFE_componentWillReceiveProps(nextProps) {
+    if (nextProps.refreshTab && nextProps.refreshTab.MenuID === this.props.MenuID) {
+      if (nextProps.refreshTab.position === 'grid') {
+        this.reloadtable()
+      } else if (nextProps.refreshTab.position === 'view') {
+        this.reloadview()
+      }
+      this.props.refreshTabView('')
+    }
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -741,110 +932,166 @@
   }
 
   render() {
-    const { setting, searchlist, actions, columns, loadingview, viewlost, setsingle, pickup, isLinkMain, config } = this.state
+    const { view, setting, searchlist, actions, columns, loadingview, viewlost, pickup, config } = this.state
 
     return (
-      <div className={'commontable ' + (isLinkMain ? 'pick-control' : '')} id={'commontable' + this.props.MenuID}>
-        {loadingview && <Spin size="large" />}
-        {searchlist && searchlist.length > 0 ?
-          <MainSearch
-            dict={this.state.dict}
-            searchlist={searchlist}
-            refreshdata={this.refreshbysearch}
-          /> : null
-        }
-        {actions && setting.onload !== 'false' ?
-          <MainAction
-            ref="mainButton"
-            BID=""
-            type="main"
-            setting={setting}
-            actions={actions}
-            dict={this.state.dict}
-            MenuID={this.props.MenuID}
-            refreshdata={this.refreshbyaction}
-            triggerPopview={this.triggerPopview}
-            gettableselected={this.gettableselected}
-          /> : null
-        }
-        {columns && setting.onload !== 'false' ?
-          <div className="main-table-box">
-            {isLinkMain ?
-              <div className="pickchange">
-                {setting.tableType === 'checkbox' ? <Switch title="鍗曢�夊垏鎹�" checkedChildren="鍗�" unCheckedChildren="澶�" defaultChecked={setsingle} onChange={this.checkChange} /> : null}
-                {this.state.BIDs.mainTable && (setting.tableType === 'radio' || setsingle) ? <Switch title="鏀惰捣" checkedChildren="寮�" unCheckedChildren="鍏�" defaultChecked={pickup} onChange={this.pickupChange} /> : null}
-              </div> : null
-            }
-            <MainTable
-              ref="mainTable"
-              pickup={pickup}
-              setting={setting}
-              columns={columns}
-              setsingle={setsingle}
+      <div>
+        {view === 'commontable' ? <div className="commontable pick-control" id={this.state.ContainerId}>
+          {loadingview && <Spin size="large" />}
+          {searchlist && searchlist.length > 0 ?
+            <MainSearch
               dict={this.state.dict}
-              data={this.state.data}
-              total={this.state.total}
-              MenuID={this.props.MenuID}
-              loading={this.state.loading}
-              refreshdata={this.refreshbytable}
-              buttonTrigger={this.buttonTrigger}
-              handleTableId={this.handleTableId}
-            />
-          </div> : null
-        }
-        {setting && setting.onload !== 'false' &&
-          config.tabgroups.map(group => {
-            if (config[group].length === 0) return null
+              searchlist={searchlist}
+              refreshdata={this.refreshbysearch}
+            /> : null
+          }
+          {actions && setting.onload !== 'false' ?
+            <div style={{minHeight: '45px'}}>
+              <MainAction
+                ref="mainButton"
+                BID=""
+                type="main"
+                menuType="main"
+                setting={setting}
+                actions={actions}
+                dict={this.state.dict}
+                MenuID={this.props.MenuID}
+                logcolumns={this.state.logcolumns}
+                ContainerId={this.state.ContainerId}
+                refreshdata={this.refreshbyaction}
+                triggerPopview={this.triggerPopview}
+                getexceloutparam={this.getexceloutparam}
+                gettableselected={this.gettableselected}
+              />
+            </div> : null
+          }
+          {columns && setting.onload !== 'false' ?
+            <div className="main-table-box">
+              <Icon className="custom-control" type="setting" onClick={this.controlCustomSetting} />
+              {this.state.data && this.state.data.length > 0 ?
+                <Switch title="鏀惰捣" className="main-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" defaultChecked={pickup} onChange={this.pickupChange} /> : null
+              }
+              <MainTable
+                ref="mainTable"
+                pickup={pickup}
+                setting={setting}
+                columns={columns}
+                dict={this.state.dict}
+                data={this.state.data}
+                total={this.state.total}
+                MenuID={this.props.MenuID}
+                loading={this.state.loading}
+                refreshdata={this.refreshbytable}
+                buttonTrigger={this.buttonTrigger}
+                handleTableId={this.handleTableId}
+              />
+            </div> : null
+          }
+          {setting && setting.onload !== 'false' &&
+            config.tabgroups.map(group => {
+              if (config[group].length === 0) return null
 
-            return (
-              <Tabs defaultActiveKey="0" key={group}>
-                {config[group].map((_tab, index) => {
-                  // return !_tab.supMenu || (_tab.supMenu && this.state.BIDs[_tab.supMenu]) ?
-                  return (
-                    <TabPane tab={
-                      <span>
-                        {_tab.icon ? <Icon type={_tab.icon} /> : null}
-                        {_tab.label}
-                      </span>
-                    } key={`${index}`}>
-                      {_tab.type === 'SubTable' ?
-                        <SubTable
-                          Tab={_tab}
-                          MenuID={_tab.linkTab}
-                          SupMenuID={this.props.MenuID}
-                          BID={this.state.BIDs[_tab.supMenu] || ''}
-                          handleTableId={this.handleTableId}
-                          handleMainTable={this.handleMainTable}
-                        /> : null}
-                    </TabPane>
-                  )
-                })}
-              </Tabs>
-            )
-          })
-        }
-        <Modal
-          className="popview-modal"
-          title={this.state.popAction.label}
-          width={'80vw'}
-          maskClosable={false}
-          visible={this.state.visible}
-          onCancel={this.popclose}
-          footer={[
-            <Button key="cancel" onClick={this.popclose}>{this.state.dict['main.close']}</Button>
-          ]}
-          destroyOnClose
-        >
-          {<SubTabTable SupMenuID={this.props.MenuID} MenuID={this.state.popAction.linkTab} BID={''} ID={this.state.popData ? this.state.popData[setting.primaryKey] : ''} />}
-        </Modal>
-        <BackTop>
-          <div className="ant-back-top">
-            <div className="ant-back-top-content">
-              <div className="ant-back-top-icon"></div>
+              return (
+                <Tabs defaultActiveKey="0" key={group}>
+                  {config[group].map((_tab, index) => {
+                    return (
+                      <TabPane tab={
+                        <span>
+                          {_tab.icon ? <Icon type={_tab.icon} /> : null}
+                          {_tab.label}
+                        </span>
+                      } key={`${index}`}>
+                        {_tab.type === 'SubTable' ?
+                          <SubTable
+                            Tab={_tab}
+                            menuType="main"
+                            MenuID={_tab.linkTab}
+                            SupMenuID={this.props.MenuID}
+                            refreshtabs={this.state.refreshtabs}
+                            ContainerId={this.state.ContainerId}
+                            BID={this.state.BIDs[_tab.supMenu] || ''}
+                            BData={this.state.BIDs[_tab.supMenu + 'data'] || ''}
+                            handleTableId={this.handleTableId}
+                            handleMainTable={(type) => this.handleMainTable(type, _tab)}
+                          /> : null}
+                      </TabPane>
+                    )
+                  })}
+                </Tabs>
+              )
+            })
+          }
+          <Button
+            icon="copy"
+            shape="circle"
+            className="common-table-copy"
+            onClick={this.handleviewconfig}
+          />
+          <Modal
+            className="popview-modal"
+            title={this.state.popAction.label}
+            width={'80vw'}
+            maskClosable={false}
+            visible={this.state.visible}
+            onCancel={this.popclose}
+            footer={[
+              <Button key="close" onClick={this.popclose}>{this.state.dict['main.close']}</Button>
+            ]}
+            destroyOnClose
+          >
+            {<SubTabTable 
+              BID={''}
+              menuType="main"
+              SupMenuID={this.props.MenuID}
+              MenuID={this.state.popAction.linkTab}
+              BData={this.state.BIDs['mainTabledata'] || ''}
+              ContainerId={this.state.ContainerId}
+              ID={this.state.popData ? this.state.popData[setting.primaryKey] : ''}
+              refreshSupView={this.reloadtable}
+            />}
+          </Modal>
+          <Modal
+            className="menu-tree-modal"
+            title={'鑿滃崟缁撴瀯鏍�'}
+            width={'650px'}
+            maskClosable={false}
+            visible={this.state.treevisible}
+            onCancel={() => this.setState({treevisible: false})}
+            footer={[
+              <Button key="close" onClick={() => this.setState({treevisible: false})}>{this.state.dict['main.close']}</Button>
+            ]}
+            destroyOnClose
+          >
+            <div className="menu-header">
+              <span>鑿滃崟鍚嶇О锛歿this.props.MenuName}</span>
+              <span>鑿滃崟鍙傛暟锛歿<Paragraph copyable>{this.props.MenuNo}</Paragraph>}</span>
             </div>
-          </div>
-        </BackTop>
-        {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
+            {this.state.treevisible ? <Tree defaultExpandAll showLine={true}>
+              {this.getTreeNode(config.funcs)}
+            </Tree> : null}
+          </Modal>
+          {/* 鎸夐挳浣跨敤绯荤粺瀛樺偍杩囩▼鏃讹紝楠岃瘉淇℃伅妯℃�佹 */}
+          <Modal
+            wrapClassName="common-table-custom-modal"
+            title={'鑷畾涔夎缃�'}
+            maskClosable={false}
+            width={850}
+            visible={this.state.settingVisible}
+            onOk={this.settingSubmit}
+            onCancel={() => { this.setState({ settingVisible: false }) }}
+            confirmLoading={this.state.confirmLoading}
+            destroyOnClose
+          >
+            {this.state.config ?
+              <VerifyCard
+                config={this.state.config}
+                wrappedComponentRef={(inst) => this.verifyRef = inst}
+              /> : null
+            }
+          </Modal>
+          {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
+        </div> : null}
+        {view === 'formtab' ? <FormTab MenuID={this.state.tabBtn.uuid} param={this.state.tabParam} refresh={this.refreshbyformtab}/> : null}
       </div>
     )
   }

--
Gitblit v1.8.0