Commit 0b4c01dc by zhaochengxiang

资产自定义树

parent 5007c1df
...@@ -20,10 +20,12 @@ const AssetTree = (props) => { ...@@ -20,10 +20,12 @@ const AssetTree = (props) => {
const [ expandedKeys, setExpandedKeys ] = useState([]); const [ expandedKeys, setExpandedKeys ] = useState([]);
const [ autoExpandParent, setAutoExpandParent ] = useState(false); const [ autoExpandParent, setAutoExpandParent ] = useState(false);
const [ currentDirId, setCurrentDirId ] = useState(''); const [ currentDirId, setCurrentDirId ] = useState('');
const [ currentDirType, setCurrentDirType ] = useState('');
const [ importDirectoryVisible, setImportDirectoryVisible ] = useState(false); const [ importDirectoryVisible, setImportDirectoryVisible ] = useState(false);
const [ updateDirectoryModalVisible, setUpdateDirectoryModalVisible ] = useState(false); const [ updateDirectoryModalVisible, setUpdateDirectoryModalVisible ] = useState(false);
const [ updateDirectoryAction, setUpdateDirectoryAction ] = useState(''); const [ updateDirectoryAction, setUpdateDirectoryAction ] = useState('');
const [ customDirectoryModalVisible, setCustomDirectoryModalVisible ] = useState(false); const [ customDirectoryModalVisible, setCustomDirectoryModalVisible ] = useState(false);
const [ customDirectoryAction, setCustomDirectoryAction ] = useState('');
const [modal, contextHolder] = Modal.useModal(); const [modal, contextHolder] = Modal.useModal();
...@@ -46,8 +48,10 @@ const AssetTree = (props) => { ...@@ -46,8 +48,10 @@ const AssetTree = (props) => {
if (resetCurrentDirId) { if (resetCurrentDirId) {
const _currentDirId = (data&&data[0]?(data[0].nodeId||''):''); const _currentDirId = (data&&data[0]?(data[0].nodeId||''):'');
const _type = (data&&data[0]?(data[0].type||''):'');
setCurrentDirId(_currentDirId); setCurrentDirId(_currentDirId);
setCurrentDirType(_type);
onSelect && onSelect(_currentDirId); onSelect && onSelect(_currentDirId);
} }
}, },
...@@ -82,6 +86,25 @@ const AssetTree = (props) => { ...@@ -82,6 +86,25 @@ const AssetTree = (props) => {
} }
return parentKey; return parentKey;
}; };
const getCurrentType = (key, tree, root=true) => {
let type;
for (let i = 0; i < tree.length; i++) {
const node = tree[i];
if (node.nodeId === key) {
type = node.type||'';
if (type !== '') {
type += (root?'-root':'');
}
} else if (node.children) {
if (getCurrentType(key, node.children, false)) {
type = getCurrentType(key, node.children, false);
}
}
}
return type;
}
const addDir = () => { const addDir = () => {
setUpdateDirectoryAction('add'); setUpdateDirectoryAction('add');
...@@ -89,8 +112,17 @@ const AssetTree = (props) => { ...@@ -89,8 +112,17 @@ const AssetTree = (props) => {
} }
const editDir = () => { const editDir = () => {
setUpdateDirectoryAction('edit'); if (currentDirType === '') {
setUpdateDirectoryModalVisible(true);
setUpdateDirectoryAction('edit');
setUpdateDirectoryModalVisible(true);
} else if (currentDirType === 'custom-root') {
setCustomDirectoryAction('edit');
setCustomDirectoryModalVisible(true);
}
} }
const refreshTree = () => { const refreshTree = () => {
...@@ -144,6 +176,7 @@ const AssetTree = (props) => { ...@@ -144,6 +176,7 @@ const AssetTree = (props) => {
} }
const customDir = () => { const customDir = () => {
setCustomDirectoryAction('add');
setCustomDirectoryModalVisible(true); setCustomDirectoryModalVisible(true);
} }
...@@ -172,13 +205,14 @@ const AssetTree = (props) => { ...@@ -172,13 +205,14 @@ const AssetTree = (props) => {
setKeyword(value); setKeyword(value);
} }
const onTreeSelect = (keys,_) => { const onTreeSelect = (keys, _) => {
if ((keys||[]).length === 0) { if ((keys||[]).length === 0) {
return; return;
} }
setCurrentDirId(keys[0]); setCurrentDirId(keys[0]);
setCurrentDirType(getCurrentType(keys[0], treeData));
onSelect && onSelect(keys[0]); onSelect && onSelect(keys[0]);
} }
...@@ -250,18 +284,18 @@ const AssetTree = (props) => { ...@@ -250,18 +284,18 @@ const AssetTree = (props) => {
<Card <Card
className={classes} className={classes}
title={ readOnly ? null : ( title={ readOnly ? null : (
<Space wrap> <Space size={5}>
<Tooltip title="新增目录"> <Tooltip title="新增目录">
<Button shape="circle" icon={<PlusOutlined />} onClick={addDir} /> <Button shape="circle" icon={<PlusOutlined />} onClick={addDir} disabled={currentDirType==='custom-root'||currentDirType==='custom'} />
</Tooltip> </Tooltip>
<Tooltip title="修改"> <Tooltip title="修改">
<Button shape="circle" icon={<EditOutlined />} onClick={editDir} /> <Button shape="circle" icon={<EditOutlined />} onClick={editDir} disabled={currentDirType==='custom'}/>
</Tooltip> </Tooltip>
<Tooltip title="刷新"> <Tooltip title="刷新">
<Button shape="circle" icon={<SyncOutlined />} onClick={refreshTree} /> <Button shape="circle" icon={<SyncOutlined />} onClick={refreshTree} />
</Tooltip> </Tooltip>
<Tooltip title="导入"> <Tooltip title="导入">
<Button shape="circle" icon={<ImportOutlined />} onClick={importDir} /> <Button shape="circle" icon={<ImportOutlined />} onClick={importDir} disabled={currentDirType==='custom-root'||currentDirType==='custom'} />
</Tooltip> </Tooltip>
<Dropdown overlay={exportMenu} placement="bottomLeft"> <Dropdown overlay={exportMenu} placement="bottomLeft">
<Tooltip title="导出"> <Tooltip title="导出">
...@@ -269,7 +303,7 @@ const AssetTree = (props) => { ...@@ -269,7 +303,7 @@ const AssetTree = (props) => {
</Tooltip> </Tooltip>
</Dropdown> </Dropdown>
<Tooltip title="删除"> <Tooltip title="删除">
<Button shape="circle" icon={<DeleteOutlined />} onClick={deleteDir} /> <Button shape="circle" icon={<DeleteOutlined />} onClick={deleteDir} disabled={currentDirType==='custom'} />
</Tooltip> </Tooltip>
<Tooltip title="自定义"> <Tooltip title="自定义">
<Button shape="circle" icon={<SettingOutlined />} onClick={customDir} /> <Button shape="circle" icon={<SettingOutlined />} onClick={customDir} />
...@@ -314,6 +348,8 @@ const AssetTree = (props) => { ...@@ -314,6 +348,8 @@ const AssetTree = (props) => {
<CustomDirectoryModal <CustomDirectoryModal
visible={ customDirectoryModalVisible } visible={ customDirectoryModalVisible }
onCancel={ onCustomDirectoryCancel } onCancel={ onCustomDirectoryCancel }
action={ customDirectoryAction }
dirId= { currentDirId }
/> />
{contextHolder} {contextHolder}
</Card> </Card>
......
...@@ -11,7 +11,7 @@ import { dispatch, dispatchLatest } from '../../../../model'; ...@@ -11,7 +11,7 @@ import { dispatch, dispatchLatest } from '../../../../model';
import { showMessage } from '../../../../util'; import { showMessage } from '../../../../util';
const CustomDirectoryModal = (props) => { const CustomDirectoryModal = (props) => {
const { visible, onCancel } = props; const { visible, onCancel, action, dirId } = props;
const [ data, setData ] = useState([]); const [ data, setData ] = useState([]);
const [ previewTreeData, setPreviewTreeData ] = useState({}); const [ previewTreeData, setPreviewTreeData ] = useState({});
...@@ -24,7 +24,7 @@ const CustomDirectoryModal = (props) => { ...@@ -24,7 +24,7 @@ const CustomDirectoryModal = (props) => {
useEffect(() => { useEffect(() => {
if (visible) { if (visible) {
reset(); reset();
getAllElements(); getAllElementsThenGetCurrentDirectory();
} }
//eslint-disable-next-line react-hooks/exhaustive-deps //eslint-disable-next-line react-hooks/exhaustive-deps
}, [visible]) }, [visible])
...@@ -35,13 +35,31 @@ const CustomDirectoryModal = (props) => { ...@@ -35,13 +35,31 @@ const CustomDirectoryModal = (props) => {
getPreviewTreeData(); getPreviewTreeData();
} }
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [checkedValues]) }, [checkedValues])
const getAllElements = () => { const getAllElementsThenGetCurrentDirectory = () => {
dispatch({ dispatch({
type: 'assetmanage.listElements', type: 'assetmanage.listElements',
callback: elements => {
setData(elements||[]);
if (action === 'edit') {
getCurrentDirectory(elements||[]);
}
}
})
}
const getCurrentDirectory = (elements) => {
dispatch({
type: 'assetmanage.getDirectoryById',
payload: {
dirId
},
callback: data => { callback: data => {
setData(data||[]); setCheckedValues(data.elementIds||[]);
form.setFieldsValue({ name: data.name||'', desc: data.desc||'' });
onChange(data.elementIds||[], elements);
} }
}) })
} }
...@@ -58,12 +76,12 @@ const CustomDirectoryModal = (props) => { ...@@ -58,12 +76,12 @@ const CustomDirectoryModal = (props) => {
}) })
} }
const onChange = (checkedValues) => { const onChange = (checkedValues, elements = data) => {
setCheckedValues(checkedValues); setCheckedValues(checkedValues);
const _checkedData = []; const _checkedData = [];
(checkedValues||[]).forEach(value => { (checkedValues||[]).forEach(value => {
(data||[]).forEach(item => { (elements||[]).forEach(item => {
if (value === item.id) { if (value === item.id) {
_checkedData.push(item); _checkedData.push(item);
} }
...@@ -77,6 +95,7 @@ const CustomDirectoryModal = (props) => { ...@@ -77,6 +95,7 @@ const CustomDirectoryModal = (props) => {
setConfirmLoading(false); setConfirmLoading(false);
setCheckedValues([]); setCheckedValues([]);
setCheckedData([]); setCheckedData([]);
setPreviewTreeData({});
form.resetFields(); form.resetFields();
} }
...@@ -90,12 +109,19 @@ const CustomDirectoryModal = (props) => { ...@@ -90,12 +109,19 @@ const CustomDirectoryModal = (props) => {
const row = await form.validateFields(); const row = await form.validateFields();
setConfirmLoading(true); setConfirmLoading(true);
let payload = {
data: checkedValues,
params: row
}
if (action === 'edit') {
payload.params = {...payload.params, dirId};
}
dispatch({ dispatch({
type: 'assetmanage.saveTreeByCustomElements', type: 'assetmanage.saveTreeByCustomElements',
payload: { payload,
data: checkedValues,
params: row
},
callback: () => { callback: () => {
setConfirmLoading(false); setConfirmLoading(false);
onCancel && onCancel(true); onCancel && onCancel(true);
...@@ -156,7 +182,7 @@ const CustomDirectoryModal = (props) => { ...@@ -156,7 +182,7 @@ const CustomDirectoryModal = (props) => {
return ( return (
<Modal <Modal
forceRender forceRender
title={'新增自定义'} title={action==='add'?'新增自定义':'修改自定义'}
visible={visible} visible={visible}
width={800} width={800}
confirmLoading={confirmLoading} confirmLoading={confirmLoading}
......
import React from 'react'; import React from 'react';
import G6 from '@antv/g6'; import G6 from '@antv/g6';
import { isNumber } from '@antv/util';
// import { ContextPath } from '../../../../util';
const colors = [ const colors = [
'#BDD2FD', '#BDD2FD',
...@@ -68,7 +66,7 @@ class Relation extends React.Component { ...@@ -68,7 +66,7 @@ class Relation extends React.Component {
[x, y] = textXY(root, cfg) [x, y] = textXY(root, cfg)
} }
const circle = group.addShape('circle', { group.addShape('circle', {
attrs: { attrs: {
x: 0, x: 0,
y: 0, y: 0,
......
import React from 'react'; import React from 'react';
import { Tabs, Spin, Select } from 'antd'; import { Tabs, Spin, Radio, Tooltip } from 'antd';
import MapContent from './MapContent'; import MapContent from './MapContent';
import { dispatchLatest } from '../../../model'; import { dispatchLatest } from '../../../model';
...@@ -7,7 +7,6 @@ import { dispatchLatest } from '../../../model'; ...@@ -7,7 +7,6 @@ import { dispatchLatest } from '../../../model';
import './index.less'; import './index.less';
const { TabPane } = Tabs; const { TabPane } = Tabs;
const { Option } = Select;
const graphModes = [ const graphModes = [
{ {
...@@ -59,8 +58,8 @@ class Map extends React.Component { ...@@ -59,8 +58,8 @@ class Map extends React.Component {
}) })
} }
onTypeChange = value => { onTypeChange = e => {
this.setState({ type: value||'' }); this.setState({ type: e.target.value });
}; };
onTabChange = activeKey => { onTabChange = activeKey => {
...@@ -85,17 +84,21 @@ class Map extends React.Component { ...@@ -85,17 +84,21 @@ class Map extends React.Component {
return ( return (
<TabPane tab={topic.name||''} key={topic.id||''}> <TabPane tab={topic.name||''} key={topic.id||''}>
<div className='d-flex px-3' style={{ height: 53, alignItems: 'center' }}> <div className='d-flex px-3' style={{ height: 53, alignItems: 'center' }}>
<Select <Radio.Group
value={type} value={type}
style={{ width: 120, marginLeft: 'auto' }} onChange={this.onTypeChange}
onChange={this.onTypeChange} style={{ marginLeft: 'auto' }}
> >
{ {
graphModes && graphModes.map((mode, index) => { graphModes && graphModes.map((mode, index) => {
return <Option key={index} value={mode.key||''}>{mode.title||''}</Option> return (
}) <Tooltip key={index} title={mode.title||''} >
} <Radio.Button value={mode.key}>{(mode.title||'').substring(0, 1)}</Radio.Button>
</Select> </Tooltip>
);
})
}
</Radio.Group>
</div> </div>
{ {
tabKey===topic.id && <div className='map-container' style={{ padding: '0 10px' }}> tabKey===topic.id && <div className='map-container' style={{ padding: '0 10px' }}>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment