diff --git a/apps/web-antd/src/views/dataManger/deviceData/index.vue b/apps/web-antd/src/views/dataManger/deviceData/index.vue index 57db4f3..840b38e 100644 --- a/apps/web-antd/src/views/dataManger/deviceData/index.vue +++ b/apps/web-antd/src/views/dataManger/deviceData/index.vue @@ -43,6 +43,9 @@ const fetchDeviceOptions = async () => { // 根据设备ID获取设备信息对象 const getDeviceInfoById = (deviceId: string) => { + if (!deviceId || !deviceOptions.value || deviceOptions.value.length === 0) { + return null; + } return deviceOptions.value.find((device) => device.id === deviceId); }; @@ -116,7 +119,7 @@ const formOptions: VbenFormProps = { if (deviceId) { // 先尝试从 deviceOptions 中查找(备用方案) - let device = deviceOptions.value.find(d => d.id === deviceId); + let device = deviceOptions.value.length > 0 ? deviceOptions.value.find(d => d.id === deviceId) : null; // 如果没找到,尝试从 DeviceSelect 组件中获取 if (!device && gridApi?.formApi) { @@ -206,14 +209,14 @@ const gridOptions: VxeGridProps = { const ioTDataTypeValue = formValues.IoTDataType; // 处理DeviceId,当设备类型为集中器(10)时,使用focusId - let finalDeviceId = formValues.DeviceId || DeviceId; - let finalFocusAddress = formValues.FocusAddress; + let finalDeviceId = formValues.DeviceId || DeviceId || ''; + let finalFocusAddress = formValues.FocusAddress || ''; // 优先使用选中的设备信息 - const deviceInfo = selectedDeviceInfo.value || (formValues.DeviceId ? getDeviceInfoById(formValues.DeviceId) : null); + const deviceInfo = selectedDeviceInfo.value || (formValues.DeviceId && deviceOptions.value.length > 0 ? getDeviceInfoById(formValues.DeviceId) : null); if (deviceInfo) { - finalFocusAddress = deviceInfo.focusAddress; + finalFocusAddress = deviceInfo.focusAddress || ''; if (deviceTypeNumber === 10) { // 集中器类型使用focusId @@ -233,12 +236,12 @@ const gridOptions: VxeGridProps = { pageIndex: page.currentPage, pageSize: page.pageSize, // 优先使用表单中的值,如果没有则使用路由参数 - DeviceType: deviceTypeNumber, - DeviceId: finalDeviceId.toString(), - FocusAddress: finalFocusAddress || FocusAddress, + DeviceType: deviceTypeNumber || undefined, + DeviceId: finalDeviceId ? finalDeviceId.toString() : '', + FocusAddress: finalFocusAddress || FocusAddress || '', // 添加其他表单参数 - SystemName: formValues.SystemName || SystemName, - IoTDataType: ioTDataTypeValue, + SystemName: formValues.SystemName || SystemName || '', + IoTDataType: ioTDataTypeValue || undefined, }, });