From ba7ebdb348541ad79500a827b8284663c1be6698 Mon Sep 17 00:00:00 2001 From: ChenYi <296215406@outlook.com> Date: Wed, 16 Jul 2025 16:48:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/dataManger/deviceData/index.vue | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) 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, }, });