This commit is contained in:
2025-10-20 15:07:30 +08:00
parent a3e9465b88
commit fdc568753c
2 changed files with 89 additions and 52 deletions

View File

@@ -1,5 +1,7 @@
import http from '../utils/http';
// --- Device API Functions ---
/**
* 获取系统中所有设备的列表
* @returns {Promise<*>}
@@ -55,41 +57,71 @@ export const manualControlDevice = (id, manualControlData) => {
return http.post(`/api/v1/devices/manual-control/${id}`, manualControlData);
};
// --- AreaController API Functions ---
/**
* 获取系统中所有区域主控的列表
* @returns {Promise<*>}
*/
export const getAreaControllers = () => {
return http.get('/api/v1/area-controllers');
};
/**
* 创建一个新区域主控
* @param {object} areaControllerData - 区域主控信息
* @returns {Promise<*>}
*/
export const createAreaController = (areaControllerData) => {
return http.post('/api/v1/area-controllers', areaControllerData);
};
/**
* 根据ID获取单个区域主控的详细信息
* @param {string} id - 区域主控ID
* @returns {Promise<*>}
*/
export const getAreaControllerById = (id) => {
return http.get(`/api/v1/area-controllers/${id}`);
};
/**
* 根据ID更新一个已存在的区域主控信息
* @param {string} id - 区域主控ID
* @param {object} areaControllerData - 要更新的区域主控信息
* @returns {Promise<*>}
*/
export const updateAreaController = (id, areaControllerData) => {
return http.put(`/api/v1/area-controllers/${id}`, areaControllerData);
};
/**
* 根据ID删除一个区域主控
* @param {string} id - 区域主控ID
* @returns {Promise<*>}
*/
export const deleteAreaController = (id) => {
return http.delete(`/api/v1/area-controllers/${id}`);
};
// --- API Wrappers ---
// AreaControllerApi 封装
export const AreaControllerApi = {
list: async () => {
const response = await getDevices();
return {
...response,
data: response.data.filter(device => device.type === 'area_controller')
};
},
create: (deviceData) => {
return createDevice({ ...deviceData, type: 'area_controller' });
},
getById: (id) => {
return getDeviceById(id);
},
update: (id, deviceData) => {
return updateDevice(id, { ...deviceData, type: 'area_controller' });
},
delete: (id) => {
return deleteDevice(id);
}
list: getAreaControllers,
create: createAreaController,
getById: getAreaControllerById,
update: updateAreaController,
delete: deleteAreaController
};
// DeviceApi 封装
export const DeviceApi = {
create: (deviceData) => {
return createDevice({ ...deviceData, type: 'device' });
},
getById: (id) => {
return getDeviceById(id);
},
update: (id, deviceData) => {
return updateDevice(id, { ...deviceData, type: 'device' });
},
delete: (id) => {
return deleteDevice(id);
}
list: getDevices,
create: createDevice,
getById: getDeviceById,
update: updateDevice,
delete: deleteDevice
};