feat(frontend): 添加捕获存储钩子
- 新增 useCapture 使用 Zustand 库创建状态管理
This commit is contained in:
@@ -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(
|
||||||
|
|||||||
@@ -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>()(
|
||||||
|
persist(
|
||||||
|
(set) => ({
|
||||||
parsedData: null,
|
parsedData: null,
|
||||||
setParsedData: (data) => set({ parsedData: data }),
|
setParsedData: (data) => set({ parsedData: data }),
|
||||||
}));
|
}),
|
||||||
|
{
|
||||||
|
name: 'capture-store', // localStorage key
|
||||||
|
partialize: (state) => ({ parsedData: state.parsedData }) }
|
||||||
|
)
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user