From 983b929d9021542bd1ebfc9b4c9edf1dbd58c391 Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Sat, 20 Sep 2025 17:30:45 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BA=E5=9F=9F=E4=B8=BB=E6=8E=A7=E9=AB=98?= =?UTF-8?q?=E4=BA=AE=20=E7=BC=96=E8=BE=91=E6=97=B6=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E5=8E=9F=E6=9C=89=E5=B1=9E=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/DeviceForm.vue | 20 ++++++++++++++++++-- src/components/DeviceList.vue | 27 +++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/components/DeviceForm.vue b/src/components/DeviceForm.vue index 66b75be0..4554f3ef 100644 --- a/src/components/DeviceForm.vue +++ b/src/components/DeviceForm.vue @@ -275,8 +275,16 @@ export default { if (newVal && Object.keys(newVal).length > 0) { // 填充表单数据 Object.keys(formData).forEach(key => { - if (newVal[key] !== undefined) { - formData[key] = newVal[key]; + // 处理字段名映射 + let dataKey = key; + if (key === 'parentControllerId') { + dataKey = 'parent_id'; + } else if (key === 'subType') { + dataKey = 'sub_type'; + } + + if (newVal[dataKey] !== undefined) { + formData[key] = newVal[dataKey]; } }); @@ -303,6 +311,14 @@ export default { } }, { immediate: true }); + // 监听visible属性变化,当对话框打开时重新加载区域主控列表 + watch(() => props.visible, (newVal) => { + if (newVal) { + // 对话框打开时重新加载区域主控列表 + loadAreaControllers(); + } + }, { immediate: true }); + // 组件挂载时加载区域主控列表 onMounted(() => { loadAreaControllers(); diff --git a/src/components/DeviceList.vue b/src/components/DeviceList.vue index 6a97d154..a4fb5f9e 100644 --- a/src/components/DeviceList.vue +++ b/src/components/DeviceList.vue @@ -35,7 +35,9 @@ table-layout="auto" row-key="id" default-expand-all - :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"> + :tree-props="{ children: 'children', hasChildren: 'hasChildren' }" + :row-class-name="tableRowClassName" + highlight-current-row> @@ -163,7 +165,20 @@ export default { }, editDevice(device) { - this.currentDevice = { ...device }; + // 处理设备数据,确保正确传递给表单 + const processedDevice = { ...device }; + + // 如果properties是字符串,则解析为对象 + if (processedDevice.properties && typeof processedDevice.properties === 'string') { + try { + processedDevice.properties = JSON.parse(processedDevice.properties); + } catch (e) { + console.error('解析properties失败:', e); + processedDevice.properties = {}; + } + } + + this.currentDevice = processedDevice; this.isEdit = true; this.dialogVisible = true; }, @@ -193,6 +208,14 @@ export default { this.dialogVisible = false; // 重新加载设备列表 await this.loadDevices(); + }, + + // 为区域主控设备添加高亮 + tableRowClassName({ row, rowIndex }) { + if (row.type === 'area_controller') { + return 'current-row'; + } + return ''; } } };