设备管理 - 调整新设备的扫描时间由120秒调整为60秒,降低用户等待时长
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 <div className="flex items-center justify-center min-h-screen">加载中...</div>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user