| | |
| | | import React, {Component} from 'react' |
| | | import PropTypes from 'prop-types' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Spin, Empty, notification, Input, Tree, Modal, Dropdown } from 'antd' |
| | | import { Spin, Empty, Input, Tree, Dropdown } from 'antd' |
| | | import { FolderOpenOutlined, FolderOutlined, FileOutlined, MoreOutlined } from '@ant-design/icons' |
| | | |
| | | import Api from '@/api' |
| | |
| | | treeNodes: null, // 列表数据集 |
| | | expandedKeys: [], // 展开的树节点 |
| | | selectedKeys: [], // 选中的树节点 |
| | | lineActions: [], |
| | | selected: false // 选中首行 |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | let lineActions = [] |
| | | _config.action = _config.action || [] |
| | | _config.action = _config.action.filter(item => { |
| | | if (item.Ot === 'requiredSgl') { |
| | | lineActions.push(item) |
| | | return false |
| | | } |
| | | return true |
| | | }) |
| | | |
| | | _config.wrap.contentHeight = config.wrap.title || config.wrap.searchable === 'true' ? 'calc(100% - 45px)' : '100%' |
| | | |
| | | if (_config.wrap.lineHeight) { |
| | | _config.style['--mk-tree-line-height'] = _config.wrap.lineHeight + 'px' |
| | | } |
| | | |
| | | this.setState({ |
| | | selected: _config.wrap.selected === 'true', |
| | | config: _config, |
| | | data: _data, |
| | | BID: BID || '' |
| | | BID: BID || '', |
| | | lineActions |
| | | }) |
| | | } |
| | | |
| | |
| | | * @param {*} position // 刷新位置 |
| | | * @param {*} btn // 执行的按钮 |
| | | */ |
| | | refreshByButtonResult = (menuId, position, btn) => { |
| | | refreshByButtonResult = (menuId, position) => { |
| | | const { config, BID } = this.state |
| | | |
| | | if (config.uuid !== menuId) return |
| | |
| | | } |
| | | } |
| | | |
| | | if (result.message) { |
| | | if (result.ErrCode === 'Y') { |
| | | Modal.success({ |
| | | title: result.message |
| | | }) |
| | | } else if (result.ErrCode === 'S') { |
| | | notification.success({ |
| | | top: 92, |
| | | message: result.message, |
| | | duration: 2 |
| | | }) |
| | | } |
| | | } |
| | | UtilsDM.querySuccess(result) |
| | | } else { |
| | | this.setState({ |
| | | loading: false |
| | | }) |
| | | this.timer && this.timer.stop() |
| | | |
| | | if (!result.message) return |
| | | if (result.ErrCode === 'N') { |
| | | Modal.error({ |
| | | title: result.message, |
| | | }) |
| | | } else if (result.ErrCode !== '-2') { |
| | | notification.error({ |
| | | top: 92, |
| | | message: result.message, |
| | | duration: 10 |
| | | }) |
| | | } |
| | | UtilsDM.queryFail(result) |
| | | } |
| | | } |
| | | |
| | |
| | | let hasSelectKey = false |
| | | |
| | | data.forEach(item => { |
| | | let pval = item[config.wrap.parentField] |
| | | let val = item[config.wrap.valueField] |
| | | let uuid = item[config.setting.primaryKey] || '' |
| | | let pval = item[config.wrap.parentField] + '' |
| | | let val = item[config.wrap.valueField] + '' |
| | | let uuid = item[config.setting.primaryKey] + '' |
| | | |
| | | if (!val || logMap.has(val)) return |
| | | |
| | |
| | | }) |
| | | } |
| | | |
| | | renderActionTreeNodes = (nodes) => { |
| | | renderActionTreeNodes = (nodes, actShow) => { |
| | | return nodes.map(item => { |
| | | let title = <> |
| | | {item.$title} |
| | | <Dropdown overlay={ |
| | | <div className="mk-tree-dropdown-wrap" onClick={(e) => e.stopPropagation()}> |
| | | <MainAction |
| | | BID={this.state.BID} |
| | | BData={this.state.BData} |
| | | setting={this.state.config.setting} |
| | | actions={this.state.config.action} |
| | | columns={this.state.config.columns} |
| | | selectedData={[{...item, children: ''}]} |
| | | /> |
| | | </div> |
| | | } placement="bottomCenter" trigger={['hover']}> |
| | | <MoreOutlined onClick={(e) => e.stopPropagation()}/> |
| | | </Dropdown> |
| | | </> |
| | | let title = null |
| | | if (actShow === 'line') { |
| | | title = <> |
| | | {item.$title} |
| | | <MainAction |
| | | BID={this.state.BID} |
| | | BData={this.state.BData} |
| | | setting={this.state.config.setting} |
| | | actions={this.state.lineActions} |
| | | columns={this.state.config.columns} |
| | | selectedData={[{...item, children: ''}]} |
| | | /> |
| | | </> |
| | | } else { |
| | | title = <> |
| | | {item.$title} |
| | | <Dropdown overlay={ |
| | | <div className="mk-tree-dropdown-wrap" onClick={(e) => e.stopPropagation()}> |
| | | <MainAction |
| | | BID={this.state.BID} |
| | | BData={this.state.BData} |
| | | setting={this.state.config.setting} |
| | | actions={this.state.lineActions} |
| | | columns={this.state.config.columns} |
| | | selectedData={[{...item, children: ''}]} |
| | | /> |
| | | </div> |
| | | } placement="bottomCenter" trigger={['hover']}> |
| | | <MoreOutlined onClick={(e) => e.stopPropagation()}/> |
| | | </Dropdown> |
| | | </> |
| | | } |
| | | |
| | | if (item.children) { |
| | | return ( |
| | | <TreeNode icon={<span><FolderOpenOutlined /><FolderOutlined /></span>} title={title} key={item.$key} dataRef={item}> |
| | | {this.renderActionTreeNodes(item.children)} |
| | | {this.renderActionTreeNodes(item.children, actShow)} |
| | | </TreeNode> |
| | | ) |
| | | } |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { config, loading, treeNodes, expandedKeys, selectedKeys } = this.state |
| | | |
| | | let extra = config.action && config.action.length > 0 |
| | | const { BID, BData, config, loading, treeNodes, expandedKeys, selectedKeys, lineActions } = this.state |
| | | |
| | | return ( |
| | | <div className="custom-tree-box" id={'anchor' + config.uuid} style={config.style}> |
| | |
| | | <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} |
| | | {config.action.length ? <MainAction |
| | | BID={BID} |
| | | setting={config.setting} |
| | | actions={config.action} |
| | | BData={BData} |
| | | columns={config.columns} |
| | | selectedData={[]} |
| | | /> : null} |
| | | {treeNodes && treeNodes.length > 0 ? <div className="tree-box" style={{height: config.wrap.contentHeight}}> |
| | | <Tree |
| | | blockNode |
| | | onSelect={this.selectTreeNode} |
| | | expandedKeys={expandedKeys} |
| | | selectedKeys={selectedKeys} |
| | | onRightClick={!extra ? this.changeExpandedAllKeys : null} |
| | | onRightClick={!lineActions.length ? this.changeExpandedAllKeys : null} |
| | | onExpand={this.changeExpandedKeys} |
| | | showIcon={config.wrap.showIcon === 'true'} |
| | | showLine={config.wrap.showLine === 'true'} |
| | | > |
| | | {!extra ? this.renderTreeNodes(treeNodes) : this.renderActionTreeNodes(treeNodes)} |
| | | {!lineActions.length ? this.renderTreeNodes(treeNodes) : this.renderActionTreeNodes(treeNodes, config.wrap.actShow)} |
| | | </Tree> |
| | | </div> : null} |
| | | {treeNodes && treeNodes.length === 0 ? <Empty description={false}/> : null} |