From 5d41cbe3722ff40b65bfa4de82d62a79f171f5a5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 15 八月 2022 17:41:55 +0800
Subject: [PATCH] 2022-08-15

---
 src/tabviews/custom/components/tree/antd-tree/index.jsx |   91 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 69 insertions(+), 22 deletions(-)

diff --git a/src/tabviews/custom/components/tree/antd-tree/index.jsx b/src/tabviews/custom/components/tree/antd-tree/index.jsx
index 9788af1..6b82284 100644
--- a/src/tabviews/custom/components/tree/antd-tree/index.jsx
+++ b/src/tabviews/custom/components/tree/antd-tree/index.jsx
@@ -16,11 +16,9 @@
 
 class NormalTree extends Component {
   static propTpyes = {
-    BID: PropTypes.any,              // 鐖剁骇Id
     data: PropTypes.array,           // 缁熶竴鏌ヨ鏁版嵁
     config: PropTypes.object,        // 缁勪欢閰嶇疆淇℃伅
     mainSearch: PropTypes.any,       // 澶栧眰鎼滅储鏉′欢
-    menuType: PropTypes.any,         // 鑿滃崟绫诲瀷
   }
 
   state = {
@@ -34,13 +32,26 @@
     treeNodes: null,           // 鍒楄〃鏁版嵁闆�
     expandedKeys: [],          // 灞曞紑鐨勬爲鑺傜偣
     selectedKeys: [],          // 閫変腑鐨勬爲鑺傜偣
+    selected: false            // 閫変腑棣栬
   }
 
   UNSAFE_componentWillMount () {
-    const { config, data, initdata, BID } = this.props
+    const { config, data, initdata } = this.props
     let _config = fromJS(config).toJS()
     let _data = null
     let _sync = config.setting.sync === 'true'
+
+    let BID = ''
+    let BData = ''
+
+    if (_config.setting.supModule) {
+      BData = window.GLOB.CacheData.get(_config.setting.supModule)
+    } else {
+      BData = window.GLOB.CacheData.get(_config.$pageId)
+    }
+    if (BData) {
+      BID = BData.$BID || ''
+    }
 
     if (config.setting.sync === 'true' && data) {
       _data = data[config.dataName] || []
@@ -53,6 +64,7 @@
     _config.wrap.contentHeight = config.wrap.title || config.wrap.searchable === 'true' ? 'calc(100% - 45px)' : '100%'
 
     this.setState({
+      selected: _config.wrap.selected === 'true',
       config: _config,
       data: _data,
       BID: BID || '',
@@ -60,9 +72,11 @@
       sync: _sync
     }, () => {
       if (config.setting.sync !== 'true' && config.setting.onload === 'true') {
-        this.loadData(null, 'init')
+        setTimeout(() => {
+          this.loadData(null)
+        }, config.setting.delay || 0)
       } else if (config.setting.sync === 'true' && _data) {
-        this.handleData('init')
+        this.handleData()
       }
     })
   }
@@ -80,7 +94,7 @@
       }
 
       this.setState({sync: false, data: _data}, () => {
-        this.handleData('init')
+        this.handleData()
       })
     } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
       this.setState({}, () => {
@@ -142,22 +156,30 @@
         })
         return
       } else if (result.run_type) {
-        this.setState({timer})
+        let repeats = config.timerRepeats || 0
+        this.setState({timer, repeats})
         this.timer = setTimeout(() => {
-          this.timerTask()
+          this.timerTask(repeats)
         }, timer)
       }
     })
   }
 
-  timerTask = () => {
-    const { timer } = this.state
+  timerTask = (times) => {
+    const { timer, repeats } = this.state
     if (!timer) return
     
     this.loadData(true)
-    
+
+    if (repeats) {
+      times = times - 1
+      if (times <= 0) {
+        clearTimeout(this.timer)
+        return
+      }
+    }
     this.timer = setTimeout(() => {
-      this.timerTask()
+      this.timerTask(times)
     }, timer)
   }
 
@@ -183,8 +205,8 @@
   /**
    * @description 鏁版嵁鍔犺浇
    */
-  async loadData (hastimer, type) {
-    const { mainSearch, menuType } = this.props
+  async loadData (hastimer) {
+    const { mainSearch } = this.props
     const { config, arr_field, BID } = this.state
 
     if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
@@ -210,7 +232,7 @@
     }
 
     let _orderBy = config.setting.order || ''
-    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, '', '', BID, menuType)
+    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, '', '', BID)
 
     let result = await Api.genericInterface(param)
     if (result.status) {
@@ -218,7 +240,7 @@
         data: result.data,
         loading: false
       }, () => {
-        this.handleData(type)
+        this.handleData()
       })
     } else {
       this.setState({
@@ -233,24 +255,41 @@
     }
   }
 
-  handleData = (type) => {
-    const { data, searchkey, config } = this.state
+  handleData = () => {
+    const { data, searchkey, config, selectedKeys, selected } = this.state
     if (!data || data.length === 0) {
       this.setState({
+        selectedKeys: [],
+        expandedKeys: [],
         treedata: [],
         treeNodes: [],
       })
+
+      MKEmitter.emit('resetSelectLine', config.uuid, '', '')
       return
     }
     let parentNodes = []
     let _options = []
     let logMap = new Map()
+    let selectKey = selectedKeys[0] || ''
+    let selectData = ''
+    let hasSelectKey = false
 
     data.forEach(item => {
       let pval = item[config.wrap.parentField]
       let val = item[config.wrap.valueField]
 
       if (!val || logMap.has(val)) return
+
+      if (selectKey && selectKey === val) {
+        hasSelectKey = true
+        selectData = {
+          ...item,
+          $title: item[config.wrap.labelField] || '',
+          $key: val,
+          $parentId: ''
+        }
+      }
 
       logMap.set(val, true)
       if (pval === config.wrap.mark) {
@@ -285,14 +324,22 @@
       treeNodes: _treeNodes,
     })
 
-    if (type === 'init' && _treeNodes[0] && config.wrap.selected === 'true') {
+    if (selected && !hasSelectKey && _treeNodes[0]) {
       this.setState({
         selectedKeys: [_treeNodes[0].$key]
       })
 
       setTimeout(() => {
-        MKEmitter.emit('resetSelectLine', config.uuid, _treeNodes[0].$key, '')
+        MKEmitter.emit('resetSelectLine', config.uuid, _treeNodes[0].$key, _treeNodes[0])
       }, 200)
+    } else if (!hasSelectKey && selectKey) {
+      this.setState({
+        selectedKeys: []
+      })
+
+      MKEmitter.emit('resetSelectLine', config.uuid, '', '')
+    } else if (hasSelectKey) {
+      MKEmitter.emit('resetSelectLine', config.uuid, selectKey, selectData)
     }
   }
 
@@ -433,7 +480,7 @@
     const { config, loading, treeNodes, expandedKeys, selectedKeys } = this.state
 
     return (
-      <div className="custom-tree-box" style={config.style}>
+      <div className="custom-tree-box" id={'anchor' + config.uuid} style={config.style}>
         {loading ?
           <div className="loading-mask">
             <div className="ant-spin-blur"></div>
@@ -441,7 +488,7 @@
           </div> : null
         }
         {config.wrap.title || config.wrap.searchable === 'true' ? <div className="tree-header" style={config.headerStyle}>
-          <span className="title">{config.wrap.title}</span>
+          <span className={'title ' + (config.wrap.searchable !== 'true' ? 'search-unable' : '')}>{config.wrap.title}</span>
           {config.wrap.searchable === 'true' ? <Search allowClear onSearch={this.treeFilter} /> : null}
         </div> : null}
         {treeNodes && treeNodes.length > 0 ? <div className="tree-box" style={{height: config.wrap.contentHeight}}>

--
Gitblit v1.8.0