style:物联设备-统计卡片添加接口

main
黄伟杰 2 days ago
parent 869347ed46
commit 5ace5f5a99

@ -39,6 +39,14 @@ export interface DeviceConnectParams {
isConnect: string | number
}
export interface DeviceStatusStatisticsRespVO {
totalCount: number
runningCount: number
standbyCount: number
alarmCount: number
offlineCount: number
}
export interface LineDeviceVO {
id?: string | number
lineNode?: string
@ -115,6 +123,11 @@ export interface ProductionDailyReportFileVO {
// 物联设备 API
export const DeviceApi = {
// 查询物联设备状态统计
getDeviceStatusStatistics: async (): Promise<DeviceStatusStatisticsRespVO> => {
return await request.get({ url: `/iot/device/status-statistics` })
},
// 查询物联设备分页
getDevicePage: async (params: any) => {
return await request.get({ url: `/iot/device/page`, params })

@ -965,12 +965,11 @@ const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) //
type DeviceOperatingStatusKey = 'running' | 'standby' | 'fault' | 'alarm' | 'offline'
type DeviceStatisticKey = 'total' | DeviceOperatingStatusKey
type DeviceStatisticKey = 'total' | 'running' | 'standby' | 'alarm' | 'offline'
const deviceStatistics = reactive<Record<DeviceStatisticKey, number>>({
total: 0,
running: 0,
standby: 0,
fault: 0,
alarm: 0,
offline: 0
})
@ -978,8 +977,7 @@ const deviceStatisticsItems = computed(() => [
{ key: 'total', label: '总数', value: deviceStatistics.total },
{ key: 'running', label: '运行数', value: deviceStatistics.running },
{ key: 'standby', label: '待机数', value: deviceStatistics.standby },
{ key: 'fault', label: '报警数', value: deviceStatistics.fault },
/*{ key: 'alarm', label: '报警数', value: deviceStatistics.alarm },*/
{ key: 'alarm', label: '报警数', value: deviceStatistics.alarm },
{ key: 'offline', label: '离线数', value: deviceStatistics.offline }
])
@ -1008,35 +1006,24 @@ const operatingStatusTypeMap: Record<DeviceOperatingStatusKey, 'success' | 'info
offline: 'info'
}
const setDeviceStatistics = (rows: DeviceVO[] = []) => {
const nextStats: Record<DeviceStatisticKey, number> = {
total: rows.length,
running: 0,
standby: 0,
fault: 0,
alarm: 0,
offline: 0
}
rows.forEach((row) => {
const key = normalizeDeviceOperatingStatus(row.operatingStatus)
nextStats[key] += 1
})
Object.assign(deviceStatistics, nextStats)
}
const getDeviceStatistics = async (totalCount = total.value) => {
const { pageNo, pageSize, ...params } = queryParams
const statisticsPageSize = Math.max(Number(totalCount) || 0, Number(pageSize) || 10, 1)
const getDeviceStatistics = async () => {
try {
const data = await DeviceApi.getDevicePage({
...params,
pageNo: 1,
pageSize: statisticsPageSize
const data = await DeviceApi.getDeviceStatusStatistics()
Object.assign(deviceStatistics, {
total: Number(data?.totalCount ?? 0),
running: Number(data?.runningCount ?? 0),
standby: Number(data?.standbyCount ?? 0),
alarm: Number(data?.alarmCount ?? 0),
offline: Number(data?.offlineCount ?? 0)
})
const rows = Array.isArray(data) ? data : Array.isArray((data as any)?.list) ? (data as any).list : []
setDeviceStatistics(rows)
} catch {
setDeviceStatistics(list.value)
Object.assign(deviceStatistics, {
total: 0,
running: 0,
standby: 0,
alarm: 0,
offline: 0
})
}
}
@ -1096,7 +1083,7 @@ const getList = async (showLoading = true) => {
const data = await DeviceApi.getDevicePage(queryParams)
list.value = data.list
total.value = data.total
await getDeviceStatistics(data.total)
await getDeviceStatistics()
} finally {
if (showLoading) {
loading.value = false
@ -1114,7 +1101,7 @@ const getListOne = async (showLoading = true) => {
const data = await DeviceApi.getDevicePage(queryParams)
list.value = data.list
total.value = data.total
await getDeviceStatistics(data.total)
await getDeviceStatistics()
} finally {
if (showLoading) {
loading.value = false

Loading…
Cancel
Save