2025-10-19 21:38:04 +08:00
|
|
|
|
import http from '../utils/http';
|
2025-09-19 14:34:51 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-19 21:38:04 +08:00
|
|
|
|
* 获取系统中所有设备的列表
|
|
|
|
|
|
* @returns {Promise<*>}
|
2025-09-30 22:20:50 +08:00
|
|
|
|
*/
|
2025-10-19 21:38:04 +08:00
|
|
|
|
export const getDevices = () => {
|
|
|
|
|
|
return http.get('/api/v1/devices');
|
|
|
|
|
|
};
|
2025-09-30 22:20:50 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
2025-10-19 21:38:04 +08:00
|
|
|
|
* 根据提供的信息创建一个新设备
|
|
|
|
|
|
* @param {object} deviceData - 设备信息,对应 dto.CreateDeviceRequest
|
|
|
|
|
|
* @returns {Promise<*>}
|
2025-09-19 14:34:51 +08:00
|
|
|
|
*/
|
2025-10-19 21:38:04 +08:00
|
|
|
|
export const createDevice = (deviceData) => {
|
|
|
|
|
|
return http.post('/api/v1/devices', deviceData);
|
|
|
|
|
|
};
|
2025-09-19 14:34:51 +08:00
|
|
|
|
|
2025-10-19 21:38:04 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 根据设备ID获取单个设备的详细信息
|
|
|
|
|
|
* @param {string} id - 设备ID
|
|
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const getDeviceById = (id) => {
|
|
|
|
|
|
return http.get(`/api/v1/devices/${id}`);
|
|
|
|
|
|
};
|
2025-09-19 14:34:51 +08:00
|
|
|
|
|
2025-10-19 21:38:04 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 根据设备ID更新一个已存在的设备信息
|
|
|
|
|
|
* @param {string} id - 设备ID
|
|
|
|
|
|
* @param {object} deviceData - 要更新的设备信息,对应 dto.UpdateDeviceRequest
|
|
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const updateDevice = (id, deviceData) => {
|
|
|
|
|
|
return http.put(`/api/v1/devices/${id}`, deviceData);
|
|
|
|
|
|
};
|
2025-09-19 14:34:51 +08:00
|
|
|
|
|
2025-10-19 21:38:04 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 根据设备ID删除一个设备(软删除)
|
|
|
|
|
|
* @param {string} id - 设备ID
|
|
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const deleteDevice = (id) => {
|
|
|
|
|
|
return http.delete(`/api/v1/devices/${id}`);
|
|
|
|
|
|
};
|
2025-09-19 14:34:51 +08:00
|
|
|
|
|
2025-10-19 21:38:04 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 根据设备ID和指定的动作(开启或关闭)来手动控制设备
|
|
|
|
|
|
* @param {string} id - 设备ID
|
|
|
|
|
|
* @param {object} manualControlData - 手动控制指令,对应 dto.ManualControlDeviceRequest
|
|
|
|
|
|
* @returns {Promise<*>}
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const manualControlDevice = (id, manualControlData) => {
|
|
|
|
|
|
return http.post(`/api/v1/devices/manual-control/${id}`, manualControlData);
|
|
|
|
|
|
};
|
2025-10-20 14:52:25 +08:00
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|