diff --git a/src/views/ems/record/recordIOTInstant/index.vue b/src/views/ems/record/recordIOTInstant/index.vue index c8bb0dc..1401017 100644 --- a/src/views/ems/record/recordIOTInstant/index.vue +++ b/src/views/ems/record/recordIOTInstant/index.vue @@ -337,6 +337,9 @@ export default { children: 'children', label: 'label' }, + + // 选中节点的类型,用于控制显示字段 + selectedNodeType: null, // 记录时间时间范围 daterangeRecordTime: [], @@ -411,6 +414,8 @@ export default { this.daterangeRecordTime[0] = yesterday+ ' 08:00:00' this.daterangeRecordTime[1] = today + ' 08:00:00' + // 初始化列显示 + this.updateColumnsVisibility(); this.getTreeMonitorInfo() this.getTreeselect() @@ -472,10 +477,25 @@ export default { }, // 节点单击事件 handleNodeClick(data) { - // 点击节点时清空monitorIds,只使用选中的monitorId + // 清空之前的查询条件 this.queryParams.monitorIds = []; - this.queryParams.monitorId = data.code - this.handleQuery() + this.queryParams.monitorId = null; + + // 判断是否为父节点(有children属性) + if (data.children && data.children.length > 0) { + // 父节点:收集所有子节点的code + this.queryParams.monitorIds = data.children.map(child => child.code); + console.log('点击父节点:', data.label, '子节点codes:', this.queryParams.monitorIds); + } else { + // 子节点:使用单个设备code + this.queryParams.monitorId = data.code; + console.log('点击子节点:', data.label, 'code:', data.code); + } + + // 存储当前选中节点的type,用于控制列显示 + this.selectedNodeType = data.type; + this.updateColumnsVisibility(); + this.handleQuery(); }, /** 查询物联网数据列表 */ @@ -536,9 +556,15 @@ export default { }, /** 重置按钮操作 */ resetQuery() { - this.resetForm("queryForm"); this.daterangeCollectTime = []; + + // 重置选中节点类型和查询条件 + this.selectedNodeType = null; + this.queryParams.monitorId = null; + this.queryParams.monitorIds = []; + this.updateColumnsVisibility(); + this.handleQuery(); }, // 多选框选中数据 @@ -606,6 +632,47 @@ export default { }) }, + // 根据选中节点类型更新列显示 + updateColumnsVisibility() { + // 重置所有列为不可见 + this.columns.forEach(col => { + if (col.key >= 2 && col.key <= 5) { // 传感器数据列 + col.visible = false; + } + }); + + if (!this.selectedNodeType) { + // 如果没有选中类型,显示所有传感器列 + this.columns[2].visible = true; // 温度 + this.columns[3].visible = true; // 湿度 + this.columns[4].visible = true; // 照度 + this.columns[5].visible = true; // 噪声 + return; + } + + // 根据type显示对应的传感器数据列 + switch (this.selectedNodeType) { + case 5: // 温度传感器:只显示温度 + this.columns[2].visible = true; // 温度 + break; + case 6: // 温湿度传感器:显示温度和湿度 + this.columns[2].visible = true; // 温度 + this.columns[3].visible = true; // 湿度 + break; + case 7: // 噪声传感器:只显示噪声 + this.columns[5].visible = true; // 噪声 + break; + default: + // 其他类型显示所有 + this.columns[2].visible = true; // 温度 + this.columns[3].visible = true; // 湿度 + this.columns[4].visible = true; // 照度 + this.columns[5].visible = true; // 噪声 + } + + console.log('更新列显示:', this.selectedNodeType, this.columns.map(c => ({key: c.key, label: c.label, visible: c.visible}))); + }, + } };