diff --git a/Server/application/superadmin/controller/devices/GetAddResultedDevicesController.php b/Server/application/superadmin/controller/devices/GetAddResultedDevicesController.php index cb266391..9232ebf5 100644 --- a/Server/application/superadmin/controller/devices/GetAddResultedDevicesController.php +++ b/Server/application/superadmin/controller/devices/GetAddResultedDevicesController.php @@ -45,12 +45,10 @@ class GetAddResultedDevicesController extends Controller protected function migrateData(int $accountId): void { $companyId = $this->getCompanyIdByAccountId($accountId); - $deviceIds = $this->getAllDevicesIdWithInCompany($companyId); + $deviceIds = $this->getAllDevicesIdWithInCompany($companyId) ?: [0]; - if ($deviceIds) { - // 从 s2_device 导入数据。 - $this->getNewDeviceFromS2_device($deviceIds, $companyId); - } + // 从 s2_device 导入数据。 + $this->getNewDeviceFromS2_device($deviceIds, $companyId); } /** @@ -93,14 +91,12 @@ class GetAddResultedDevicesController extends Controller ); $result = json_decode($result, true); - $result = $result['data']['results'][0]; + $result = $result['data']['results'][0] ?? false; - return true; - - return ( + return $result ? ( // 125是前端延迟5秒 + 轮询120次 1次/s - time() - strtotime($result['lastUpdateTime']) <= 125 - ); + time() - strtotime($result['lastUpdateTime']) <= 65 + ) : false; } /** diff --git a/SuperAdmin/app/dashboard/projects/[id]/page.tsx b/SuperAdmin/app/dashboard/projects/[id]/page.tsx index 6296f8d4..e1a5f875 100644 --- a/SuperAdmin/app/dashboard/projects/[id]/page.tsx +++ b/SuperAdmin/app/dashboard/projects/[id]/page.tsx @@ -76,6 +76,11 @@ export default function ProjectDetailPage({ params }: ProjectDetailPageProps) { const [wechatStatusFilter, setWechatStatusFilter] = useState<'all' | 'loggedIn' | 'loggedOut' | 'notLogged'>('all') const [userStatusFilter, setUserStatusFilter] = useState<'all' | 'enabled' | 'disabled'>('all') const [userTypeFilter, setUserTypeFilter] = useState<'all' | 'system' | 'operator' | 'consultant'>('all') + const [pollingCount, setPollingCount] = useState(0) + const [isPolling, setIsPolling] = useState(false) + const [qrCode, setQrCode] = useState("") + const [showQrCode, setShowQrCode] = useState(false) + const maxPollingCount = 60 // 修改为60次 const fetchProject = async () => { try { @@ -201,6 +206,36 @@ export default function ProjectDetailPage({ params }: ProjectDetailPageProps) { }) } + const startPolling = () => { + setPollingCount(0) + setIsPolling(true) + const timer = setInterval(async () => { + if (pollingCount >= maxPollingCount) { + clearInterval(timer) + setIsPolling(false) + toast.error("轮询超时,请重试") + return + } + + try { + const result = await apiRequest(`/company/device/query?accountId=${profile?.s2_accountId}`) + if (result.code === 200 && result.data) { + clearInterval(timer) + setIsPolling(false) + setShowQrCode(false) + toast.success("设备添加成功") + fetchDevices() // 刷新设备列表 + } + } catch (error) { + console.error("轮询失败:", error) + } + + setPollingCount(prev => prev + 1) + }, 1000) + + return timer + } + if (isLoading) { return
加载中...
}