From 5046d0d13dc6a8563b8e54e31913bc44cfa1072f Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期二, 26 四月 2022 19:23:18 +0800 Subject: [PATCH] 2022-04-26 --- src/tabviews/custom/components/tree/antd-tree/index.jsx | 54 ++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/tabviews/custom/components/tree/antd-tree/index.jsx b/src/tabviews/custom/components/tree/antd-tree/index.jsx index ebbd2d7..305d461 100644 --- a/src/tabviews/custom/components/tree/antd-tree/index.jsx +++ b/src/tabviews/custom/components/tree/antd-tree/index.jsx @@ -1,7 +1,8 @@ import React, {Component} from 'react' import PropTypes from 'prop-types' import { is, fromJS } from 'immutable' -import { Spin, Empty, notification, Input, Tree, Icon } from 'antd' +import { Spin, Empty, notification, Input, Tree } from 'antd' +import { FolderOpenOutlined, FolderOutlined, FileOutlined } from '@ant-design/icons' import moment from 'moment' import Api from '@/api' @@ -33,6 +34,7 @@ treeNodes: null, // 鍒楄〃鏁版嵁闆� expandedKeys: [], // 灞曞紑鐨勬爲鑺傜偣 selectedKeys: [], // 閫変腑鐨勬爲鑺傜偣 + selected: false // 閫変腑棣栬 } UNSAFE_componentWillMount () { @@ -52,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 || '', @@ -59,9 +62,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() } }) } @@ -79,7 +84,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({}, () => { @@ -182,7 +187,7 @@ /** * @description 鏁版嵁鍔犺浇 */ - async loadData (hastimer, type) { + async loadData (hastimer) { const { mainSearch, menuType } = this.props const { config, arr_field, BID } = this.state @@ -217,7 +222,7 @@ data: result.data, loading: false }, () => { - this.handleData(type) + this.handleData() }) } else { this.setState({ @@ -232,24 +237,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) { @@ -284,14 +306,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) } } @@ -365,12 +395,12 @@ return nodes.map(item => { if (item.children) { return ( - <TreeNode icon={<span><Icon type="folder-open" /><Icon type="folder" /></span>} title={item.$title} key={item.$key} dataRef={item}> + <TreeNode icon={<span><FolderOpenOutlined /><FolderOutlined /></span>} title={item.$title} key={item.$key} dataRef={item}> {this.renderTreeNodes(item.children)} </TreeNode> ) } - return <TreeNode icon={<Icon type="file" />} key={item.$key} title={item.$title} dataRef={item} isLeaf /> + return <TreeNode icon={<FileOutlined />} key={item.$key} title={item.$title} dataRef={item} isLeaf /> }) } -- Gitblit v1.8.0