| | |
| | | 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' |
| | |
| | | |
| | | class NormalTree extends Component { |
| | | static propTpyes = { |
| | | BID: PropTypes.any, // 父级Id |
| | | data: PropTypes.array, // 统一查询数据 |
| | | config: PropTypes.object, // 组件配置信息 |
| | | mainSearch: PropTypes.any, // 外层搜索条件 |
| | | menuType: PropTypes.any, // 菜单类型 |
| | | } |
| | | |
| | | state = { |
| | |
| | | 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] || [] |
| | |
| | | _sync = false |
| | | } |
| | | |
| | | _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 || '', |
| | |
| | | sync: _sync |
| | | }, () => { |
| | | if (config.setting.sync !== 'true' && config.setting.onload === 'true') { |
| | | this.loadData() |
| | | setTimeout(() => { |
| | | this.loadData(null) |
| | | }, config.setting.delay || 0) |
| | | } else if (config.setting.sync === 'true' && _data) { |
| | | this.handleData() |
| | | } |
| | |
| | | |
| | | 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] |
| | | |
| | |
| | | }) |
| | | 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) |
| | | } |
| | | |
| | |
| | | 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() |
| | | }) |
| | |
| | | * @description 数据加载 |
| | | */ |
| | | async loadData (hastimer) { |
| | | const { mainSearch, menuType } = this.props |
| | | const { mainSearch } = this.props |
| | | const { config, arr_field, BID } = this.state |
| | | |
| | | if (config.setting.supModule && !BID) { // BID 不存在时,不做查询 |
| | |
| | | } |
| | | |
| | | 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) { |
| | |
| | | } |
| | | |
| | | handleData = () => { |
| | | const { data, searchkey, config } = this.state |
| | | 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] |
| | |
| | | |
| | | 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) { |
| | | parentNodes.push({ |
| | | // ...item, |
| | | ...item, |
| | | $title: item[config.wrap.labelField] || '', |
| | | $key: val, |
| | | $parentId: '' |
| | | }) |
| | | } else if (pval) { |
| | | _options.push({ |
| | | // ...item, |
| | | ...item, |
| | | $title: item[config.wrap.labelField] || '', |
| | | $key: val, |
| | | $parentId: pval |
| | |
| | | } |
| | | |
| | | this.setState({ |
| | | expandedKeys: _treeNodes[0] ? [_treeNodes[0].$key] : [], |
| | | treedata: _treedata, |
| | | treeNodes: _treeNodes, |
| | | }) |
| | | |
| | | if (selected && !hasSelectKey && _treeNodes[0]) { |
| | | this.setState({ |
| | | selectedKeys: [_treeNodes[0].$key] |
| | | }) |
| | | |
| | | 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) |
| | | } |
| | | } |
| | | |
| | | treeFilter = (value) => { |
| | |
| | | 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 /> |
| | | }) |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if (selected) { |
| | | delete _data.children |
| | | MKEmitter.emit('resetSelectLine', config.uuid, (_data ? _data.$key : ''), _data) |
| | | } |
| | | |
| | |
| | | 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> |
| | |
| | | </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"> |
| | | {treeNodes && treeNodes.length > 0 ? <div className="tree-box" style={{height: config.wrap.contentHeight}}> |
| | | <Tree |
| | | blockNode |
| | | onSelect={this.selectTreeNode} |