From 5223edbcccfed84a33a706e5637ee65a61f377aa Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 22 十二月 2021 18:00:39 +0800 Subject: [PATCH] 2021-12-22 --- src/tabviews/custom/components/tree/antd-tree/index.jsx | 116 +++++++++++++++++++++++++--------------------------------- 1 files changed, 50 insertions(+), 66 deletions(-) diff --git a/src/tabviews/custom/components/tree/antd-tree/index.jsx b/src/tabviews/custom/components/tree/antd-tree/index.jsx index 1ab48b4..9788af1 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' @@ -49,6 +50,8 @@ _sync = false } + _config.wrap.contentHeight = config.wrap.title || config.wrap.searchable === 'true' ? 'calc(100% - 45px)' : '100%' + this.setState({ config: _config, data: _data, @@ -57,9 +60,9 @@ sync: _sync }, () => { if (config.setting.sync !== 'true' && config.setting.onload === 'true') { - this.loadData() + this.loadData(null, 'init') } else if (config.setting.sync === 'true' && _data) { - this.handleData() + this.handleData('init') } }) } @@ -76,24 +79,13 @@ _data = nextProps.data[config.dataName] || [] } - // _data = [ - // {ID: 'dsdsagsgfs32ed2dqd61', nvarchar1: '1', nvarchar2: '1', nvarchar3: ''}, - // {ID: 'dsdsagsgfs32ed2dqd61', nvarchar1: '1-1', nvarchar2: '1-1', nvarchar3: '1'}, - // {ID: 'dsdsagsgfs32ed2dqd61', nvarchar1: '1-2', nvarchar2: '1-2', nvarchar3: '1'}, - // {ID: 'dsdsagsgfs32ed2dqd61', nvarchar1: '2', nvarchar2: '2', nvarchar3: ''}, - // {ID: 'dsdsagsgfs32ed2dqd61', nvarchar1: '2-1', nvarchar2: '2-1', nvarchar3: '2'}, - // {ID: 'dsdsagsgfs32ed2dqd61', nvarchar1: '2-2', nvarchar2: '2-2', nvarchar3: '2'}, - // ] - this.setState({sync: false, data: _data}, () => { - this.handleData() + this.handleData('init') }) - } else if (nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { - if (config.setting.syncRefresh === 'true') { - this.setState({}, () => { - this.loadData() - }) - } + } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) { + this.setState({}, () => { + this.loadData() + }) } } @@ -124,16 +116,7 @@ if (!config.timer) return - const _change = { - '15s': 15000, - '30s': 30000, - '1min': 60000, - '5min': 300000, - '10min': 600000, - '15min': 900000, - '30min': 1800000, - '1hour': 3600000 - } + const _change = { '5s': 5000, '15s': 15000, '30s': 30000, '1min': 60000, '5min': 300000, '10min': 600000, '15min': 900000, '30min': 1800000, '1hour': 3600000 } let timer = _change[config.timer] @@ -190,7 +173,7 @@ const { config } = this.state if (!config.setting.supModule || config.setting.supModule !== MenuID) return - if (id !== this.state.BID) { + if (id !== this.state.BID || id !== '') { this.setState({ BID: id }, () => { this.loadData() }) @@ -200,7 +183,7 @@ /** * @description 鏁版嵁鍔犺浇 */ - async loadData (hastimer) { + async loadData (hastimer, type) { const { mainSearch, menuType } = this.props const { config, arr_field, BID } = this.state @@ -213,21 +196,10 @@ return } - let searches = [] - if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢 - let keys = searches.map(item => item.key) - mainSearch.forEach(item => { - if (!keys.includes(item.key)) { - searches.push(item) - } - }) - } + let searches = config.setting.useMSearch && mainSearch ? mainSearch : [] - let requireFields = searches.filter(item => item.required && (!item.value || item.value.length === 0)) + let requireFields = searches.filter(item => item.required && item.value === '') if (requireFields.length > 0) { - this.setState({ - loading: false - }) return } @@ -246,7 +218,7 @@ data: result.data, loading: false }, () => { - this.handleData() + this.handleData(type) }) } else { this.setState({ @@ -261,7 +233,7 @@ } } - handleData = () => { + handleData = (type) => { const { data, searchkey, config } = this.state if (!data || data.length === 0) { this.setState({ @@ -283,17 +255,17 @@ logMap.set(val, true) if (pval === config.wrap.mark) { parentNodes.push({ - // ...item, - title: item[config.wrap.labelField] || '', - key: val, - parentId: '' + ...item, + $title: item[config.wrap.labelField] || '', + $key: val, + $parentId: '' }) } else if (pval) { _options.push({ - // ...item, - title: item[config.wrap.labelField] || '', - key: val, - parentId: pval + ...item, + $title: item[config.wrap.labelField] || '', + $key: val, + $parentId: pval }) } }) @@ -308,9 +280,20 @@ } this.setState({ + expandedKeys: _treeNodes[0] ? [_treeNodes[0].$key] : [], treedata: _treedata, treeNodes: _treeNodes, }) + + if (type === 'init' && _treeNodes[0] && config.wrap.selected === 'true') { + this.setState({ + selectedKeys: [_treeNodes[0].$key] + }) + + setTimeout(() => { + MKEmitter.emit('resetSelectLine', config.uuid, _treeNodes[0].$key, '') + }, 200) + } } treeFilter = (value) => { @@ -336,9 +319,9 @@ getFilterTree = (parents, searchkey) => { return parents.filter(node => { if (!node.children) { - return (node.title.toLowerCase().indexOf(searchkey) >= 0 || node.key.toLowerCase().indexOf(searchkey) >= 0) + return (node.$title.toLowerCase().indexOf(searchkey) >= 0 || node.$key.toLowerCase().indexOf(searchkey) >= 0) } else { - if (node.title.toLowerCase().indexOf(searchkey) >= 0 || node.key.toLowerCase().indexOf(searchkey) >= 0) { + if (node.$title.toLowerCase().indexOf(searchkey) >= 0 || node.$key.toLowerCase().indexOf(searchkey) >= 0) { return true } @@ -360,7 +343,7 @@ parent.children = [] // 娣诲姞鑿滃崟鐨勫瓙鍏冪礌 options = options.filter(option => { - if (option.parentId === parent.key) { + if (option.$parentId === parent.$key) { parent.children.push(option) return false } @@ -383,12 +366,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 /> }) } @@ -414,7 +397,7 @@ getExpandKeys = (node, keys) => { if (node.children) { - keys.push(node.key) + keys.push(node.$key) node.children.forEach(_node => { this.getExpandKeys(_node, keys) }) @@ -426,22 +409,23 @@ let _expandedKeys = fromJS(this.state.expandedKeys).toJS() let _data = fromJS(node.props.dataRef).toJS() - if (_expandedKeys.indexOf(_data.key) >= 0) { - _expandedKeys = _expandedKeys.filter(key => key !== _data.key) + if (_expandedKeys.indexOf(_data.$key) >= 0) { + _expandedKeys = _expandedKeys.filter(key => key !== _data.$key) } else { if (_data.children) { - _expandedKeys.push(_data.key) + _expandedKeys.push(_data.$key) _expandedKeys = Array.from(new Set(_expandedKeys)) } } if (selected) { - MKEmitter.emit('resetSelectLine', config.uuid, (_data ? _data.key : ''), _data) + delete _data.children + MKEmitter.emit('resetSelectLine', config.uuid, (_data ? _data.$key : ''), _data) } this.setState({ expandedKeys: _expandedKeys, - selectedKeys: [_data.key] + selectedKeys: [_data.$key] }) } @@ -460,7 +444,7 @@ <span className="title">{config.wrap.title}</span> {config.wrap.searchable === 'true' ? <Search allowClear onSearch={this.treeFilter} /> : null} </div> : null} - {treeNodes && treeNodes.length > 0 ? <div className="tree-box"> + {treeNodes && treeNodes.length > 0 ? <div className="tree-box" style={{height: config.wrap.contentHeight}}> <Tree blockNode onSelect={this.selectTreeNode} -- Gitblit v1.8.0