diff --git a/nkebao/src/pages/guide/index.tsx b/nkebao/src/pages/guide/index.tsx index ce817144..da42ed05 100644 --- a/nkebao/src/pages/guide/index.tsx +++ b/nkebao/src/pages/guide/index.tsx @@ -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 = () => {
{qrCode && (