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 (_) { /* 隐私模式下忽略 */ } };