Commit 56a52f8f by zhaochengxiang

资产滚动

parent 42a4b586
import React,{ useState, useEffect, useRef } from "react"; import React,{ useState, useEffect, useRef } from "react";
import { Button, Pagination, Space, Modal, Input, Table, Tooltip, Checkbox, Typography, Dropdown, Menu } from "antd"; import { Button, Pagination, Space, Modal, Input, Table, Tooltip, Checkbox, Typography, Dropdown, Menu } from "antd";
import classNames from 'classnames'; import classNames from 'classnames';
import SmoothScroll from 'smooth-scroll';
import { Resizable } from 'react-resizable'; import { Resizable } from 'react-resizable';
import ResizeObserver from 'rc-resize-observer'; import ResizeObserver from 'rc-resize-observer';
import { useContextMenu, Menu as RcMenu, Item as RcItem } from "react-contexify"; import { useContextMenu, Menu as RcMenu, Item as RcItem } from "react-contexify";
...@@ -192,9 +191,6 @@ const AssetTable = (props) => { ...@@ -192,9 +191,6 @@ const AssetTable = (props) => {
setCheckedKeys([]); setCheckedKeys([]);
if (shouldScrollRef.current === true) { if (shouldScrollRef.current === true) {
shouldScrollRef.current = false;
if (remoteRelationRef.current) { if (remoteRelationRef.current) {
getDataAssetLocationByRelation(); getDataAssetLocationByRelation();
} else { } else {
...@@ -225,20 +221,6 @@ const AssetTable = (props) => { ...@@ -225,20 +221,6 @@ const AssetTable = (props) => {
//eslint-disable-next-line react-hooks/exhaustive-deps //eslint-disable-next-line react-hooks/exhaustive-deps
}, [ keyword, pagination, elementsChanged, assetActionChanged, recursive, fullSearch ]) }, [ keyword, pagination, elementsChanged, assetActionChanged, recursive, fullSearch ])
useEffect(() => {
if (shouldScrollRef.current) {
SmoothScroll('a[href*="#"]');
var scroll = new SmoothScroll();
var anchor = document.querySelector(`#data-asset-${anchorId}`);
if (anchor) {
scroll.animateScroll(anchor);
shouldScrollRef.current = false;
}
}
})
const storageChange = (e) => { const storageChange = (e) => {
if (e.key === 'assetRelationOnClickEvent') { if (e.key === 'assetRelationOnClickEvent') {
remoteRelationRef.current = e.relation; remoteRelationRef.current = e.relation;
...@@ -247,7 +229,7 @@ const AssetTable = (props) => { ...@@ -247,7 +229,7 @@ const AssetTable = (props) => {
remoteRelationRef.current = { remoteRelationRef.current = {
dataAssetId: e.id, dataAssetId: e.id,
dirId: e.dirId dirId: e.dirId
}; };
shouldScrollRef.current = true; shouldScrollRef.current = true;
} }
} }
...@@ -460,12 +442,28 @@ const AssetTable = (props) => { ...@@ -460,12 +442,28 @@ const AssetTable = (props) => {
setAssets(_assets); setAssets(_assets);
if (shouldScrollRef.current) {
let scrollId = null;
if (remoteRelationRef.current) {
scrollId = remoteRelationRef.current.dataAssetId;
} else {
scrollId = anchorId;
}
shouldScrollRef.current = false;
setTimeout(() => {
var anchor = document.querySelector(`#data-asset-${scrollId}`);
anchor?.scrollIntoView();
}, 500)
}
if (reference === AssetManageReference) { if (reference === AssetManageReference) {
if (remoteRelationRef.current) { if (remoteRelationRef.current) {
const index = _assets.findIndex((asset) => asset.id === remoteRelationRef.current.dataAssetId); const index = _assets.findIndex((asset) => asset.id === remoteRelationRef.current.dataAssetId);
remoteRelationRef.current = null; remoteRelationRef.current = null;
if (index === -1) { if (index === -1) {
setSelectItem(_assets.length>0?_assets[0]:{}); setSelectItem(_assets.length>0?_assets[0]:{});
onSelect && onSelect(_assets.length>0?_assets[0].id:'', _assets.length>0?_assets[0].dirId:''); onSelect && onSelect(_assets.length>0?_assets[0].id:'', _assets.length>0?_assets[0].dirId:'');
......
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