From bd4f9185bd2760d659a316ea01ae774f3fb8d32e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Tue, 29 Apr 2025 16:48:37 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86=20-=20?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=96=B0=E8=AE=BE=E5=A4=87=E7=9A=84=E6=89=AB?= =?UTF-8?q?=E6=8F=8F=E6=97=B6=E9=97=B4=E7=94=B1120=E7=A7=92=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E4=B8=BA60=E7=A7=92=EF=BC=8C=E9=99=8D=E4=BD=8E?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=AD=89=E5=BE=85=E6=97=B6=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GetAddResultedDevicesController.php | 18 ++++------ .../app/dashboard/projects/[id]/page.tsx | 35 +++++++++++++++++++ 2 files changed, 42 insertions(+), 11 deletions(-) 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
加载中...
}