修bug
This commit is contained in:
		| @@ -1,4 +1,4 @@ | ||||
| import {AreaControllerApi, DeviceApi} from '../api/device.js'; | ||||
| import {AreaControllerApi, DeviceApi, getDevices} from '../api/device.js'; | ||||
|  | ||||
| class DeviceService { | ||||
|     /** | ||||
| @@ -7,9 +7,9 @@ class DeviceService { | ||||
|      */ | ||||
|     async getDevices() { | ||||
|         try { | ||||
|             const [areaControllersResponse, devicesResponse] = await Promise.all([ | ||||
|             const [areaControllersResponse, allDevicesResponse] = await Promise.all([ | ||||
|                 AreaControllerApi.list(), | ||||
|                 DeviceApi.list() | ||||
|                 getDevices() // 使用通用的getDevices函数获取所有设备 | ||||
|             ]); | ||||
|  | ||||
|             const areaControllers = (areaControllersResponse.data || []).map(controller => ({ | ||||
| @@ -17,11 +17,13 @@ class DeviceService { | ||||
|                 type: 'area_controller' // 添加类型标识 | ||||
|             })); | ||||
|  | ||||
|             const devices = (devicesResponse.data || []).map(device => ({ | ||||
|                 ...device, | ||||
|                 type: 'device', // 添加类型标识 | ||||
|                 parent_id: device.area_controller_id // 适配前端树形结构 | ||||
|             })); | ||||
|             const devices = (allDevicesResponse.data || []) | ||||
|                 .filter(device => device.type === 'device') // 过滤出普通设备 | ||||
|                 .map(device => ({ | ||||
|                     ...device, | ||||
|                     type: 'device', // 添加类型标识 | ||||
|                     parent_id: device.area_controller_id // 适配前端树形结构 | ||||
|                 })); | ||||
|  | ||||
|             return [...areaControllers, ...devices]; | ||||
|         } catch (error) { | ||||
| @@ -60,10 +62,10 @@ class DeviceService { | ||||
|     async getDevice(id, type) { | ||||
|         try { | ||||
|             if (type === 'area_controller') { | ||||
|                 const response = await AreaControllerApi.get(id); | ||||
|                 const response = await AreaControllerApi.getById(id); | ||||
|                 return {...response.data, type: 'area_controller'}; | ||||
|             } else { | ||||
|                 const response = await DeviceApi.get(id); | ||||
|                 const response = await DeviceApi.getById(id); | ||||
|                 return {...response.data, type: 'device', parent_id: response.data.area_controller_id}; | ||||
|             } | ||||
|         } catch (error) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user