Commit 5768dd4c by zhaochengxiang

资产增加视角

parent 800eceaf
...@@ -268,3 +268,11 @@ export function* getScore(payload) { ...@@ -268,3 +268,11 @@ export function* getScore(payload) {
export function* getResourceTypes(payload) { export function* getResourceTypes(payload) {
return yield call(service.getResourceTypes, payload); return yield call(service.getResourceTypes, payload);
} }
export function* getDirectoryChild(payload) {
return yield call(service.getDirectoryChild, payload);
}
export function* queryCustomTypeRootDirectory() {
return yield call(service.queryCustomTypeRootDirectory);
}
\ No newline at end of file
...@@ -275,3 +275,11 @@ export function getScore(payload) { ...@@ -275,3 +275,11 @@ export function getScore(payload) {
export function getResourceTypes(payload) { export function getResourceTypes(payload) {
return GetJSON("/dataassetmanager/dataAssetApi/listSupportResourceTypes", payload); return GetJSON("/dataassetmanager/dataAssetApi/listSupportResourceTypes", payload);
} }
export function getDirectoryChild(payload) {
return GetJSON("/dataassetmanager/directoryApi/getChildByParentId", payload);
}
export function queryCustomTypeRootDirectory() {
return GetJSON("/dataassetmanager/directoryApi/queryCustomTypeRootDirectory");
}
\ No newline at end of file
import React, { useEffect, useState, useRef, useContext } from 'react'; import React, { useEffect, useState, useRef, useContext } from 'react';
import { useMount, useUnmount } from 'ahooks'; import { useMount, useUnmount } from 'ahooks';
import {Card, Spin, Tooltip, Tree, Dropdown, Menu, Modal, AutoComplete} from 'antd'; import {Card, Spin, Tooltip, Tree, Dropdown, Menu, Modal, AutoComplete} from 'antd';
import { PlusOutlined, ImportOutlined,ExportOutlined,ReloadOutlined, SettingOutlined, CalculatorOutlined } from '@ant-design/icons'; import { PlusOutlined, ImportOutlined,ExportOutlined,ReloadOutlined, SettingOutlined, CalculatorOutlined, UnorderedListOutlined } from '@ant-design/icons';
import classNames from 'classnames'; import classNames from 'classnames';
import { useContextMenu, Menu as RcMenu, Item as RcItem } from "react-contexify"; import { useContextMenu, Menu as RcMenu, Item as RcItem } from "react-contexify";
import LocalStorage from 'local-storage'; import LocalStorage from 'local-storage';
...@@ -21,6 +21,34 @@ import 'react-contexify/dist/ReactContexify.css'; ...@@ -21,6 +21,34 @@ import 'react-contexify/dist/ReactContexify.css';
const { Option } = AutoComplete; const { Option } = AutoComplete;
const viewModes = [
{
key: 'dir',
name: '目录视角'
},
{
key: 'custom',
name: '自定义目录视角'
}
];
function updateTreeData(list, key, children) {
return list.map((node) => {
if (node.nodeId === key) {
return { ...node, children };
}
if (node.children) {
return {
...node,
children: updateTreeData(node.children, key, children),
};
}
return node;
});
}
const AssetTree = (props) => { const AssetTree = (props) => {
const MENU_ID = 'asset-tree'; const MENU_ID = 'asset-tree';
...@@ -50,6 +78,8 @@ const AssetTree = (props) => { ...@@ -50,6 +78,8 @@ const AssetTree = (props) => {
const [ customDirectoryAction, setCustomDirectoryAction ] = useState(''); const [ customDirectoryAction, setCustomDirectoryAction ] = useState('');
const [options, setOptions] = useState([]); const [options, setOptions] = useState([]);
const [ computeScoreVisible, setComputeScoreVisible ] = useState(false); const [ computeScoreVisible, setComputeScoreVisible ] = useState(false);
const [ loadedKeys, setLoadedKeys ] = useState([]);
const [ viewSelectedKey, setViewSelectedKey ] = useState(viewModes[0].key);
const [modal, contextHolder] = Modal.useModal(); const [modal, contextHolder] = Modal.useModal();
...@@ -59,6 +89,7 @@ const AssetTree = (props) => { ...@@ -59,6 +89,7 @@ const AssetTree = (props) => {
const treeDataRef = useRef([]); const treeDataRef = useRef([]);
const dataListRef = useRef([]); const dataListRef = useRef([]);
const viewSelectedKeyRef = useRef(viewModes[0].key)
useMount(() => { useMount(() => {
window?.addEventListener("storage", storageChange); window?.addEventListener("storage", storageChange);
...@@ -70,8 +101,12 @@ const AssetTree = (props) => { ...@@ -70,8 +101,12 @@ const AssetTree = (props) => {
useEffect(() => { useEffect(() => {
if ((id||'') !== '') { if ((id||'') !== '') {
setViewSelectedKey(viewModes[0].key);
viewSelectedKeyRef.current = viewModes[0].key;
getDataAssetLocationThenGetTreeData(); getDataAssetLocationThenGetTreeData();
} else if ((did||'') !== '') { } else if ((did||'') !== '') {
setViewSelectedKey(viewModes[0].key);
viewSelectedKeyRef.current = viewModes[0].key;
getAllDirectoryAsTree(true, did); getAllDirectoryAsTree(true, did);
} else { } else {
getAllDirectoryAsTree(true); getAllDirectoryAsTree(true);
...@@ -149,12 +184,24 @@ const AssetTree = (props) => { ...@@ -149,12 +184,24 @@ const AssetTree = (props) => {
url = 'assetmanage.queryResourceDirectoryAsTree'; url = 'assetmanage.queryResourceDirectoryAsTree';
} }
if (viewSelectedKeyRef.current === 'custom') {
url = 'assetmanage.queryCustomTypeRootDirectory';
}
dispatch({ dispatch({
type: url, type: url,
callback: data => { callback: data => {
setLoading(false); setLoading(false);
let newData = [...data]; let newData = [];
if (viewSelectedKeyRef.current==='dir') {
newData = [...data];
} else {
newData = (data||[]).map((item) => {
console.log(item);
return {...item, text: item.name, nodeId: item.id, type: item.resourceType}
});
}
if (reference === Asset1104ManageReference) { if (reference === Asset1104ManageReference) {
function recursion1104(subCatalogs) { function recursion1104(subCatalogs) {
...@@ -178,6 +225,7 @@ const AssetTree = (props) => { ...@@ -178,6 +225,7 @@ const AssetTree = (props) => {
newData = newData.filter(item => item.type!=='custom'); newData = newData.filter(item => item.type!=='custom');
} }
setLoadedKeys([]);
setTreeData(newData); setTreeData(newData);
const _dataList = [], _groupIds = []; const _dataList = [], _groupIds = [];
...@@ -211,6 +259,7 @@ const AssetTree = (props) => { ...@@ -211,6 +259,7 @@ const AssetTree = (props) => {
} }
if (resetCurrentDirId) { if (resetCurrentDirId) {
if (viewSelectedKeyRef.current==='custom') { defaultItem = newData[0]; }
if (defaultItem) { if (defaultItem) {
const expandedKeys = _dataList const expandedKeys = _dataList
...@@ -467,6 +516,62 @@ const AssetTree = (props) => { ...@@ -467,6 +516,62 @@ const AssetTree = (props) => {
setCustomDirectoryModalVisible(true); setCustomDirectoryModalVisible(true);
} }
const onViewClick = ({ key }) => {
if (viewSelectedKey && viewSelectedKey===key ) return;
viewSelectedKeyRef.current = key;
setViewSelectedKey(key);
setExpandedKeys([]);
getAllDirectoryAsTree();
}
const viewMenus = (
<Menu selectedKeys={[viewSelectedKey]} onClick={onViewClick}>
{
viewModes && viewModes.map(item => {
return (
<Menu.Item key={item.key} value={item.key} >
<div style={{ textAlign: 'center' }}>
{item.name}
</div>
</Menu.Item>
)
})
}
</Menu>
);
const onLoadData = ({ key, children }) =>
new Promise((resolve) => {
if (children) {
resolve();
return;
}
setLoadedKeys([...loadedKeys, key]);
dispatch({
type: 'assetmanage.getDirectoryChild',
payload: {
parentId: key,
},
callback: (data) => {
if (data && data.length>0) {
let newTreeData = updateTreeData(treeData, key, data);
setTreeData(newTreeData);
treeDataRef.current = newTreeData;
}
resolve();
},
error: () => {
resolve();
}
});
});
// const onChange = (e) => { // const onChange = (e) => {
// const { value } = e.target; // const { value } = e.target;
...@@ -607,24 +712,33 @@ const AssetTree = (props) => { ...@@ -607,24 +712,33 @@ const AssetTree = (props) => {
</Menu> </Menu>
); );
const loop = (data, isRootLeaf= true) => const loop = (data, rootResourceType = null) =>
data.map(item => { data.map(item => {
if (item.level === 1) {
rootResourceType = item.resourceType;
}
const title = ( const title = (
<span <span
className={isRootLeaf?'title-color': 'text-color'} className={(item.level===1)?'title-color': 'text-color'}
> >
{item.text} {item.text}
{ {
reference === AssetManageReference && <span>{` (${item.dataAssetAndSubDirCount})`}</span> //自定义类型栏目不统计资产数
(item.level!==1||(item.level===1&&item.resourceType!=='custom')) && <span>{` (${item.dataAssetAndSubDirCount})`}</span>
} }
</span> </span>
); );
if (item.children) { if (item.children && item.children.length>0) {
return { ...item, ...{title, key: item.nodeId, children: loop(item.children, false)} }; return { ...item, ...{title, key: item.nodeId, children: loop(item.children, rootResourceType), className: (item.level===1)?'root':''} };
} }
return { ...item, ...{ title, key: item.nodeId }}; if (rootResourceType !== 'custom') {
return { ...item, ...{ title, key: item.nodeId, isLeaf: true, className: (item.level===1)?'root':'' }};
}
return { ...item, ...{ title, key: item.nodeId, children: null, className: (item.level===1)?'root':''}};
}); });
const classes = classNames('asset-tree', className, { const classes = classNames('asset-tree', className, {
...@@ -644,6 +758,13 @@ const AssetTree = (props) => { ...@@ -644,6 +758,13 @@ const AssetTree = (props) => {
justifyContent: 'space-around', justifyContent: 'space-around',
}} }}
> >
<Dropdown overlay={viewMenus} placement="bottomLeft">
<Tooltip title="视角">
<UnorderedListOutlined className='default' style={{ fontSize:16,cursor:'pointer' }} />
</Tooltip>
</Dropdown>
{
(viewSelectedKeyRef.current==='dir') ? <React.Fragment>
<Tooltip title="新增目录"> <Tooltip title="新增目录">
<PlusOutlined className={(currentDirType==='custom')?'disable': 'default'} onClick={addDir} style={{ fontSize:16,cursor: (currentDirType==='custom')?'not-allowed':'pointer' }}/> <PlusOutlined className={(currentDirType==='custom')?'disable': 'default'} onClick={addDir} style={{ fontSize:16,cursor: (currentDirType==='custom')?'not-allowed':'pointer' }}/>
</Tooltip> </Tooltip>
...@@ -658,12 +779,21 @@ const AssetTree = (props) => { ...@@ -658,12 +779,21 @@ const AssetTree = (props) => {
<ExportOutlined className='default' style={{ fontSize:16,cursor:'pointer' }} /> <ExportOutlined className='default' style={{ fontSize:16,cursor:'pointer' }} />
</Tooltip> </Tooltip>
</Dropdown> </Dropdown>
<Tooltip title="自定义目录">
<SettingOutlined className='default' onClick={customDir} style={{ fontSize:16,cursor:'pointer' }} />
</Tooltip>
<Tooltip title="资产价值评分"> <Tooltip title="资产价值评分">
<CalculatorOutlined className='default' onClick={() => {setComputeScoreVisible(true)}} style={{ fontSize:16,cursor:'pointer' }} /> <CalculatorOutlined className='default' onClick={() => {setComputeScoreVisible(true)}} style={{ fontSize:16,cursor:'pointer' }} />
</Tooltip> </Tooltip>
</React.Fragment> : <React.Fragment>
<Tooltip title="刷新目录">
<ReloadOutlined className='default' onClick={refreshTree} style={{ fontSize:16,cursor:'pointer' }} />
</Tooltip>
<Tooltip title="自定义目录">
<SettingOutlined className='default' onClick={customDir} style={{ fontSize:16,cursor:'pointer' }} />
</Tooltip>
<div />
<div />
<div />
</React.Fragment>
}
</div> </div>
)} )}
bordered={false} bordered={false}
...@@ -672,7 +802,7 @@ const AssetTree = (props) => { ...@@ -672,7 +802,7 @@ const AssetTree = (props) => {
style={{ width: '100%' }} style={{ width: '100%' }}
> >
<Spin spinning={loading}> <Spin spinning={loading}>
<AutoComplete {viewSelectedKeyRef.current==='dir' && <AutoComplete
allowClear allowClear
value={keyword} value={keyword}
style={{ marginBottom: 10, width: '100%' }} style={{ marginBottom: 10, width: '100%' }}
...@@ -692,6 +822,7 @@ const AssetTree = (props) => { ...@@ -692,6 +822,7 @@ const AssetTree = (props) => {
}) })
} }
</AutoComplete> </AutoComplete>
}
<Tree <Tree
checkable={checkable} checkable={checkable}
showLine={true} showLine={true}
...@@ -700,6 +831,8 @@ const AssetTree = (props) => { ...@@ -700,6 +831,8 @@ const AssetTree = (props) => {
expandedKeys={expandedKeys} expandedKeys={expandedKeys}
autoExpandParent={autoExpandParent} autoExpandParent={autoExpandParent}
treeData={loop(treeData)} treeData={loop(treeData)}
loadData={onLoadData}
loadedKeys={loadedKeys}
selectedKeys={[currentDirId||'']} selectedKeys={[currentDirId||'']}
onSelect={onTreeSelect} onSelect={onTreeSelect}
onCheck={onTreeCheck} onCheck={onTreeCheck}
...@@ -737,6 +870,8 @@ const AssetTree = (props) => { ...@@ -737,6 +870,8 @@ const AssetTree = (props) => {
/> />
{ {
(reference!==AssetMountReference) && <RcMenu id={MENU_ID}> (reference!==AssetMountReference) && <RcMenu id={MENU_ID}>
{
viewSelectedKeyRef.current==='dir' && <React.Fragment>
<RcItem id="edit" onClick={editDir}> <RcItem id="edit" onClick={editDir}>
修改目录 修改目录
</RcItem> </RcItem>
...@@ -746,6 +881,8 @@ const AssetTree = (props) => { ...@@ -746,6 +881,8 @@ const AssetTree = (props) => {
<RcItem id="down" onClick={() => { moveNode(-1); }}> <RcItem id="down" onClick={() => { moveNode(-1); }}>
下移目录 下移目录
</RcItem> </RcItem>
</React.Fragment>
}
<RcItem id="delete" onClick={deleteDir}> <RcItem id="delete" onClick={deleteDir}>
删除目录 删除目录
</RcItem> </RcItem>
......
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