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

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

@ -3,11 +3,14 @@ import qs from 'qs'
// 物联设备 VO
export interface DeviceVO {
id: number // ID
id: string | number // ID
deviceCode: string // 设备编号
deviceName: string // 设备名称
boundLedgerName?: string // 已绑定的设备台账名称
deviceType: string // 设备类型
ledgerBound?: boolean
selectable?: boolean
boundLedgerId?: string | number | null
status: string // 状态
isConnect?: string | number
operatingStatus?: string | number
@ -91,7 +94,7 @@ export const DeviceApi = {
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 })
},
getDeviceListByNoUsed: async () => {

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

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

Loading…
Cancel
Save