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 '';
}
}
};