FEAT => 本次更新项目为:
设备绑定指引
This commit is contained in:
30
nkebao/src/store/module/device.ts
Normal file
30
nkebao/src/store/module/device.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
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,
|
||||
}),
|
||||
);
|
||||
Reference in New Issue
Block a user