style: lock body scroll bar when open a modal
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import useBodyScroll from '@/hooks/use-body-scroll';
|
||||||
import { ExclamationCircleFilled } from '@ant-design/icons';
|
import { ExclamationCircleFilled } from '@ant-design/icons';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import { Button, Modal, Space, message, type ModalFuncProps } from 'antd';
|
import { Button, Modal, Space, message, type ModalFuncProps } from 'antd';
|
||||||
@@ -6,6 +7,7 @@ import Styles from './index.less';
|
|||||||
|
|
||||||
const DeleteModal = forwardRef((props, ref) => {
|
const DeleteModal = forwardRef((props, ref) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const { saveScrollHeight, restoreScrollHeight } = useBodyScroll();
|
||||||
const [visible, setVisible] = useState(false);
|
const [visible, setVisible] = useState(false);
|
||||||
const [config, setConfig] = useState<
|
const [config, setConfig] = useState<
|
||||||
ModalFuncProps & {
|
ModalFuncProps & {
|
||||||
@@ -31,23 +33,27 @@ const DeleteModal = forwardRef((props, ref) => {
|
|||||||
operation: string;
|
operation: string;
|
||||||
}
|
}
|
||||||
) => {
|
) => {
|
||||||
|
saveScrollHeight();
|
||||||
setConfig(data);
|
setConfig(data);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
},
|
},
|
||||||
hide: () => {
|
hide: () => {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
|
restoreScrollHeight();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleCancel = () => {
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
config.onCancel?.();
|
config.onCancel?.();
|
||||||
|
restoreScrollHeight();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOk = async () => {
|
const handleOk = async () => {
|
||||||
await config.onOk?.();
|
await config.onOk?.();
|
||||||
message.success(intl.formatMessage({ id: 'common.message.success' }));
|
message.success(intl.formatMessage({ id: 'common.message.success' }));
|
||||||
setVisible(false);
|
setVisible(false);
|
||||||
|
restoreScrollHeight();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export default function useBodyScroll() {
|
|||||||
const bodyScroller = React.useRef<any>(null);
|
const bodyScroller = React.useRef<any>(null);
|
||||||
|
|
||||||
const instanceRef = React.useRef<any>(null);
|
const instanceRef = React.useRef<any>(null);
|
||||||
|
const timer = React.useRef<any>(null);
|
||||||
|
|
||||||
const int = () => {
|
const int = () => {
|
||||||
bodyScroller.current =
|
bodyScroller.current =
|
||||||
@@ -16,10 +17,11 @@ export default function useBodyScroll() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const saveScrollHeight = React.useCallback(() => {
|
const saveScrollHeight = React.useCallback(() => {
|
||||||
|
if (!bodyScroller.current) {
|
||||||
|
int();
|
||||||
|
}
|
||||||
scrollerState.current = instanceRef.current?.state();
|
scrollerState.current = instanceRef.current?.state();
|
||||||
|
|
||||||
console.log('saveScrollHeight', scrollerState.current?.overflowAmount?.y);
|
|
||||||
|
|
||||||
const scrollTop = scrollerState.current?.overflowAmount?.y;
|
const scrollTop = scrollerState.current?.overflowAmount?.y;
|
||||||
scrollHeight.current = scrollTop;
|
scrollHeight.current = scrollTop;
|
||||||
instanceRef.current?.options?.({
|
instanceRef.current?.options?.({
|
||||||
@@ -31,21 +33,17 @@ export default function useBodyScroll() {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const restoreScrollHeight = React.useCallback(() => {
|
const restoreScrollHeight = React.useCallback(() => {
|
||||||
console.log('saveScrollHeight++++++++++', scrollHeight.current);
|
if (timer.current) {
|
||||||
|
clearTimeout(timer.current);
|
||||||
bodyScroller.current?.scrollTo?.({
|
}
|
||||||
top: scrollHeight.current,
|
timer.current = setTimeout(() => {
|
||||||
behavior: 'smooth'
|
instanceRef.current?.options?.({
|
||||||
});
|
overflow: {
|
||||||
|
x: 'hidden',
|
||||||
instanceRef.current?.options?.({
|
y: 'scroll'
|
||||||
overflow: {
|
}
|
||||||
x: 'hidden',
|
});
|
||||||
y: 'scroll'
|
}, 1000);
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
instanceRef.current?.update?.();
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { modelsExpandKeysAtom } from '@/atoms/models';
|
import { modelsExpandKeysAtom } from '@/atoms/models';
|
||||||
import PageTools from '@/components/page-tools';
|
import PageTools from '@/components/page-tools';
|
||||||
import { PageAction } from '@/config';
|
import { PageAction } from '@/config';
|
||||||
|
import useBodyScroll from '@/hooks/use-body-scroll';
|
||||||
import { SyncOutlined } from '@ant-design/icons';
|
import { SyncOutlined } from '@ant-design/icons';
|
||||||
import { PageContainer } from '@ant-design/pro-components';
|
import { PageContainer } from '@ant-design/pro-components';
|
||||||
import { useIntl, useNavigate } from '@umijs/max';
|
import { useIntl, useNavigate } from '@umijs/max';
|
||||||
@@ -16,6 +17,7 @@ import { CatalogItem as CatalogItemType, FormData } from './config/types';
|
|||||||
|
|
||||||
const Catalog: React.FC = () => {
|
const Catalog: React.FC = () => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
const { saveScrollHeight, restoreScrollHeight } = useBodyScroll();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [activeId, setActiveId] = React.useState(-1);
|
const [activeId, setActiveId] = React.useState(-1);
|
||||||
const [isFirst, setIsFirst] = React.useState(true);
|
const [isFirst, setIsFirst] = React.useState(true);
|
||||||
@@ -109,10 +111,12 @@ const Catalog: React.FC = () => {
|
|||||||
...openDeployModal,
|
...openDeployModal,
|
||||||
show: false
|
show: false
|
||||||
});
|
});
|
||||||
|
restoreScrollHeight();
|
||||||
setActiveId(-1);
|
setActiveId(-1);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOnDeploy = useCallback((item: CatalogItemType) => {
|
const handleOnDeploy = useCallback((item: CatalogItemType) => {
|
||||||
|
saveScrollHeight();
|
||||||
setActiveId(item.id);
|
setActiveId(item.id);
|
||||||
setOpenDeployModal({
|
setOpenDeployModal({
|
||||||
show: true,
|
show: true,
|
||||||
|
|||||||
@@ -225,6 +225,8 @@ const InstanceItem: React.FC<InstanceItemProps> = ({
|
|||||||
<Tag
|
<Tag
|
||||||
color="cyan"
|
color="cyan"
|
||||||
style={{
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
maxWidth: '100%',
|
maxWidth: '100%',
|
||||||
minWidth: 50,
|
minWidth: 50,
|
||||||
textOverflow: 'ellipsis',
|
textOverflow: 'ellipsis',
|
||||||
@@ -251,6 +253,8 @@ const InstanceItem: React.FC<InstanceItemProps> = ({
|
|||||||
<Tag
|
<Tag
|
||||||
color="processing"
|
color="processing"
|
||||||
style={{
|
style={{
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
maxWidth: '100%',
|
maxWidth: '100%',
|
||||||
minWidth: 50,
|
minWidth: 50,
|
||||||
textOverflow: 'ellipsis',
|
textOverflow: 'ellipsis',
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import SealTable from '@/components/seal-table';
|
|||||||
import SealColumn from '@/components/seal-table/components/seal-column';
|
import SealColumn from '@/components/seal-table/components/seal-column';
|
||||||
import { PageAction } from '@/config';
|
import { PageAction } from '@/config';
|
||||||
import HotKeys from '@/config/hotkeys';
|
import HotKeys from '@/config/hotkeys';
|
||||||
|
import useBodyScroll from '@/hooks/use-body-scroll';
|
||||||
import useExpandedRowKeys from '@/hooks/use-expanded-row-keys';
|
import useExpandedRowKeys from '@/hooks/use-expanded-row-keys';
|
||||||
import useTableRowSelection from '@/hooks/use-table-row-selection';
|
import useTableRowSelection from '@/hooks/use-table-row-selection';
|
||||||
import useTableSort from '@/hooks/use-table-sort';
|
import useTableSort from '@/hooks/use-table-sort';
|
||||||
@@ -130,6 +131,7 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
loadend,
|
loadend,
|
||||||
total
|
total
|
||||||
}) => {
|
}) => {
|
||||||
|
const { saveScrollHeight, restoreScrollHeight } = useBodyScroll();
|
||||||
const [expandAtom, setExpandAtom] = useAtom(modelsExpandKeysAtom);
|
const [expandAtom, setExpandAtom] = useAtom(modelsExpandKeysAtom);
|
||||||
const access = useAccess();
|
const access = useAccess();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
@@ -362,6 +364,7 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
setOpenAddModal(false);
|
setOpenAddModal(false);
|
||||||
message.success(intl.formatMessage({ id: 'common.message.success' }));
|
message.success(intl.formatMessage({ id: 'common.message.success' }));
|
||||||
handleSearch();
|
handleSearch();
|
||||||
|
restoreScrollHeight();
|
||||||
} catch (error) {}
|
} catch (error) {}
|
||||||
},
|
},
|
||||||
[currentData]
|
[currentData]
|
||||||
@@ -369,6 +372,7 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
|
|
||||||
const handleModalCancel = useCallback(() => {
|
const handleModalCancel = useCallback(() => {
|
||||||
setOpenAddModal(false);
|
setOpenAddModal(false);
|
||||||
|
restoreScrollHeight();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleDeployModalCancel = () => {
|
const handleDeployModalCancel = () => {
|
||||||
@@ -408,6 +412,7 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
const handleLogModalCancel = useCallback(() => {
|
const handleLogModalCancel = useCallback(() => {
|
||||||
setOpenLogModal(false);
|
setOpenLogModal(false);
|
||||||
onCancelViewLogs();
|
onCancelViewLogs();
|
||||||
|
restoreScrollHeight();
|
||||||
}, [onCancelViewLogs]);
|
}, [onCancelViewLogs]);
|
||||||
|
|
||||||
const handleDelete = async (row: any) => {
|
const handleDelete = async (row: any) => {
|
||||||
@@ -478,6 +483,7 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
});
|
});
|
||||||
setOpenLogModal(true);
|
setOpenLogModal(true);
|
||||||
onViewLogs();
|
onViewLogs();
|
||||||
|
saveScrollHeight();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('error:', error);
|
console.log('error:', error);
|
||||||
}
|
}
|
||||||
@@ -518,6 +524,7 @@ const Models: React.FC<ModelsProps> = ({
|
|||||||
const handleEdit = (row: ListItem) => {
|
const handleEdit = (row: ListItem) => {
|
||||||
setCurrentData(row);
|
setCurrentData(row);
|
||||||
setOpenAddModal(true);
|
setOpenAddModal(true);
|
||||||
|
saveScrollHeight();
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSelect = useCallback(
|
const handleSelect = useCallback(
|
||||||
|
|||||||
Reference in New Issue
Block a user