king
2022-01-07 c1f9e05741e64087ebbfa5e1185bfd0beeb4eeb5
src/tabviews/custom/components/tree/antd-tree/index.jsx
@@ -34,6 +34,7 @@
    treeNodes: null,           // 列表数据集
    expandedKeys: [],          // 展开的树节点
    selectedKeys: [],          // 选中的树节点
    selected: false            // 选中首行
  }
  UNSAFE_componentWillMount () {
@@ -53,6 +54,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 +62,9 @@
      sync: _sync
    }, () => {
      if (config.setting.sync !== 'true' && config.setting.onload === 'true') {
        this.loadData(null, 'init')
        this.loadData(null)
      } else if (config.setting.sync === 'true' && _data) {
        this.handleData('init')
        this.handleData()
      }
    })
  }
@@ -80,7 +82,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({}, () => {
@@ -183,7 +185,7 @@
  /**
   * @description 数据加载
   */
  async loadData (hastimer, type) {
  async loadData (hastimer) {
    const { mainSearch, menuType } = this.props
    const { config, arr_field, BID } = this.state
@@ -218,7 +220,7 @@
        data: result.data,
        loading: false
      }, () => {
        this.handleData(type)
        this.handleData()
      })
    } else {
      this.setState({
@@ -233,24 +235,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,7 +304,7 @@
      treeNodes: _treeNodes,
    })
    if (type === 'init' && _treeNodes[0] && config.wrap.selected === 'true') {
    if (selected && !hasSelectKey && _treeNodes[0]) {
      this.setState({
        selectedKeys: [_treeNodes[0].$key]
      })
@@ -293,6 +312,14 @@
      setTimeout(() => {
        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)
    }
  }