learshaw 4 месяцев назад
Родитель
Сommit
3166eb5299
1 измененных файлов с 174 добавлено и 19 удалено
  1. 174 19
      ems-ui-cloud/src/views/adapter/nhjc/index.vue

+ 174 - 19
ems-ui-cloud/src/views/adapter/nhjc/index.vue

@@ -315,7 +315,7 @@
           </div>
         </el-tab-pane>
 
-        <!-- 楼控设备标签页 - 新增 -->
+        <!-- 楼控设备标签页 - 已改造 -->
         <el-tab-pane label="楼控设备" name="baDevices">
           <div class="tab-content">
             <!-- 设备类型选择 -->
@@ -399,6 +399,51 @@
                   </el-tag>
                 </template>
               </el-table-column>
+              <!-- 新增操作列 -->
+              <el-table-column label="操作" width="200" align="center">
+                <template slot-scope="scope">
+                  <!-- 获取当前设备模型的能力列表 -->
+                  <template v-if="getBaDeviceAbilities(scope.row.deviceModel).length > 0">
+                    <template v-for="ability in getBaDeviceAbilities(scope.row.deviceModel)">
+                      <!-- 如果能力有 Options 参数定义,展示多个按钮 -->
+                      <el-button-group v-if="getParamType(ability.paramDefinition) === 'Options'" :key="ability.abilityKey" style="margin: 2px;">
+                        <el-button
+                          v-for="option in parseOptions(ability.paramDefinition)"
+                          :key="option.value"
+                          size="mini"
+                          type="primary"
+                          @click="executeBaDeviceAbility(scope.row, ability, option.value)"
+                          :loading="isBaAbilityExecuting(scope.row.deviceCode, ability.abilityKey, option.value)">
+                          {{ option.key }}
+                        </el-button>
+                      </el-button-group>
+                      <!-- 如果能力有其他参数类型(Slider/Input),显示单个按钮 -->
+                      <el-button
+                        v-else-if="getParamType(ability.paramDefinition) === 'Slider' || getParamType(ability.paramDefinition) === 'Input'"
+                        :key="ability.abilityKey"
+                        size="mini"
+                        type="primary"
+                        @click="handleBaDeviceAbilityClick(scope.row, ability)"
+                        :loading="isBaAbilityExecuting(scope.row.deviceCode, ability.abilityKey)"
+                        style="margin: 2px;">
+                        {{ ability.abilityName }}
+                      </el-button>
+                      <!-- 如果能力无参数,直接执行 -->
+                      <el-button
+                        v-else
+                        :key="ability.abilityKey"
+                        size="mini"
+                        type="primary"
+                        @click="executeBaDeviceAbility(scope.row, ability, null)"
+                        :loading="isBaAbilityExecuting(scope.row.deviceCode, ability.abilityKey)"
+                        style="margin: 2px;">
+                        {{ ability.abilityName }}
+                      </el-button>
+                    </template>
+                  </template>
+                  <span v-else style="color: #909399; font-size: 12px;">无可用操作</span>
+                </template>
+              </el-table-column>
             </el-table>
           </div>
         </el-tab-pane>
@@ -407,6 +452,16 @@
         <el-tab-pane label="调用日志" name="callLogs">
           <div class="tab-content">
             <el-form :inline="true" :model="callLogQuery" class="log-filter">
+              <el-form-item label="模型类型">
+                <el-select v-model="selectedLogModel" placeholder="请选择模型类型" clearable style="width: 200px;">
+                  <el-option
+                    v-for="item in logModelOptions"
+                    :key="item.modelCode"
+                    :label="item.modelName"
+                    :value="item.modelCode">
+                  </el-option>
+                </el-select>
+              </el-form-item>
               <el-form-item label="时间范围">
                 <el-date-picker
                   v-model="callLogQuery.dateRange"
@@ -466,6 +521,16 @@
         <el-tab-pane label="事件日志" name="eventLogs">
           <div class="tab-content">
             <el-form :inline="true" :model="eventLogQuery" class="log-filter">
+              <el-form-item label="模型类型">
+                <el-select v-model="selectedEventLogModel" placeholder="请选择模型类型" clearable style="width: 200px;">
+                  <el-option
+                    v-for="item in logModelOptions"
+                    :key="item.modelCode"
+                    :label="item.modelName"
+                    :value="item.modelCode">
+                  </el-option>
+                </el-select>
+              </el-form-item>
               <el-form-item label="时间范围">
                 <el-date-picker
                   v-model="eventLogQuery.dateRange"
@@ -724,7 +789,7 @@ export default {
       // 子设备相关
       subDeviceAttrs: {},
       subDeviceGatewayMap: {},
-      // 楼控设备相关 - 新增
+      // 楼控设备相关
       baDeviceModels: [
         { modelCode: 'M_Z020_DEV_BA_XF', modelName: 'BA新风设备' },
         { modelCode: 'M_Z020_DEV_BA_AHU', modelName: 'BA空调设备' },
@@ -735,7 +800,22 @@ export default {
       selectedBaDeviceModel: 'M_Z020_DEV_BA_XF',
       baDeviceList: [],
       baDeviceLoading: false,
-      baDeviceAttrs: {}, // 楼控设备属性缓存
+      baDeviceAttrs: {},
+      // 楼控设备能力执行状态
+      baAbilityExecuting: {},
+      // 日志模型选项
+      logModelOptions: [
+        { modelCode: 'ALL', modelName: '全部' },
+        { modelCode: 'M_W4_SYS_BA', modelName: '系统日志' },
+        { modelCode: 'M_W4_DEV_BA_GA', modelName: '能耗监测' },
+        { modelCode: 'M_Z020_DEV_BA_XF', modelName: 'BA新风设备' },
+        { modelCode: 'M_Z020_DEV_BA_AHU', modelName: 'BA空调设备' },
+        { modelCode: 'M_Z020_DEV_BA_WT', modelName: 'BA水箱监测' },
+        { modelCode: 'M_Z020_DEV_BA_WP', modelName: 'BA水泵监测' },
+        { modelCode: 'M_Z020_DEV_BA_LIGHT', modelName: 'BA照明监测' },
+      ],
+      selectedLogModel: 'ALL', // 调用日志选择的模型
+      selectedEventLogModel: 'ALL', // 事件日志选择的模型
       // 调用日志查询
       callLogQuery: {
         dateRange: [],
@@ -809,6 +889,67 @@ export default {
     this.initDateRange()
   },
   methods: {
+    // ========== 楼控设备能力相关方法 ==========
+
+    // 获取楼控设备的能力列表
+    getBaDeviceAbilities(deviceModel) {
+      if (!deviceModel) return []
+
+      const modelData = this.baDeviceAttrs['_model_' + deviceModel]
+      if (!modelData || !modelData.abilityList) return []
+
+      // 只返回 hiddenFlag === 1 的能力
+      return modelData.abilityList.filter(ability => ability.hiddenFlag === 1)
+    },
+
+    // 处理楼控设备能力点击(需要参数输入)
+    handleBaDeviceAbilityClick(device, ability) {
+      const paramType = this.getParamType(ability.paramDefinition)
+
+      if (paramType === 'Slider') {
+        this.showSliderDialog(ability, device, 2)
+      } else if (paramType === 'Input') {
+        this.showInputDialog(ability, device, 2)
+      }
+    },
+
+    // 执行楼控设备能力
+    async executeBaDeviceAbility(device, ability, paramValue) {
+      // 设置执行状态
+      const stateKey = `${device.deviceCode}_${ability.abilityKey}${paramValue !== null ? '_' + paramValue : ''}`
+      this.$set(this.baAbilityExecuting, stateKey, true)
+
+      try {
+        const params = {
+          objCode: device.deviceCode,
+          objType: 2,
+          modelCode: device.deviceModel,
+          abilityKey: ability.abilityKey,
+          abilityParam: paramValue
+        }
+
+        await callAbility(params)
+
+        this.$message.success(`${ability.abilityName}执行成功`)
+
+        // 刷新设备属性
+        await this.loadBaDeviceAttrsBatch(device.deviceModel)
+
+      } catch (error) {
+        this.$message.error(`${ability.abilityName}执行失败:${error.message}`)
+      } finally {
+        this.$set(this.baAbilityExecuting, stateKey, false)
+      }
+    },
+
+    // 判断楼控设备能力是否正在执行
+    isBaAbilityExecuting(deviceCode, abilityKey, paramValue) {
+      const stateKey = `${deviceCode}_${abilityKey}${paramValue !== undefined ? '_' + paramValue : ''}`
+      return this.baAbilityExecuting[stateKey] || false
+    },
+
+    // ========== 原有方法保持不变 ==========
+
     // 打开编辑对话框
     handleEdit() {
       this.editForm = { ...this.systemInfo }
@@ -939,7 +1080,6 @@ export default {
           data: res.data
         }
 
-        // 如果是抄表能力,刷新设备数据
         if (ability.abilityKey === 'MeterReadingGw' || ability.abilityKey === 'MeterReadingTotal') {
           this.loadDevices()
         }
@@ -1029,7 +1169,6 @@ export default {
         this.$message.success('执行成功')
         this.abilityDialogVisible = false
 
-        // 如果是抄表相关能力,刷新数据
         if (this.abilityForm.abilityKey.toLowerCase().includes('meter') ||
           this.abilityForm.abilityKey.toLowerCase().includes('reading')) {
           if (this.currentObjType === 3) {
@@ -1109,13 +1248,13 @@ export default {
       }
     },
 
-    // 加载设备列表(能耗网关) - 修改:添加deviceModel过滤
+    // 加载设备列表(能耗网关)
     async loadDevices() {
       this.deviceLoading = true
       try {
         const res = await getByCondition({
           subsystemCode: this.systemCode,
-          deviceModel: 'M_W4_DEV_BA_GA' // 仅查询能耗网关
+          deviceModel: 'M_W4_DEV_BA_GA'
         })
 
         const deviceData = res.data || res.rows || []
@@ -1125,7 +1264,6 @@ export default {
           detailTab: 'attrs'
         }))
 
-        // 收集设备模型
         const deviceModelCodes = new Set()
         this.deviceList.forEach(device => {
           if (device.deviceModel) {
@@ -1143,7 +1281,6 @@ export default {
         this.deviceStats.online = this.deviceList.filter(d => d.deviceStatus === 1).length
         this.deviceStats.offline = this.deviceList.filter(d => d.deviceStatus !== 1).length
 
-        // 按模型分组设备
         const devicesByModel = {}
         this.deviceList.forEach(device => {
           if (device.deviceModel) {
@@ -1154,12 +1291,10 @@ export default {
           }
         })
 
-        // 批量加载网关设备属性
         for (const modelCode in devicesByModel) {
           await this.loadDeviceAttrsBatch(modelCode, devicesByModel[modelCode])
         }
 
-        // 加载所有子设备的属性
         await this.loadAllSubDeviceAttrs()
 
       } catch (error) {
@@ -1438,7 +1573,7 @@ export default {
       this.$refs.deviceTable?.toggleRowExpansion(row)
     },
 
-    // ========== 楼控设备相关方法 - 新增 ==========
+    // ========== 楼控设备相关方法 ==========
 
     // 处理楼控设备类型切换
     handleBaDeviceTypeChange() {
@@ -1456,11 +1591,11 @@ export default {
 
       this.baDeviceLoading = true
       try {
-        // 1. 先查询设备物模型,获取属性定义
+        // 1. 先查询设备物模型,获取属性定义和能力列表
         const modelRes = await getModelByCode(this.selectedBaDeviceModel)
         const modelData = modelRes.data
 
-        // 缓存当前模型的属性定义
+        // 缓存当前模型的属性定义和能力列表
         this.$set(this.baDeviceAttrs, '_model_' + this.selectedBaDeviceModel, modelData)
 
         // 2. 查询指定模型的设备列表
@@ -1504,7 +1639,7 @@ export default {
       }
     },
 
-    // 获取楼控设备的属性(按组) - 修改:合并模型定义和实际值
+    // 获取楼控设备的属性(按组)
     getBaDeviceAttrs(deviceCode, attrGroup) {
       // 获取设备所属的模型
       const device = this.baDeviceList.find(d => d.deviceCode === deviceCode)
@@ -1587,14 +1722,30 @@ export default {
       }
     },
 
-    // ========== 日志查询相关 ==========
+    // ========== 日志查询相关 - 已优化 ==========
+
+    // 获取要查询的模型代码列表
+    getQueryModelCodes(selectedModel) {
+      if (selectedModel === 'ALL' || !selectedModel) {
+        // 返回所有模型代码(排除 'ALL' 选项)
+        return this.logModelOptions
+          .filter(item => item.modelCode !== 'ALL')
+          .map(item => item.modelCode)
+      } else {
+        // 返回单个选中的模型
+        return [selectedModel]
+      }
+    },
 
     // 查询调用日志
     async queryCallLogs() {
       this.logLoading = true
       try {
+        // 根据选择的模型类型获取要查询的modelCodes
+        const modelCodes = this.getQueryModelCodes(this.selectedLogModel)
+
         const params = {
-          modelCodes: this.allModelCodes,
+          modelCodes: modelCodes,
           pageNum: this.callLogQuery.pageNum,
           pageSize: this.callLogQuery.pageSize
         }
@@ -1624,6 +1775,7 @@ export default {
 
     // 重置调用日志查询
     resetCallLogQuery() {
+      this.selectedLogModel = 'ALL'
       this.initDateRange()
       this.callLogQuery.abilityKey = ''
       this.callLogQuery.callStatus = ''
@@ -1635,8 +1787,11 @@ export default {
     async queryEventLogs() {
       this.eventLogLoading = true
       try {
+        // 根据选择的模型类型获取要查询的modelCodes
+        const modelCodes = this.getQueryModelCodes(this.selectedEventLogModel)
+
         const params = {
-          modelCodes: this.allModelCodes,
+          modelCodes: modelCodes,
           pageNum: this.eventLogQuery.pageNum,
           pageSize: this.eventLogQuery.pageSize
         }
@@ -1662,6 +1817,7 @@ export default {
 
     // 重置事件日志查询
     resetEventLogQuery() {
+      this.selectedEventLogModel = 'ALL'
       this.initDateRange()
       this.eventLogQuery.eventKey = ''
       this.eventLogQuery.pageNum = 1
@@ -1843,7 +1999,6 @@ export default {
     }
   }
 
-  // 楼控设备样式 - 新增
   .ba-device-header {
     display: flex;
     align-items: center;