Files
xk-admin/apps/web-antd/src/components/canvas-spreadsheet/history/layoutLocalStore.ts
李琦 69862cd982
Some checks failed
CI / Test (ubuntu-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Lint (ubuntu-latest) (push) Has been cancelled
CI / Lint (windows-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / CI OK (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Website on push / Deploy Push Playground Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Docs Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Antd Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Element Ftp (push) Has been cancelled
Deploy Website on push / Deploy Push Naive Ftp (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Issue Close Require / close-issues (push) Has been cancelled
Close stale issues / stale (push) Has been cancelled
1. Excel交互组件封装
2026-06-25 16:09:07 +08:00

42 lines
1.1 KiB
TypeScript

import type { SpreadsheetLayoutState } from '../types';
function storageKey(tableName: string, sheetKey?: string) {
return `xk_spreadsheet_layout_${tableName}_${sheetKey ?? 'default'}`;
}
export function readSpreadsheetLayout(
tableName: string,
sheetKey?: string,
): SpreadsheetLayoutState | null {
try {
const raw = localStorage.getItem(storageKey(tableName, sheetKey));
if (!raw) return null;
return JSON.parse(raw) as SpreadsheetLayoutState;
} catch {
return null;
}
}
export function writeSpreadsheetLayout(
tableName: string,
sheetKey: string | undefined,
state: SpreadsheetLayoutState,
) {
localStorage.setItem(storageKey(tableName, sheetKey), JSON.stringify(state));
}
let saveTimer: ReturnType<typeof setTimeout> | null = null;
export function debouncedWriteSpreadsheetLayout(
tableName: string,
sheetKey: string | undefined,
state: SpreadsheetLayoutState,
delayMs = 400,
) {
if (saveTimer) clearTimeout(saveTimer);
saveTimer = setTimeout(() => {
writeSpreadsheetLayout(tableName, sheetKey, state);
saveTimer = null;
}, delayMs);
}