FEAT => 更新设备绑定引导页逻辑,新增设备列表接口调用以优化设备数量获取,提升用户体验。
This commit is contained in:
@@ -8,10 +8,9 @@ import {
|
||||
QrcodeOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import Layout from "@/components/Layout/Layout";
|
||||
import { fetchDeviceQRCode, addDeviceByImei } from "./api";
|
||||
import { fetchDeviceQRCode, addDeviceByImei, fetchDeviceList } from "./api";
|
||||
import { useUserStore } from "@/store/module/user";
|
||||
import styles from "./index.module.scss";
|
||||
|
||||
const Guide: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
const { user } = useUserStore();
|
||||
@@ -72,10 +71,10 @@ const Guide: React.FC = () => {
|
||||
// 这里可以调用一个简单的设备数量接口来检查是否有新设备
|
||||
// 或者使用其他方式检测设备状态变化
|
||||
// 暂时使用store中的数量,实际项目中可能需要调用专门的接口
|
||||
const currentDeviceCount = user?.deviceTotal || 0;
|
||||
|
||||
// 如果设备数量增加了,说明有新设备添加成功
|
||||
if (currentDeviceCount > initialDeviceCountRef.current) {
|
||||
let currentDeviceCount = user?.deviceTotal || 0;
|
||||
const res = await fetchDeviceList({ accountId: user?.s2_accountId });
|
||||
if (res.added) {
|
||||
currentDeviceCount = 1;
|
||||
Toast.show({ content: "设备添加成功!", position: "top" });
|
||||
setAddVisible(false);
|
||||
setDeviceCount(currentDeviceCount);
|
||||
@@ -85,7 +84,7 @@ const Guide: React.FC = () => {
|
||||
pollingRef.current = null;
|
||||
}
|
||||
// 可以选择跳转到首页或继续留在当前页面
|
||||
// navigate("/");
|
||||
navigate("/");
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -95,7 +94,7 @@ const Guide: React.FC = () => {
|
||||
|
||||
// 每3秒检查一次设备状态
|
||||
pollingRef.current = setInterval(pollDeviceStatus, 3000);
|
||||
}, [isPolling, deviceCount, user?.deviceTotal]);
|
||||
}, [isPolling, user?.s2_accountId]);
|
||||
|
||||
// 停止轮询
|
||||
const stopPolling = useCallback(() => {
|
||||
@@ -289,7 +288,7 @@ const Guide: React.FC = () => {
|
||||
<div style={{ textAlign: "center", minHeight: 200 }}>
|
||||
<Button color="primary" onClick={handleGetQr} loading={qrLoading}>
|
||||
<QrcodeOutlined />
|
||||
获取二维码
|
||||
获取二维码
|
||||
</Button>
|
||||
{qrCode && (
|
||||
<div style={{ marginTop: 16 }}>
|
||||
|
||||
Reference in New Issue
Block a user