优化列配置组件,添加点击外部关闭功能;改进数据转换逻辑,支持防抖处理以提升性能

This commit is contained in:
lirui
2026-02-09 20:23:24 +08:00
parent c7f97f77c7
commit 16164f3e5c
2 changed files with 39 additions and 2 deletions

View File

@@ -16,7 +16,24 @@
// Derived
const hasData = $derived(headers.length > 0 && rows.length > 0);
const convertedJson = $derived(hasData ? convertData(rows, mappings) : []);
// Debounced conversion to avoid lag while editing mappings
let convertedJson = $state<Record<string, unknown>[]>([]);
let debounceTimer: ReturnType<typeof setTimeout>;
$effect(() => {
// $state.snapshot forces deep read of all nested properties,
// so changes to e.g. mappings[i].target will trigger this effect
const snapshotMappings = $state.snapshot(mappings);
const currentRows = rows;
const dataReady = hasData;
clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => {
convertedJson = dataReady ? convertData(currentRows, snapshotMappings) : [];
}, 150);
});
const jsonString = $derived(JSON.stringify(convertedJson, null, 2));
// File handling