mirror of
https://github.com/Youzini-afk/ST-Bionic-Memory-Ecology.git
synced 2026-05-15 22:30:38 +08:00
feat: 面板尺寸localStorage持久化
This commit is contained in:
37
panel.js
37
panel.js
@@ -195,6 +195,7 @@ export async function initPanel({
|
||||
_bindTabs();
|
||||
_bindClose();
|
||||
_bindResizeHandle();
|
||||
_bindPanelResize();
|
||||
_bindGraphControls();
|
||||
_bindActions();
|
||||
_bindConfigControls();
|
||||
@@ -212,6 +213,8 @@ export function openPanel() {
|
||||
if (!overlayEl) return;
|
||||
overlayEl.classList.add("active");
|
||||
|
||||
_restorePanelSize();
|
||||
|
||||
const isMobile = _isMobile();
|
||||
const settings = _getSettings?.() || {};
|
||||
const themeName = settings.panelTheme || "crimson";
|
||||
@@ -679,6 +682,40 @@ function _bindResizeHandle() {
|
||||
});
|
||||
}
|
||||
|
||||
const PANEL_SIZE_KEY = "st-bme-panel-size";
|
||||
let _panelResizeTimer = null;
|
||||
|
||||
function _bindPanelResize() {
|
||||
if (!panelEl || typeof ResizeObserver === "undefined") return;
|
||||
const observer = new ResizeObserver(() => {
|
||||
clearTimeout(_panelResizeTimer);
|
||||
_panelResizeTimer = setTimeout(() => {
|
||||
if (!overlayEl?.classList.contains("active")) return;
|
||||
const w = panelEl.offsetWidth;
|
||||
const h = panelEl.offsetHeight;
|
||||
if (w > 0 && h > 0) {
|
||||
try {
|
||||
localStorage.setItem(PANEL_SIZE_KEY, JSON.stringify({ w, h }));
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
}, 300);
|
||||
});
|
||||
observer.observe(panelEl);
|
||||
}
|
||||
|
||||
function _restorePanelSize() {
|
||||
if (!panelEl) return;
|
||||
try {
|
||||
const raw = localStorage.getItem(PANEL_SIZE_KEY);
|
||||
if (!raw) return;
|
||||
const { w, h } = JSON.parse(raw);
|
||||
if (Number.isFinite(w) && Number.isFinite(h) && w > 200 && h > 200) {
|
||||
panelEl.style.width = w + "px";
|
||||
panelEl.style.height = h + "px";
|
||||
}
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
|
||||
// ==================== 操作绑定 ====================
|
||||
|
||||
function _bindActions() {
|
||||
|
||||
Reference in New Issue
Block a user