From 843648c69b9a73fcaa753d0e8ac19fd39865de78 Mon Sep 17 00:00:00 2001 From: LiuJiaNan <15703339975@163.com> Date: Tue, 4 Aug 2026 15:28:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor(table):=20=E7=A7=BB=E9=99=A4=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E5=AD=98=E5=82=A8=E6=B8=85=E7=90=86=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E5=B9=B6=E6=94=B9=E7=94=A8sessionStorage=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E8=A1=A8=E6=A0=BC=E5=B0=BA=E5=AF=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除了定期清理本地存储相关代码 - 去除了dayjs依赖和相关时间判断 - 将表格尺寸的存储由localStorage改为sessionStorage,提高会话隔离性 --- src/components/Table/index.js | 39 ++--------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/src/components/Table/index.js b/src/components/Table/index.js index 7f6200e..00c440f 100644 --- a/src/components/Table/index.js +++ b/src/components/Table/index.js @@ -1,5 +1,4 @@ import { ProTable } from "@ant-design/pro-components"; -import dayjs from "dayjs"; import { useEffect, useMemo, useState } from "react"; import { throttle } from "throttle-debounce"; import { useAntdResizableHeader } from "use-antd-resizable-header"; @@ -7,38 +6,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 +19,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) { @@ -146,8 +113,6 @@ function Table(props) { }); } - cleanupTableLocalStorage(); - return () => { if (mutationObserver && resizeObserver && enabledResizer) { resizeObserver.unobserve(document.body);