style:设备台账-关联物联设备单选框修复

main
黄伟杰 20 hours ago
parent 5a84773a2d
commit 80fc2bad24

@ -3,11 +3,14 @@ import qs from 'qs'
// 物联设备 VO // 物联设备 VO
export interface DeviceVO { export interface DeviceVO {
id: number // ID id: string | number // ID
deviceCode: string // 设备编号 deviceCode: string // 设备编号
deviceName: string // 设备名称 deviceName: string // 设备名称
boundLedgerName?: string // 已绑定的设备台账名称 boundLedgerName?: string // 已绑定的设备台账名称
deviceType: string // 设备类型 deviceType: string // 设备类型
ledgerBound?: boolean
selectable?: boolean
boundLedgerId?: string | number | null
status: string // 状态 status: string // 状态
isConnect?: string | number isConnect?: string | number
operatingStatus?: string | number operatingStatus?: string | number
@ -91,7 +94,7 @@ export const DeviceApi = {
return await request.get({ url: `/iot/device/deviceList`, params }) return await request.get({ url: `/iot/device/deviceList`, params })
}, },
// 查询物联设备详情 // 查询物联设备详情
getDevice: async (id: number) => { getDevice: async (id: string | number) => {
return await request.get({ url: `/iot/device/get?id=` + id }) return await request.get({ url: `/iot/device/get?id=` + id })
}, },
getDeviceListByNoUsed: async () => { getDeviceListByNoUsed: async () => {

@ -425,8 +425,8 @@
<el-table-column width="56" align="center"> <el-table-column width="56" align="center">
<template #default="scope"> <template #default="scope">
<el-radio <el-radio
:model-value="iotDeviceDraftId" v-model="iotDeviceDraftId"
:label="scope.row.id" :value="String(scope.row.id)"
:disabled="!isIotDeviceSelectable(scope.row)" :disabled="!isIotDeviceSelectable(scope.row)"
@change="selectIotDevice(scope.row)" @change="selectIotDevice(scope.row)"
@click.stop @click.stop
@ -796,7 +796,7 @@ const iotDeviceDialogVisible = ref(false)
const iotDeviceList = ref<DeviceVO[]>([]) const iotDeviceList = ref<DeviceVO[]>([])
const iotDeviceTotal = ref(0) const iotDeviceTotal = ref(0)
const iotDeviceSelectedLabel = ref('') const iotDeviceSelectedLabel = ref('')
const iotDeviceDraftId = ref<number | undefined>() const iotDeviceDraftId = ref<string | undefined>()
const iotDeviceDraftRow = ref<DeviceVO | undefined>() const iotDeviceDraftRow = ref<DeviceVO | undefined>()
const list = ref<CriticalComponentVO[]>([]) const list = ref<CriticalComponentVO[]>([])
const bjList = ref<ProductVO[]>([]) const bjList = ref<ProductVO[]>([])
@ -825,6 +825,12 @@ const normalizeNumberish = (value: any): number | undefined => {
} }
return undefined return undefined
} }
const normalizeId = (value: unknown): string | undefined => {
if (value === null || value === undefined) return undefined
const id = String(value).trim()
return id || undefined
}
const normalizeYmd = (value: any): string | undefined => { const normalizeYmd = (value: any): string | undefined => {
if (value === null || value === undefined || value === '') return undefined if (value === null || value === undefined || value === '') return undefined
@ -1094,7 +1100,7 @@ const buildIotDeviceLabel = (item: any) => {
} }
const getIotDeviceIdFromDetail = (detail: any) => const getIotDeviceIdFromDetail = (detail: any) =>
normalizeNumberish( normalizeId(
detail?.dvId ?? detail?.iotDeviceId ?? detail?.iotDevice?.id ?? detail?.device?.id detail?.dvId ?? detail?.iotDeviceId ?? detail?.iotDevice?.id ?? detail?.device?.id
) )
@ -1118,8 +1124,19 @@ const getIotDeviceLabelFromDetail = (detail: any) => {
const iotDeviceDisplay = computed(() => iotDeviceSelectedLabel.value) const iotDeviceDisplay = computed(() => iotDeviceSelectedLabel.value)
const isCurrentIotDevice = (row: any) => {
const rowId = normalizeId(row?.id)
const selectedId = normalizeId(formData.value.dvId)
if (rowId !== undefined && rowId === selectedId) return true
const boundLedgerId = normalizeId(row?.boundLedgerId)
const currentLedgerId = normalizeId(formData.value.id)
return boundLedgerId !== undefined && boundLedgerId === currentLedgerId
}
const isIotDeviceSelectable = (row: any) => { const isIotDeviceSelectable = (row: any) => {
const value = row?.selectable const value = row?.selectable
if (isCurrentIotDevice(row)) return true
return value !== false && String(value ?? 'true').toLowerCase() !== 'false' return value !== false && String(value ?? 'true').toLowerCase() !== 'false'
} }
@ -1134,7 +1151,7 @@ const isIotDeviceEnabled = (row: any) => {
const selectIotDevice = (row: DeviceVO) => { const selectIotDevice = (row: DeviceVO) => {
if (!isIotDeviceSelectable(row)) return if (!isIotDeviceSelectable(row)) return
const id = normalizeNumberish(row?.id) const id = normalizeId(row?.id)
if (id === undefined) return if (id === undefined) return
iotDeviceDraftId.value = id iotDeviceDraftId.value = id
iotDeviceDraftRow.value = row iotDeviceDraftRow.value = row
@ -1149,7 +1166,7 @@ const getIotDeviceRowClassName = ({ row }: { row: DeviceVO }) => {
} }
const openIotDeviceDialog = async () => { const openIotDeviceDialog = async () => {
const id = normalizeNumberish(formData.value.dvId) const id = normalizeId(formData.value.dvId)
iotDeviceDraftId.value = id iotDeviceDraftId.value = id
iotDeviceDraftRow.value = iotDeviceDraftRow.value =
id === undefined ? undefined : ({ id, deviceName: iotDeviceSelectedLabel.value } as DeviceVO) id === undefined ? undefined : ({ id, deviceName: iotDeviceSelectedLabel.value } as DeviceVO)

@ -730,8 +730,8 @@
<el-table-column width="56" align="center"> <el-table-column width="56" align="center">
<template #default="scope"> <template #default="scope">
<el-radio <el-radio
:model-value="iotDeviceDraftId" v-model="iotDeviceDraftId"
:label="scope.row.id" :value="String(scope.row.id)"
:disabled="!isIotDeviceSelectable(scope.row)" :disabled="!isIotDeviceSelectable(scope.row)"
@change="selectIotDevice(scope.row)" @change="selectIotDevice(scope.row)"
@click.stop @click.stop
@ -894,7 +894,7 @@ const iotDeviceDialogVisible = ref(false)
const iotDeviceList = ref<DeviceVO[]>([]) const iotDeviceList = ref<DeviceVO[]>([])
const iotDeviceTotal = ref(0) const iotDeviceTotal = ref(0)
const iotDeviceSelectedLabel = ref('') const iotDeviceSelectedLabel = ref('')
const iotDeviceDraftId = ref<number | undefined>() const iotDeviceDraftId = ref<string | undefined>()
const iotDeviceDraftRow = ref<DeviceVO | undefined>() const iotDeviceDraftRow = ref<DeviceVO | undefined>()
const parseIdsValue = (value: any): number[] => { const parseIdsValue = (value: any): number[] => {
if (!value) return [] if (!value) return []
@ -1158,6 +1158,12 @@ const normalizeNumberish = (value: any): number | undefined => {
} }
return undefined return undefined
} }
const normalizeId = (value: unknown): string | undefined => {
if (value === null || value === undefined) return undefined
const id = String(value).trim()
return id || undefined
}
const normalizeYmd = (value: any): string | undefined => { const normalizeYmd = (value: any): string | undefined => {
if (value === null || value === undefined || value === '') return undefined if (value === null || value === undefined || value === '') return undefined
@ -1428,7 +1434,7 @@ const buildIotDeviceLabel = (item: any) => {
} }
const getIotDeviceIdFromDetail = (detail: any) => const getIotDeviceIdFromDetail = (detail: any) =>
normalizeNumberish( normalizeId(
detail?.dvId ?? detail?.iotDeviceId ?? detail?.iotDevice?.id ?? detail?.device?.id detail?.dvId ?? detail?.iotDeviceId ?? detail?.iotDevice?.id ?? detail?.device?.id
) )
@ -1452,8 +1458,19 @@ const getIotDeviceLabelFromDetail = (detail: any) => {
const iotDeviceDisplay = computed(() => iotDeviceSelectedLabel.value) const iotDeviceDisplay = computed(() => iotDeviceSelectedLabel.value)
const isCurrentIotDevice = (row: any) => {
const rowId = normalizeId(row?.id)
const selectedId = normalizeId(formData.value.dvId)
if (rowId !== undefined && rowId === selectedId) return true
const boundLedgerId = normalizeId(row?.boundLedgerId)
const currentLedgerId = normalizeId(formData.value.id)
return boundLedgerId !== undefined && boundLedgerId === currentLedgerId
}
const isIotDeviceSelectable = (row: any) => { const isIotDeviceSelectable = (row: any) => {
const value = row?.selectable const value = row?.selectable
if (isCurrentIotDevice(row)) return true
return value !== false && String(value ?? 'true').toLowerCase() !== 'false' return value !== false && String(value ?? 'true').toLowerCase() !== 'false'
} }
@ -1468,7 +1485,7 @@ const isIotDeviceEnabled = (row: any) => {
const selectIotDevice = (row: DeviceVO) => { const selectIotDevice = (row: DeviceVO) => {
if (!isIotDeviceSelectable(row)) return if (!isIotDeviceSelectable(row)) return
const id = normalizeNumberish(row?.id) const id = normalizeId(row?.id)
if (id === undefined) return if (id === undefined) return
iotDeviceDraftId.value = id iotDeviceDraftId.value = id
iotDeviceDraftRow.value = row iotDeviceDraftRow.value = row
@ -1483,7 +1500,7 @@ const getIotDeviceRowClassName = ({ row }: { row: DeviceVO }) => {
} }
const openIotDeviceDialog = async () => { const openIotDeviceDialog = async () => {
const id = normalizeNumberish(formData.value.dvId) const id = normalizeId(formData.value.dvId)
iotDeviceDraftId.value = id iotDeviceDraftId.value = id
iotDeviceDraftRow.value = iotDeviceDraftRow.value =
id === undefined ? undefined : ({ id, deviceName: iotDeviceSelectedLabel.value } as DeviceVO) id === undefined ? undefined : ({ id, deviceName: iotDeviceSelectedLabel.value } as DeviceVO)

Loading…
Cancel
Save