import { createPersistStore } from "@/store/createPersistStore"; export interface DeviceState { deviceCount: number; setDeviceCount: (count: number) => void; updateDeviceCount: () => Promise; resetDeviceCount: () => void; } export const useDeviceStore = createPersistStore( (set, get) => ({ deviceCount: 0, setDeviceCount: (count: number) => set({ deviceCount: count }), updateDeviceCount: async () => { try { // 这里需要导入getDashboard,但为了避免循环依赖,我们通过参数传入 // 实际使用时会在组件中调用并传入API函数 set({ deviceCount: 0 }); // 默认设置为0,实际值由调用方设置 } catch (error) { console.error("更新设备数量失败:", error); set({ deviceCount: 0 }); } }, resetDeviceCount: () => set({ deviceCount: 0 }), }), "device-store", state => ({ deviceCount: state.deviceCount, }), );