diff --git a/src/components/Table/index.js b/src/components/Table/index.js index 7f6200e..d380472 100644 --- a/src/components/Table/index.js +++ b/src/components/Table/index.js @@ -7,38 +7,6 @@ import { getDataType, getIndexColumn } from "../../utils"; import "use-antd-resizable-header/dist/style.css"; import "./index.less"; -const CLEANUP_INTERVAL_DAYS = 10; // 清理间隔天数 -const LAST_CLEANUP_KEY = "tableLocalStorageLastCleanup"; // 最后清理时间存储key - -// 清理本地存储中特定后缀的key -function cleanupTableLocalStorage() { - const now = dayjs(); - const lastCleanupStr = localStorage.getItem(LAST_CLEANUP_KEY); - const lastCleanup = lastCleanupStr ? dayjs(lastCleanupStr) : null; - - // 如果没有上次清理时间或距离上次清理已超过10天 - if (!lastCleanup || now.diff(lastCleanup, "day") >= CLEANUP_INTERVAL_DAYS) { - // 查找并清理符合条件的key - const keysToRemove = []; - for (let i = 0; i < localStorage.length; i++) { - const key = localStorage.key(i); - if (key && (key.endsWith("#columnState") - || key.endsWith("#size") - || key.endsWith("#resizable"))) { - keysToRemove.push(key); - } - } - - // 删除匹配的key - keysToRemove.forEach((key) => { - localStorage.removeItem(key); - }); - - // 更新最后清理时间 - localStorage.setItem(LAST_CLEANUP_KEY, now.toISOString()); - } -} - function getPersistenceKey(index) { const basename = process.env?.app?.basename; const pathname = decodeURIComponent(window.location.pathname); @@ -52,11 +20,11 @@ function getPersistenceKey(index) { } function getTableSize(index) { - return window.localStorage.getItem(getPersistenceKey(index).size); + return window.sessionStorage.getItem(getPersistenceKey(index).size); } function setTableSize(value, index) { - return window.localStorage.setItem(getPersistenceKey(index).size, value); + return window.sessionStorage.setItem(getPersistenceKey(index).size, value); } function Table(props) { @@ -94,7 +62,7 @@ function Table(props) { columns, columnsState: { persistenceKey: persistenceKey.resizable, - persistenceType: "localStorage", + persistenceType: "sessionStorage", }, }); @@ -146,8 +114,6 @@ function Table(props) { }); } - cleanupTableLocalStorage(); - return () => { if (mutationObserver && resizeObserver && enabledResizer) { resizeObserver.unobserve(document.body); @@ -203,7 +169,7 @@ function Table(props) { components={components} columnsState={{ persistenceKey: persistenceKey.columnState, - persistenceType: "localStorage", + persistenceType: "sessionStorage", }} onSizeChange={setSize} columns={processedColumns}