From 191d6d48a282479c02ea212ca33789ad34137361 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 11 一月 2021 16:21:17 +0800
Subject: [PATCH] 2021-01-11

---
 src/tabviews/zshare/pageMessage/index.jsx |  346 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 335 insertions(+), 11 deletions(-)

diff --git a/src/tabviews/zshare/pageMessage/index.jsx b/src/tabviews/zshare/pageMessage/index.jsx
index 908815c..cd3d297 100644
--- a/src/tabviews/zshare/pageMessage/index.jsx
+++ b/src/tabviews/zshare/pageMessage/index.jsx
@@ -1,28 +1,352 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { Button } from 'antd'
+import { is, fromJS } from 'immutable'
+import { Button, Modal, Typography, Tree } from 'antd'
 
+import Api from '@/api'
+import Utils from '@/utils/utils.js'
 import options from '@/store/options.js'
+
+import './index.scss'
+
+const { TreeNode } = Tree
+const { Paragraph } = Typography
 
 class PageMessage extends Component {
   static propTpyes = {
     BID: PropTypes.any,          // 鐖剁骇Id锛岀敤浜庢煡璇笅鎷夐�夋嫨椤�
-    menuType: PropTypes.any,     // 鑿滃崟鏉冮檺锛屾槸鍚︿负HS
+    dict: PropTypes.object,      // 瀛楀吀
   }
 
   state = {
-    debug: sessionStorage.getItem('debug') === 'true'
+    debug: sessionStorage.getItem('debug') === 'true',
+    visible: false,
+    key: '',        // 鏇存柊鎸囬拡
+    data: []
   }
 
-  render() {
-    const { debug } = this.state
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.state), fromJS(nextState))
+  }
 
-    return (debug && options.sysType !== 'cloud' ? <Button
-      icon="copy"
-      shape="circle"
-      className="page-message"
-      onClick={this.handleviewconfig}
-    /> : null)
+  /**
+   * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
+   */
+  componentWillUnmount () {
+    this.setState = () => {
+      return
+    }
+  }
+
+  handleviewconfig = (e) => {
+    const { config } = this.props
+    let data = []
+    e.stopPropagation()
+
+    if (config.Template === 'CustomPage') {
+      data = this.getCusData(config)
+    } else {
+      data = this.getData(config)
+    }
+
+    this.setState({
+      visible: true,
+      data: data
+    })
+  }
+
+  getBtnCell = (cell, item) => {
+    let _cell = { uuid: cell.uuid, title: `鎸夐挳(${cell.label})锛歚 }
+    let _others = []
+    let tablename = cell.OpenType === 'excelIn' ? (cell.sheet || '') : (cell.sql || '')
+
+    if (cell.OpenType === 'excelOut' && cell.intertype === 'system') {
+      tablename = item.setting.tableName || ''
+    }
+    if (['pop', 'prompt', 'exec', 'excelIn', 'excelOut'].includes(cell.OpenType)) {
+      if (tablename) {
+        _others.push(`${tablename}(琛ㄥ悕)`)
+      }
+      if (cell.innerFunc) {
+        _others.push(`${cell.innerFunc}(鍐呴儴鍑芥暟)`)
+      }
+      if (cell.outerFunc) {
+        _others.push(`${cell.outerFunc}(澶栭儴鍑芥暟)`)
+      }
+    } else if (cell.OpenType === 'popview') {
+      _cell.sublist = []
+      Api.getLocalCacheConfig({
+        func: 'sPC_Get_LongParam',
+        MenuID: cell.uuid
+      }).then(res => {
+        if (res.LongParam) {
+          let _config
+          try { // 閰嶇疆淇℃伅瑙f瀽
+            _config = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
+          } catch (e) {
+            _config = ''
+          }
+
+          if (_config) {
+            _cell.sublist = this.getCusData(_config)
+            this.setState({key: cell.uuid})
+          }
+        }
+      })
+    }
+
+    _cell.title = _cell.title + _others.join('銆�')
+
+    return _cell
+  }
+
+  getCusData = (config) => {
+    let data = []
+    config.components.forEach(item => {
+      let _item = { uuid: item.uuid, title: item.name, sublist: [] }
+      if (item.type === 'tabs') {
+        item.subtabs.forEach(tab => {
+          let cell = { uuid: tab.uuid, title: tab.label }
+
+          cell.sublist = this.getCusData(tab)
+
+          _item.sublist.push(cell)
+        })
+      } else if (item.type === 'group') {
+        _item.sublist = this.getCusData(item)
+      } else if (item.type === 'search' || (item.type === 'card' && item.subtype === 'propcard' && item.wrap.datatype === 'static')) {
+        let cell = { uuid: Utils.getuuid(), title: '鏁版嵁婧愶細(鏃�)' }
+        _item.sublist.push(cell)
+      } else if (item.setting) {
+        let cell = { uuid: Utils.getuuid(), title: '鏁版嵁婧愶細' }
+        let _others = []
+
+        if (item.setting.tableName) {
+          _others.push(`${item.setting.tableName}(琛ㄥ悕)`)
+        }
+        if (item.setting.innerFunc) {
+          _others.push(`${item.setting.innerFunc}(鍐呴儴鍑芥暟)`)
+        }
+        if (item.setting.outerFunc) {
+          _others.push(`${item.setting.outerFunc}(澶栭儴鍑芥暟)`)
+        }
+        cell.title = cell.title + _others.join('銆�')
+
+        _item.sublist.push(cell)
+      }
+
+      if (item.action) {
+        item.action.forEach(cell => {
+          let _cell = this.getBtnCell(cell, item)
+          _item.sublist.push(_cell)
+        })
+      }
+
+      if (item.type === 'card' || (item.type === 'table' && item.subtype === 'tablecard')) {
+        item.subcards.forEach(card => {
+          card.elements && card.elements.forEach(cell => {
+            if (cell.eleType === 'button') {
+              let _cell = this.getBtnCell(cell, item)
+              _item.sublist.push(_cell)
+            }
+          })
+          card.backElements && card.backElements.forEach(cell => {
+            if (cell.eleType === 'button') {
+              let _cell = this.getBtnCell(cell, item)
+              _item.sublist.push(_cell)
+            }
+          })
+        })
+      } else if (item.type === 'table' && item.subtype === 'normaltable') {
+        item.cols.forEach(col => {
+          if (col.type !== 'action') return
+          col.elements = col.elements.forEach(cell => {
+            let _cell = this.getBtnCell(cell, item)
+            _item.sublist.push(_cell)
+          })
+        })
+      }
+
+      data.push(_item)
+    })
+
+    return data
+  }
+
+  getData = (config) => {
+    let data = []
+    let item = {uuid: Utils.getuuid(), title: '鏁版嵁婧愶細'}
+    let _others = []
+
+    if (config.Template === 'SubTable') {
+      if (config.tabNo) {
+        _others.push(`${config.tabNo}(鑿滃崟鍙傛暟)`)
+      }
+    }
+
+    if (config.setting.tableName) {
+      _others.push(`${config.setting.tableName}(琛ㄥ悕)`)
+    }
+    if (config.setting.innerFunc) {
+      _others.push(`${config.setting.innerFunc}(鍐呴儴鍑芥暟)`)
+    }
+    if (config.setting.outerFunc) {
+      _others.push(`${config.setting.outerFunc}(澶栭儴鍑芥暟)`)
+    }
+    item.title = item.title + _others.join('銆�')
+    data.push(item)
+
+    // 鎸夐挳
+    config.action && config.action.forEach(item => {
+      let _item = {uuid: Utils.getuuid(), title: `鎸夐挳(${item.label})锛歚}
+      let _others = []
+
+      let tablename = item.OpenType === 'excelIn' ? (item.sheet || '') : (item.sql || '')
+  
+      if (item.OpenType === 'excelOut' && item.intertype === 'system') {
+        tablename = config.setting.tableName || ''
+      }
+  
+      if (item.OpenType === 'popview') {
+        _item.sublist = []
+        Api.getLocalCacheConfig({
+          func: 'sPC_Get_LongParam',
+          MenuID: item.linkTab
+        }).then(res => {
+          if (res.LongParam) {
+            let _config
+            try { // 閰嶇疆淇℃伅瑙f瀽
+              _config = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
+            } catch (e) {
+              _config = ''
+            }
+
+            if (_config) {
+              _item.sublist = this.getData(_config)
+              this.setState({key: item.uuid})
+            }
+          }
+        })
+      } else if (['pop', 'prompt', 'exec', 'excelIn', 'excelOut'].includes(item.OpenType)) {
+        if (tablename) {
+          _others.push(`${tablename}(琛ㄥ悕)`)
+        }
+        if (item.innerFunc) {
+          _others.push(`${item.innerFunc}(鍐呴儴鍑芥暟)`)
+        }
+        if (item.outerFunc) {
+          _others.push(`${item.outerFunc}(澶栭儴鍑芥暟)`)
+        }
+      }
+      _item.title = _item.title + _others.join('銆�')
+      
+      data.push(_item)
+    })
+
+    // 鏍囩椤�
+    config.tabgroups && config.tabgroups.forEach(group => {
+      group.sublist.forEach(tab => {
+        let _item = {uuid: Utils.getuuid(), title: `鏍囩(${tab.label})锛歚, sublist: []}
+    
+        Api.getLocalCacheConfig({
+          func: 'sPC_Get_LongParam',
+          MenuID: tab.linkTab
+        }).then(res => {
+          if (res.LongParam) {
+            let _config
+            try { // 閰嶇疆淇℃伅瑙f瀽
+              _config = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
+            } catch (e) {
+              _config = ''
+            }
+
+            if (_config) {
+              _item.sublist = this.getData(_config)
+              this.setState({key: tab.uuid})
+            }
+          }
+        })
+
+        data.push(_item)
+      })
+    })
+
+    if (config.Template === 'CalendarPage' && config.tab) {
+      let _item = {uuid: Utils.getuuid(), title: `鏍囩(${config.tab.label})锛歚, sublist: []}
+    
+      Api.getLocalCacheConfig({
+        func: 'sPC_Get_LongParam',
+        MenuID: config.tab.linkTab
+      }).then(res => {
+        if (res.LongParam) {
+          let _config
+          try { // 閰嶇疆淇℃伅瑙f瀽
+            _config = JSON.parse(window.decodeURIComponent(window.atob(res.LongParam)))
+          } catch (e) {
+            _config = ''
+          }
+
+          if (_config) {
+            _item.sublist = this.getData(_config)
+            this.setState({key: config.tab.linkTab})
+          }
+        }
+      })
+
+      data.push(_item)
+    }
+
+    return data
+  }
+
+  getTreeNode = (data) => {
+    return data.map(item => {
+      if (item.sublist && item.sublist.length) {
+        return (
+          <TreeNode title={item.title} key={item.uuid} selectable={false}>
+            {this.getTreeNode(item.sublist)}
+          </TreeNode>
+        )
+      }
+      return <TreeNode key={item.uuid} title={item.title} isLeaf selectable={false} />
+    })
+  }
+
+
+  render() {
+    const { menu, dict } = this.props
+    const { debug, visible, data } = this.state
+
+    return (
+      <div className="page-message-wrap">
+        {debug && options.sysType !== 'cloud' ? <Button
+          icon="copy"
+          shape="circle"
+          className="page-message"
+          onClick={this.handleviewconfig}
+        /> : null}
+        <Modal
+          className="menu-tree-modal"
+          title={'鑿滃崟淇℃伅'}
+          width={'850px'}
+          maskClosable={false}
+          visible={visible}
+          onCancel={() => this.setState({visible: false})}
+          footer={[
+            <Button key="close" onClick={() => this.setState({visible: false})}>{dict['main.close']}</Button>
+          ]}
+          destroyOnClose
+        >
+          <div className="menu-header">
+            <span>鑿滃崟鍚嶇О锛歿menu.MenuName}</span>
+            {menu.MenuNo ? <span>鑿滃崟鍙傛暟锛�<Paragraph copyable>{menu.MenuNo}</Paragraph></span> : null}
+          </div>
+          {visible ? <Tree defaultExpandAll showLine={true}>
+            {this.getTreeNode(data)}
+          </Tree> : null}
+        </Modal>
+      </div>
+    )
   }
 }
 

--
Gitblit v1.8.0