diff --git a/src/api/mes/deviceledger/index.ts b/src/api/mes/deviceledger/index.ts index 7b59e90f..c0795e3f 100644 --- a/src/api/mes/deviceledger/index.ts +++ b/src/api/mes/deviceledger/index.ts @@ -10,6 +10,7 @@ export interface DeviceLedgerVO { deviceName: string // 设备名称 iotDeviceCode?: string // 物联设备编码 iotDeviceName?: string // 物联设备名称 + dvId?: string | number // 物联设备 ID deviceStatus: number // 设备状态 (0-正常, 1-停用, 2-维修, 3-报废) deviceBrand: string // 设备品牌 sn?: string // 序列号 @@ -60,8 +61,8 @@ export const DeviceLedgerApi = { return await request.get({ url: `/mes/device-ledger/page`, params }) }, - getDeviceLedgerList: async () => { - return await request.get({ url: `/mes/device-ledger/list` }) + getDeviceLedgerList: async (params?: any) => { + return await request.get({ url: `/mes/device-ledger/list`, params }) }, getDeviceLedgerListByNoUsed: async () => { diff --git a/src/api/mes/organization/index.ts b/src/api/mes/organization/index.ts index e61cf229..50715657 100644 --- a/src/api/mes/organization/index.ts +++ b/src/api/mes/organization/index.ts @@ -74,6 +74,6 @@ export const OrganizationApi = { }, deviceParameterAnalysis: async (params: { keyword?: string, showDevices?: number }) => { - return await request.get({ url: `/mes/organization/deviceParameterAnalysis`, params }) + return await request.get({ url: `/mes/device-line/deviceParameterAnalysis`, params }) } } diff --git a/src/views/iot/runoverview/index.vue b/src/views/iot/runoverview/index.vue index fc8935f4..3d52d20b 100644 --- a/src/views/iot/runoverview/index.vue +++ b/src/views/iot/runoverview/index.vue @@ -76,6 +76,7 @@ const fullscreenTargetRef = ref() const { isFullscreen, toggle: toggleFullscreen } = useFullscreen(fullscreenTargetRef) const deviceLedgerList = ref([]) const groupOptions = ref([]) +let deviceLedgerRequestSeq = 0 const createDateRangeByQuickKey = (key: QuickRangeKey): [string, string] => { const format = 'YYYY-MM-DD HH:mm:ss' @@ -143,7 +144,7 @@ const collectGroupIds = (groupId?: string) => { return ids } -const hasIotDeviceCode = (item: DeviceLedgerVO) => String(item.iotDeviceCode ?? '').trim() !== '' +const hasIotDeviceId = (item: DeviceLedgerVO) => String(item.dvId ?? '').trim() !== '' const getDeviceOptionLabel = (item: DeviceLedgerVO) => { const deviceName = String(item.deviceName ?? '').trim() @@ -156,11 +157,11 @@ const collectDeviceOptionsByGroup = (groupId?: string) => { const groupIds = collectGroupIds(groupId) deviceLedgerList.value.forEach((item) => { if (groupIds && !groupIds.has(String(item.deviceLine ?? ''))) return - const deviceCode = String(item.iotDeviceCode ?? '').trim() - if (!deviceCode || deviceMap.has(deviceCode)) return - deviceMap.set(deviceCode, { + const deviceId = String(item.dvId ?? '').trim() + if (!deviceId || deviceMap.has(deviceId)) return + deviceMap.set(deviceId, { label: getDeviceOptionLabel(item), - value: deviceCode + value: deviceId }) }) return Array.from(deviceMap.values()) @@ -244,14 +245,27 @@ watch(pageNo, () => { void refreshData() }) +const getDeviceLedgerOptions = async (groupId?: string) => { + const requestSeq = ++deviceLedgerRequestSeq + const ledgerList = await DeviceLedgerApi.getDeviceLedgerList({ + deviceLine: groupId || undefined + }) + if (requestSeq !== deviceLedgerRequestSeq) return + deviceLedgerList.value = Array.isArray(ledgerList) ? ledgerList.filter(hasIotDeviceId) : [] +} + const getFilterOptions = async () => { - const [deviceLineTree, ledgerList] = await Promise.all([ - DeviceLineApi.getDeviceLineTree(), - DeviceLedgerApi.getDeviceLedgerList() - ]) + const deviceLineTree = await DeviceLineApi.getDeviceLineTree() groupOptions.value = normalizeDeviceLineTree(Array.isArray(deviceLineTree) ? deviceLineTree : []) - deviceLedgerList.value = Array.isArray(ledgerList) ? ledgerList.filter(hasIotDeviceCode) : [] + await getDeviceLedgerOptions(queryParams.value.groupId) } + +watch( + () => queryParams.value.groupId, + (groupId) => { + void getDeviceLedgerOptions(groupId) + } +) watch( deviceOptions, (options) => {