Compare commits
	
		
			4 Commits
		
	
	
		
			6fce84c002
			...
			02e9f9b9a3
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 02e9f9b9a3 | |||
| 983b929d90 | |||
| e48d5ab2d8 | |||
| 320df0b3d4 | 
@@ -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();
 | 
			
		||||
 
 | 
			
		||||
@@ -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="false">
 | 
			
		||||
        <el-table-column width="40"></el-table-column>
 | 
			
		||||
        <el-table-column prop="id" label="设备ID" min-width="80" />
 | 
			
		||||
        <el-table-column prop="name" label="设备名称" min-width="120" />
 | 
			
		||||
@@ -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 '';
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
};
 | 
			
		||||
@@ -235,6 +258,11 @@ export default {
 | 
			
		||||
  margin-top: 15px;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* 确保区域主控设备始终高亮显示 */
 | 
			
		||||
:deep(.current-row) {
 | 
			
		||||
  background-color: #f5f7fa !important;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@media (max-width: 768px) {
 | 
			
		||||
  .device-list {
 | 
			
		||||
    padding: 10px;
 | 
			
		||||
 
 | 
			
		||||
@@ -29,8 +29,20 @@ http.interceptors.request.use(
 | 
			
		||||
// 响应拦截器
 | 
			
		||||
http.interceptors.response.use(
 | 
			
		||||
  response => {
 | 
			
		||||
    // 可以在这里统一处理响应数据
 | 
			
		||||
    return response.data;
 | 
			
		||||
    // 统一处理响应数据,检查code字段
 | 
			
		||||
    const data = response.data;
 | 
			
		||||
    
 | 
			
		||||
    // 如果存在code字段且不在2000到3000之间,表示请求失败
 | 
			
		||||
    if (data.code !== undefined && (data.code < 2000 || data.code >= 3000)) {
 | 
			
		||||
      // 抛出错误,包含错误信息
 | 
			
		||||
      const error = new Error(data.message || '请求失败');
 | 
			
		||||
      error.code = data.code;
 | 
			
		||||
      error.data = data;
 | 
			
		||||
      return Promise.reject(error);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    // code在2000到3000之间或不存在code字段时,返回数据
 | 
			
		||||
    return data;
 | 
			
		||||
  },
 | 
			
		||||
  error => {
 | 
			
		||||
    // 统一错误处理
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user