31 lines
800 B
TypeScript
31 lines
800 B
TypeScript
import { getDashboard } from "@/pages/mobile/home/api";
|
|
|
|
/**
|
|
* 更新设备数量到store
|
|
* @param setDeviceCount store中的setDeviceCount函数
|
|
* @returns 更新后的设备数量
|
|
*/
|
|
export const updateDeviceCount = async (
|
|
setDeviceCount: (count: number) => void,
|
|
): Promise<number> => {
|
|
try {
|
|
const dashboardData = await getDashboard();
|
|
const deviceCount = dashboardData?.deviceNum || 0;
|
|
setDeviceCount(deviceCount);
|
|
return deviceCount;
|
|
} catch (error) {
|
|
console.error("更新设备数量失败:", error);
|
|
setDeviceCount(0);
|
|
return 0;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* 检查是否需要设备绑定
|
|
* @param deviceCount 设备数量
|
|
* @returns 是否需要设备绑定
|
|
*/
|
|
export const needsDeviceBinding = (deviceCount: number): boolean => {
|
|
return deviceCount === 0;
|
|
};
|