Commit 247742eb by zhaochengxiang

地图性能优化

parent 346fee25
...@@ -62,7 +62,7 @@ export default class App extends React.Component { ...@@ -62,7 +62,7 @@ export default class App extends React.Component {
<Route path={'/center-home/view/asset-map'} component={Map} exact /> <Route path={'/center-home/view/asset-map'} component={Map} exact />
<Route path={'/center-home/view/asset-manage'} component={AssetManage} exact /> <Route path={'/center-home/view/asset-manage'} component={AssetManage} exact />
<Route path={'/center-home/view/asset-browse'} component={AssetBrowse} exact /> <Route path={'/center-home/view/asset-browse'} component={AssetBrowse} exact />
<Route path={'/center-home/view/asset-recycle'} component={AssetRecycle} exact /> <Route path={'/center-home/view/asset-recycle'} component={AssetRecycle} exact />
</Switch> </Switch>
</Router> </Router>
</React.Fragment> </React.Fragment>
......
...@@ -16,3 +16,7 @@ export function* getTreeTotalLevel(payload) { ...@@ -16,3 +16,7 @@ export function* getTreeTotalLevel(payload) {
export function* queryAllDirectoryAsTreeByDirLevel(payload) { export function* queryAllDirectoryAsTreeByDirLevel(payload) {
return yield call(service.queryAllDirectoryAsTreeByDirLevel, payload); return yield call(service.queryAllDirectoryAsTreeByDirLevel, payload);
} }
export function* getTableModelInfoByDirIdAndBeginIndex(payload) {
return yield call(service.getTableModelInfoByDirIdAndBeginIndex, payload);
}
...@@ -15,3 +15,7 @@ export function getTreeTotalLevel(payload) { ...@@ -15,3 +15,7 @@ export function getTreeTotalLevel(payload) {
export function queryAllDirectoryAsTreeByDirLevel(payload) { export function queryAllDirectoryAsTreeByDirLevel(payload) {
return GetJSON("/dataassetmanager/countApi/queryAllDirectoryAsTreeByDirLevel", payload); return GetJSON("/dataassetmanager/countApi/queryAllDirectoryAsTreeByDirLevel", payload);
} }
export function getTableModelInfoByDirIdAndBeginIndex(payload) {
return GetJSON("/dataassetmanager/countApi/getTableModelInfoByDirIdAndBeginIndex", payload);
}
import React from 'react'; import React from 'react';
import G6 from '@antv/g6'; import G6 from '@antv/g6';
// import { ContextPath } from '../../../../util';
let graph = null; let graph = null;
const globalFontSize = 20; const globalFontSize = 20;
...@@ -32,7 +30,7 @@ const EXPAND_ICON = function EXPAND_ICON(x, y, r) { ...@@ -32,7 +30,7 @@ const EXPAND_ICON = function EXPAND_ICON(x, y, r) {
class Org extends React.Component { class Org extends React.Component {
componentDidMount() { componentDidMount() {
const { type, loadMoreData } = this.props; const { type, loadSubLeafData, loadMoreLeafData, onAssetClick } = this.props;
const container = document.getElementById(`container${type||''}`); const container = document.getElementById(`container${type||''}`);
if (!container) return; if (!container) return;
...@@ -68,7 +66,7 @@ class Org extends React.Component { ...@@ -68,7 +66,7 @@ class Org extends React.Component {
const bbox = text.getBBox(); const bbox = text.getBBox();
if (cfg.dbType==='Root' || cfg.dbType==='Dir') { if (cfg.dbType==='Dir') {
if (!cfg.children) { if (!cfg.children) {
group.addShape('marker', { group.addShape('marker', {
attrs: { attrs: {
...@@ -99,7 +97,7 @@ class Org extends React.Component { ...@@ -99,7 +97,7 @@ class Org extends React.Component {
rect.attr({ rect.attr({
x: bbox.minX - 10, x: bbox.minX - 10,
y: bbox.minY - 10, y: bbox.minY - 10,
width: bbox.width + ((cfg.dbType==='Root'||cfg.dbType==='Dir')&&(!cfg.children||((cfg.children||[]).length>0)) ? 38 : 20), width: bbox.width + (cfg.dbType==='Dir'&&(!cfg.children||((cfg.children||[]).length>0)) ? 38 : 20),
height: bbox.height + 20, height: bbox.height + 20,
}); });
...@@ -258,13 +256,21 @@ class Org extends React.Component { ...@@ -258,13 +256,21 @@ class Org extends React.Component {
const model = node.getModel(); const model = node.getModel();
if (model.dbType==='Root' || model.dbType==='Dir') { if (model.dbType==='Dir') {
const children = model.children; const children = model.children;
if (!children && loadMoreData) { if (!children && loadSubLeafData) {
loadMoreData(model.dirId||'', nodeId); loadSubLeafData(model.dirId||'', nodeId);
} }
} else if (model.dbType === 'Table') { } else if (model.dbType === 'Table') {
onAssetClick && onAssetClick(model.tid);
} else if (model.dbType === 'More') {
loadMoreLeafData && loadMoreLeafData(model.pDirId, model.pid, model.index);
} }
}); });
...@@ -297,7 +303,9 @@ class Org extends React.Component { ...@@ -297,7 +303,9 @@ class Org extends React.Component {
if (!parentData.children) { if (!parentData.children) {
parentData.children = []; parentData.children = [];
} }
parentData.children = childData;
parentData.children = parentData.children.filter(item => item.dbType!=='More');
parentData.children = [...parentData.children, ...childData];
graph.changeData(); graph.changeData();
graph.updateItem(graph.findById(parentNodeId), { graph.updateItem(graph.findById(parentNodeId), {
......
...@@ -29,13 +29,15 @@ class Relation extends React.Component { ...@@ -29,13 +29,15 @@ class Relation extends React.Component {
} }
componentDidUpdate(prevProps, _prevState) { componentDidUpdate(prevProps, _prevState) {
const { childData, parentNodeId, data } = this.props; const { childData, parentNodeId } = this.props;
if (parentNodeId && parentNodeId !== prevProps.parentNodeId) { if (parentNodeId && parentNodeId !== prevProps.parentNodeId) {
const parentData = this.graph?.findDataById(parentNodeId); const parentData = this.graph?.findDataById(parentNodeId);
if (!parentData.children) { if (!parentData.children) {
parentData.children = []; parentData.children = [];
} }
parentData.children = childData;
parentData.children = parentData.children.filter(item => item.dbType!=='More');
parentData.children = [...parentData.children, ...childData];
this.graph?.changeData(); this.graph?.changeData();
this.graph?.fitView(); this.graph?.fitView();
} else if (this.props.data) { } else if (this.props.data) {
...@@ -63,7 +65,7 @@ class Relation extends React.Component { ...@@ -63,7 +65,7 @@ class Relation extends React.Component {
export default Relation; export default Relation;
let root = null, depthCount = {} let depthCount = {}
function countDepth(node, _depth = 0) { function countDepth(node, _depth = 0) {
// node.text = "测试123567890" // node.text = "测试123567890"
...@@ -173,31 +175,30 @@ const init = (ctx) => function (container, data) { ...@@ -173,31 +175,30 @@ const init = (ctx) => function (container, data) {
focusNodes.forEach((fnode) => { focusNodes.forEach((fnode) => {
graph.setItemState(fnode, 'focus', false); // false graph.setItemState(fnode, 'focus', false); // false
}); });
const { item, target } = evt; const { item } = evt;
graph.setItemState(item, 'focus', true); graph.setItemState(item, 'focus', true);
graph.setItemState(item, 'hover', false); graph.setItemState(item, 'hover', false);
const targetType = target.get('type'); const model = item.getModel();
const name = target.get('name'); const nodeId = item.get('id');
if (targetType === 'marker') { // 响应展开按钮
const model = item.getModel(); if (model.dbType==='Dir') {
if (name === 'add-item') {
const nodeId = item.get('id'); const children = model.children;
if (model.dbType === 'Dir') { if (!children) {
const children = model.children; ctx.props?.loadSubLeafData(model.dirId||'', nodeId);
if (!children) {
ctx.props?.loadMoreData(model.dirId || '', nodeId);
}
} else if (model.dbType !== 'Root') {
//通过资产id跳转到资产详情页
// history && history.push(`${ContextPath}/home`);
}
} }
} else { // 展示 node 详情
} else if (model.dbType === 'Table') {
ctx.props?.onAssetClick(model.tid);
} else if (model.dbType === 'More') {
ctx.props?.loadMoreLeafData(model.pDirId, model.pid, model.index);
} }
}); });
if (typeof window !== 'undefined') if (typeof window !== 'undefined')
...@@ -224,9 +225,9 @@ G6.registerNode( ...@@ -224,9 +225,9 @@ G6.registerNode(
width1 = r * 2.5 width1 = r * 2.5
width2 = r * 4 width2 = r * 4
if (cfg.depth === 0) { // if (cfg.depth === 0) {
root = cfg // root = cfg
} // }
// if (depthCount[cfg.depth] > 10) { // if (depthCount[cfg.depth] > 10) {
group.addShape('image', { group.addShape('image', {
...@@ -304,7 +305,7 @@ G6.registerNode( ...@@ -304,7 +305,7 @@ G6.registerNode(
} }
const bbox = keyShape.getBBox() const bbox = keyShape.getBBox()
if (cfg.dbType === 'Root' || cfg.dbType === 'Dir') { if (cfg.dbType === 'Dir') {
if (!cfg.children) { if (!cfg.children) {
const marker = group.addShape('marker', { const marker = group.addShape('marker', {
attrs: { attrs: {
...@@ -399,7 +400,7 @@ G6.registerNode( ...@@ -399,7 +400,7 @@ G6.registerNode(
'aggregated-node', 'aggregated-node',
); // 这样可以继承 aggregated-node 的 setState ); // 这样可以继承 aggregated-node 的 setState
const lineDash = [4, 2, 1, 2]; // const lineDash = [4, 2, 1, 2];
G6.registerEdge( G6.registerEdge(
'custom-line', 'custom-line',
{ {
...@@ -546,19 +547,19 @@ const formatText = (text, length = 5, elipsis = '...') => { ...@@ -546,19 +547,19 @@ const formatText = (text, length = 5, elipsis = '...') => {
} }
return text; return text;
}; };
function textXY(root, cfg) { // function textXY(root, cfg) {
const txtWidth = cfg.label.length > 5 ? 24 : cfg.label.length * 4 // const txtWidth = cfg.label.length > 5 ? 24 : cfg.label.length * 4
const { x, y } = cfg // const { x, y } = cfg
const _y = y - root.y, _x = x - root.x // const _y = y - root.y, _x = x - root.x
const angle = Math.atan2(_y, _x) // const angle = Math.atan2(_y, _x)
const sinAngle = Math.sin(angle), cosAngle = Math.cos(angle) // const sinAngle = Math.sin(angle), cosAngle = Math.cos(angle)
const radX = 4 + txtWidth // const radX = 4 + txtWidth
const radY = Math.abs(Math.pow(sinAngle, Math.abs(Math.round(sinAngle * 50)))) * 10 //Math.pow(Math.E, 80 * Math.log(Math.abs(sinAngle))) * 40 // const radY = Math.abs(Math.pow(sinAngle, Math.abs(Math.round(sinAngle * 50)))) * 10 //Math.pow(Math.E, 80 * Math.log(Math.abs(sinAngle))) * 40
return [ // return [
// 右侧文字(中间向右侧15px,上下部向左靠20px) : 左侧 // // 右侧文字(中间向右侧15px,上下部向左靠20px) : 左侧
radX * cosAngle, // radX * cosAngle,
radY * sinAngle + (sinAngle > 0 ? sinAngle * 20 : sinAngle * 10) // radY * sinAngle + (sinAngle > 0 ? sinAngle * 20 : sinAngle * 10)
]; // ];
} // }
import React from 'react'; import React from 'react';
import G6 from '@antv/g6'; import G6 from '@antv/g6';
// import { ContextPath } from '../../../../util';
let graph = null; let graph = null;
const globalFontSize = 20; const globalFontSize = 20;
const maxTextWidth = 160; const maxTextWidth = 160;
...@@ -31,7 +29,7 @@ const EXPAND_ICON = function EXPAND_ICON(x, y, r) { ...@@ -31,7 +29,7 @@ const EXPAND_ICON = function EXPAND_ICON(x, y, r) {
class Tree extends React.Component { class Tree extends React.Component {
componentDidMount() { componentDidMount() {
const { type, loadMoreData } = this.props; const { type, loadSubLeafData, loadMoreLeafData, onAssetClick } = this.props;
const container = document.getElementById(`container${type||''}`); const container = document.getElementById(`container${type||''}`);
if (!container) return; if (!container) return;
...@@ -68,7 +66,7 @@ class Tree extends React.Component { ...@@ -68,7 +66,7 @@ class Tree extends React.Component {
const bbox = text.getBBox(); const bbox = text.getBBox();
if (cfg.dbType==='Root' || cfg.dbType==='Dir') { if (cfg.dbType==='Dir') {
if (!cfg.children) { if (!cfg.children) {
group.addShape('marker', { group.addShape('marker', {
attrs: { attrs: {
...@@ -97,7 +95,7 @@ class Tree extends React.Component { ...@@ -97,7 +95,7 @@ class Tree extends React.Component {
rect.attr({ rect.attr({
x: bbox.minX - 10, x: bbox.minX - 10,
y: bbox.minY - 10, y: bbox.minY - 10,
width: bbox.width + ((cfg.dbType==='Root'||cfg.dbType==='Dir')&&(!cfg.children||((cfg.children||[]).length>0)) ? 38 : 20), width: bbox.width + (cfg.dbType==='Dir'&&(!cfg.children||((cfg.children||[]).length>0)) ? 38 : 20),
height: bbox.height + 20, height: bbox.height + 20,
}); });
...@@ -217,13 +215,20 @@ class Tree extends React.Component { ...@@ -217,13 +215,20 @@ class Tree extends React.Component {
const model = node.getModel(); const model = node.getModel();
if (model.dbType==='Dir') { if (model.dbType==='Dir') {
const children = model.children; const children = model.children;
if (!children && loadMoreData) { if (!children && loadSubLeafData) {
loadMoreData(model.dirId||'', nodeId); loadSubLeafData(model.dirId||'', nodeId);
} }
} else if (model.dbType !== 'Root') {
//通过资产id跳转到资产详情页 } else if (model.dbType === 'Table') {
// history && history.push(`${ContextPath}/home`);
onAssetClick && onAssetClick(model.tid);
} else if (model.dbType === 'More') {
loadMoreLeafData && loadMoreLeafData(model.pDirId, model.pid, model.index);
} }
}); });
...@@ -256,7 +261,9 @@ class Tree extends React.Component { ...@@ -256,7 +261,9 @@ class Tree extends React.Component {
if (!parentData.children) { if (!parentData.children) {
parentData.children = []; parentData.children = [];
} }
parentData.children = childData;
parentData.children = parentData.children.filter(item => item.dbType!=='More');
parentData.children = [...parentData.children, ...childData];
graph.changeData(); graph.changeData();
graph.updateItem(graph.findById(parentNodeId), { graph.updateItem(graph.findById(parentNodeId), {
......
...@@ -8,7 +8,8 @@ import Tree from './Component/Tree'; ...@@ -8,7 +8,8 @@ import Tree from './Component/Tree';
import Relation from './Component/Relation'; import Relation from './Component/Relation';
import { dispatch, dispatchLatest } from '../../../model'; import { dispatch, dispatchLatest } from '../../../model';
const column = 4; // const column = 4;
const defaultLoadCount = 10;
class MapContent extends React.Component { class MapContent extends React.Component {
...@@ -64,11 +65,22 @@ class MapContent extends React.Component { ...@@ -64,11 +65,22 @@ class MapContent extends React.Component {
dispatchLatest({ dispatchLatest({
type: 'map.queryAllDirectoryAsTreeByDirLevel', type: 'map.queryAllDirectoryAsTreeByDirLevel',
payload: { dirId: topic.id, dirLevel: level }, payload: {
dirId: topic.id,
dirLevel: level,
topNum: defaultLoadCount
},
callback: data => { callback: data => {
this.convertRemoteData(data); const _treeData = {
const _treeData = this.convertTreeModelData(data || []); text: topic.name || '',
dirId: topic.id,
id: `d${topic.id}`,
dbType: 'dir',
children: (data||[]).length===0 ? null : data
};
this.convertRemoteData(_treeData.children||[], _treeData.id, _treeData.dirId);
this.setState({ this.setState({
curTableModelData: data || [], curTableModelData: data || [],
...@@ -82,38 +94,33 @@ class MapContent extends React.Component { ...@@ -82,38 +94,33 @@ class MapContent extends React.Component {
}) })
} }
convertRemoteData = (data, parentDirId = '') => { convertRemoteData = (data, pid, pDirId, start=0) => {
data.forEach((item, index) => { data.forEach((item, index) => {
item.pid = pid||'';
item.pDirId = pDirId||'';
item.index = (index+start);
if (item.dbType === 'Dir') { if (item.dbType === 'Dir') {
item.text = item.dirName || ''; item.text = item.dirName || '';
item.id = `d${parentDirId}${item.dirId || ''}${index}`; item.id = `d${pDirId}${item.dirId || ''}${index}`;
} else { } else if (item.dbType === 'Table') {
item.text = item.cnName || ''; item.text = item.cnName || '';
item.id = `t${parentDirId}${item.id || ''}${index}`; item.tid = item.id||'';
item.id = `t${pDirId}${item.id || ''}${index}`;
} }
if (index === 10) { if (index === defaultLoadCount) {
item.text = '点击加载更多'; item.text = '点击加载更多';
item.dbType = 'More';
} }
if (item.children) { if (item.children) {
this.convertRemoteData(item.children, item.dirId || ''); this.convertRemoteData(item.children, item.id, item.dirId);
} }
}) })
} }
convertTreeModelData = (data) => {
const { topic } = this.props;
return {
text: topic.name || '',
dirId: topic.id,
id: `t${topic.id}`,
dbType: 'Root',
children: (data||[]).length===0 ? null : data
};
}
setSquareGraphState = (item) => { setSquareGraphState = (item) => {
const { breadcrumbContents } = this.state; const { breadcrumbContents } = this.state;
...@@ -150,19 +157,43 @@ class MapContent extends React.Component { ...@@ -150,19 +157,43 @@ class MapContent extends React.Component {
}) })
} }
loadMoreData = (dirId, nodeId) => { loadSubLeafData = (dirId, nodeId) => {
dispatchLatest({ this.setState({ parentNodeId: '' }, () => {
type: 'map.getTableModelByDirIid', dispatchLatest({
payload: { dirId }, type: 'map.getTableModelByDirIid',
callback: data => { payload: { dirId },
this.convertRemoteData(data || [], dirId); callback: data => {
this.setState({ this.convertRemoteData(data||[], nodeId, dirId);
parentNodeId: nodeId, this.setState({
orgChildData: JSON.parse(JSON.stringify(data || [])), parentNodeId: nodeId,
treeChildData: JSON.parse(JSON.stringify(data || [])), orgChildData: JSON.parse(JSON.stringify(data || [])),
relationChildData: JSON.parse(JSON.stringify(data)), treeChildData: JSON.parse(JSON.stringify(data || [])),
}); relationChildData: JSON.parse(JSON.stringify(data)),
} });
}
})
})
}
loadMoreLeafData = (dirId, nodeId, start) => {
this.setState({ parentNodeId: '' }, () => {
dispatchLatest({
type: 'map.getTableModelInfoByDirIdAndBeginIndex',
payload: {
dirId,
beginIndex: Number(start)+1,
topNum: defaultLoadCount
},
callback: data => {
this.convertRemoteData(data||[], nodeId, dirId, start);
this.setState({
parentNodeId: nodeId,
orgChildData: JSON.parse(JSON.stringify(data || [])),
treeChildData: JSON.parse(JSON.stringify(data || [])),
relationChildData: JSON.parse(JSON.stringify(data)),
});
}
})
}) })
} }
...@@ -172,6 +203,10 @@ class MapContent extends React.Component { ...@@ -172,6 +203,10 @@ class MapContent extends React.Component {
}); });
} }
onAssetClick = (id) => {
}
render() { render() {
const { type, topic, switchMode } = this.props; const { type, topic, switchMode } = this.props;
const { curTableModelData, breadcrumbContents, orgModelData, treeModelData, relationModelData, orgChildData, treeChildData, relationChildData, parentNodeId, currentLevel, totalLevel } = this.state; const { curTableModelData, breadcrumbContents, orgModelData, treeModelData, relationModelData, orgChildData, treeChildData, relationChildData, parentNodeId, currentLevel, totalLevel } = this.state;
...@@ -230,7 +265,9 @@ class MapContent extends React.Component { ...@@ -230,7 +265,9 @@ class MapContent extends React.Component {
parentNodeId={parentNodeId} parentNodeId={parentNodeId}
childData={orgChildData} childData={orgChildData}
type={`${topic.id || ''}${type}`} type={`${topic.id || ''}${type}`}
loadMoreData={this.loadMoreData} loadMoreLeafData={this.loadMoreLeafData}
loadSubLeafData={this.loadSubLeafData}
onAssetClick={this.onAssetClick}
/> />
} }
{ {
...@@ -239,7 +276,10 @@ class MapContent extends React.Component { ...@@ -239,7 +276,10 @@ class MapContent extends React.Component {
parentNodeId={parentNodeId} parentNodeId={parentNodeId}
childData={treeChildData} childData={treeChildData}
type={`${topic.id || ''}${type}`} type={`${topic.id || ''}${type}`}
loadMoreData={this.loadMoreData} /> loadMoreLeafData={this.loadMoreLeafData}
loadSubLeafData={this.loadSubLeafData}
onAssetClick={this.onAssetClick}
/>
} }
{ {
type === 'relation' && <Relation type === 'relation' && <Relation
...@@ -247,7 +287,10 @@ class MapContent extends React.Component { ...@@ -247,7 +287,10 @@ class MapContent extends React.Component {
parentNodeId={parentNodeId} parentNodeId={parentNodeId}
childData={relationChildData} childData={relationChildData}
type={`${topic.id || ''}${type}`} type={`${topic.id || ''}${type}`}
loadMoreData={this.loadMoreData} /> loadMoreLeafData={this.loadMoreLeafData}
loadSubLeafData={this.loadSubLeafData}
onAssetClick={this.onAssetClick}
/>
} }
<div <div
className='position-absolute text-right p-3' className='position-absolute text-right p-3'
......
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