feat(frontend): 添加捕获存储钩子

- 新增 useCapture 使用 Zustand 库创建状态管理
This commit is contained in:
hu xiaotong
2025-07-02 17:21:59 +08:00
parent 44ee8da1ed
commit 92807c8554
2 changed files with 14 additions and 6 deletions

View File

@@ -79,7 +79,7 @@ function CapturePage() {
const fetchInterfaces = async () => { const fetchInterfaces = async () => {
setIsCapturing(false); setIsCapturing(false);
setCapturedData([]); setCapturedData([]);
setParsedData(null); // setParsedData(null);
setLoading(false); setLoading(false);
setInterfaceLoading(true); setInterfaceLoading(true);
try { try {
@@ -145,7 +145,7 @@ function CapturePage() {
setLoading(false); setLoading(false);
setIsCapturing(false); setIsCapturing(false);
setCapturedData([]); setCapturedData([]);
setParsedData(null); // setParsedData(null);
try { try {
setLoading(true); setLoading(true);
await safeApiCall( await safeApiCall(

View File

@@ -1,4 +1,5 @@
import {create} from 'zustand'; import {create} from 'zustand';
import {persist} from 'zustand/middleware';
export interface Equipment { export interface Equipment {
id: string; id: string;
@@ -24,7 +25,14 @@ interface CaptureStoreState {
setParsedData: (data: CaptureResult | null) => void; setParsedData: (data: CaptureResult | null) => void;
} }
export const useCaptureStore = create<CaptureStoreState>((set) => ({ export const useCaptureStore = create<CaptureStoreState>()(
parsedData: null, persist(
setParsedData: (data) => set({ parsedData: data }), (set) => ({
})); parsedData: null,
setParsedData: (data) => set({ parsedData: data }),
}),
{
name: 'capture-store', // localStorage key
partialize: (state) => ({ parsedData: state.parsedData }) }
)
);