Files
cunkebao_v3/nkebao/src/store/module/device.ts
超级老白兔 f78af9e77c FEAT => 本次更新项目为:
设备绑定指引
2025-07-30 12:52:58 +08:00

31 lines
974 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { createPersistStore } from "@/store/createPersistStore";
export interface DeviceState {
deviceCount: number;
setDeviceCount: (count: number) => void;
updateDeviceCount: () => Promise<void>;
resetDeviceCount: () => void;
}
export const useDeviceStore = createPersistStore<DeviceState>(
(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,
}),
);