diff --git a/src/components/ScanBox/index.vue b/src/components/ScanBox/index.vue index a591adc0..8662cb52 100644 --- a/src/components/ScanBox/index.vue +++ b/src/components/ScanBox/index.vue @@ -546,10 +546,22 @@ function saveSnapshot() { }, getScopedCacheKey()) } +/** 仅保存 UI 草稿(表单值),不覆盖上次查询的 activeCondition */ +function saveDraftSnapshot() { + const routePath = getRouteCacheKey() + if (!routePath) return + const existing = scanBoxCacheStore.getSnapshot(routePath, getScopedCacheKey()) + scanBoxCacheStore.setSnapshot(routePath, { + activeTab: activeTab.value, + activeCondition: existing?.activeCondition ?? null, + customConditions: cloneSnapshotValue(customConditions) + }, getScopedCacheKey()) +} + function scheduleSaveSnapshot() { clearTimeout(cacheTimer) cacheTimer = setTimeout(() => { - saveSnapshot() + saveDraftSnapshot() }, 120) } @@ -995,6 +1007,7 @@ function buildAndEmitCustomCondition() { if (hasCondition) { activeCondition.value = conditions + saveSnapshot() emit('condition-change', activeCondition.value) } else if (activeCondition.value && activeCondition.value.type === 'custom') { clearActiveCondition() @@ -1029,6 +1042,9 @@ function handleReset() { function handleSubmit() { submitting.value = true + // 查询前立即持久化当前条件,供刷新恢复和导出使用 + saveSnapshot() + // 对于自定义筛选,先构建当前条件但不依赖 buildAndEmitCustomCondition 的内部 emit if (activeTab.value === 'custom') { const currentConditions = buildConditionsObject() @@ -1215,7 +1231,14 @@ function setFieldCondition( } } -defineExpose({ getConditions, reset, clear, getFieldDraft, setFieldCondition, submit: handleSubmit }) +/** 获取上次查询时存储的条件,供导出等场景复用 */ +function getStoredConditions() { + const routePath = getRouteCacheKey() + if (!routePath) return null + return scanBoxCacheStore.getSnapshot(routePath, getScopedCacheKey()) +} + +defineExpose({ getConditions, reset, clear, getFieldDraft, setFieldCondition, submit: handleSubmit, getStoredConditions })