From a8a0c6d4c94f770a243925ed9b400372f767647f Mon Sep 17 00:00:00 2001 From: renshen <1005457301@qq.com> Date: Tue, 13 Oct 2026 15:24:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=B2=E6=89=93=E5=BC=80=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=A0=8F=E6=94=B9=E4=B8=BA=E6=8C=89=E6=B5=8F?= =?UTF-8?q?=E8=A7=88=E5=99=A8=E4=BC=9A=E8=AF=9D=E4=BF=9D=E7=95=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前存在 localStorage:跨浏览器重启也不会清,前几天点过的标签刷新后又出现 (用户反馈"没点过/刷新后其他标签又弹出来")。改成 sessionStorage:同一次浏览器 会话内刷新、来回切换都保留,关掉浏览器或另开窗口重新进来就是干净的;同时清掉 旧版本写在 localStorage 里的记录。 --- .../pages/partials/open-page-tabs.blade.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/resources/views/business/pages/partials/open-page-tabs.blade.php b/resources/views/business/pages/partials/open-page-tabs.blade.php index 7c43a7fc..f4946521 100644 --- a/resources/views/business/pages/partials/open-page-tabs.blade.php +++ b/resources/views/business/pages/partials/open-page-tabs.blade.php @@ -80,12 +80,21 @@ return; } const list = root.querySelector('[data-open-tabs-list]'); - const storageKey = 'caiwu.open-pages.v1.' + (root.dataset.userId || 'anon'); + const userId = root.dataset.userId || 'anon'; + const storageKey = 'caiwu.open-pages.v1.' + userId; + // 只在"本次浏览器会话"里保留:同一个浏览器窗口内刷新/来回切换都在, + // 关掉浏览器或换一个窗口重新进来就是干净的,不会再把前几天的旧标签带出来。 + const storage = window.sessionStorage; const maxTabs = 15; + // 清理早期版本写在 localStorage 里的记录(那份会跨浏览器一直保留)。 + try { + window.localStorage.removeItem(storageKey); + } catch (_) { /* 隐私模式下忽略 */ } + const read = () => { try { - const parsed = JSON.parse(window.localStorage.getItem(storageKey) || '[]'); + const parsed = JSON.parse(storage.getItem(storageKey) || '[]'); return Array.isArray(parsed) ? parsed.filter((item) => item && typeof item.url === 'string' && typeof item.path === 'string') : []; } catch (_) { return []; @@ -93,7 +102,7 @@ }; const save = (items) => { try { - window.localStorage.setItem(storageKey, JSON.stringify(items)); + storage.setItem(storageKey, JSON.stringify(items)); } catch (_) { /* 隐私模式下忽略 */ } };