From 92807c855455e0dec47d598ae0157bbc05f7b137 Mon Sep 17 00:00:00 2001 From: hu xiaotong <416314413@163.com> Date: Wed, 2 Jul 2025 17:21:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(frontend):=20=E6=B7=BB=E5=8A=A0=E6=8D=95?= =?UTF-8?q?=E8=8E=B7=E5=AD=98=E5=82=A8=E9=92=A9=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 useCapture 使用 Zustand 库创建状态管理 --- frontend/src/pages/CapturePage.tsx | 4 ++-- frontend/src/store/useCaptureStore.ts | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/frontend/src/pages/CapturePage.tsx b/frontend/src/pages/CapturePage.tsx index fffb493..67197bf 100644 --- a/frontend/src/pages/CapturePage.tsx +++ b/frontend/src/pages/CapturePage.tsx @@ -79,7 +79,7 @@ function CapturePage() { const fetchInterfaces = async () => { setIsCapturing(false); setCapturedData([]); - setParsedData(null); + // setParsedData(null); setLoading(false); setInterfaceLoading(true); try { @@ -145,7 +145,7 @@ function CapturePage() { setLoading(false); setIsCapturing(false); setCapturedData([]); - setParsedData(null); + // setParsedData(null); try { setLoading(true); await safeApiCall( diff --git a/frontend/src/store/useCaptureStore.ts b/frontend/src/store/useCaptureStore.ts index ff1356b..2311478 100644 --- a/frontend/src/store/useCaptureStore.ts +++ b/frontend/src/store/useCaptureStore.ts @@ -1,4 +1,5 @@ import {create} from 'zustand'; +import {persist} from 'zustand/middleware'; export interface Equipment { id: string; @@ -24,7 +25,14 @@ interface CaptureStoreState { setParsedData: (data: CaptureResult | null) => void; } -export const useCaptureStore = create((set) => ({ - parsedData: null, - setParsedData: (data) => set({ parsedData: data }), -})); \ No newline at end of file +export const useCaptureStore = create()( + persist( + (set) => ({ + parsedData: null, + setParsedData: (data) => set({ parsedData: data }), + }), + { + name: 'capture-store', // localStorage key + partialize: (state) => ({ parsedData: state.parsedData }) } + ) +); \ No newline at end of file