This commit is contained in:
2025-09-19 14:25:20 +08:00
parent 269893a435
commit fbf3f77229
24949 changed files with 2839404 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
import http from '../utils/http.js';
import API_CONFIG from '../config/api.js';
class DeviceService {
/**
* 获取设备列表
* @returns {Promise<Array>} 设备列表
*/
async getDevices() {
try {
const response = await http.get(API_CONFIG.ENDPOINTS.DEVICES);
return response.data || [];
} catch (error) {
console.error('获取设备列表失败:', error);
throw error;
}
}
/**
* 创建新设备
* @param {Object} device 设备信息
* @returns {Promise<Object>} 创建的设备信息
*/
async createDevice(device) {
try {
const response = await http.post(API_CONFIG.ENDPOINTS.DEVICES, device);
return response.data;
} catch (error) {
console.error('创建设备失败:', error);
throw error;
}
}
/**
* 更新设备信息
* @param {string} deviceId 设备ID
* @param {Object} device 更新的设备信息
* @returns {Promise<Object>} 更新后的设备信息
*/
async updateDevice(deviceId, device) {
try {
const response = await http.put(`${API_CONFIG.ENDPOINTS.DEVICES}/${deviceId}`, device);
return response.data;
} catch (error) {
console.error('更新设备失败:', error);
throw error;
}
}
/**
* 删除设备
* @param {string} deviceId 设备ID
* @returns {Promise<void>}
*/
async deleteDevice(deviceId) {
try {
await http.delete(`${API_CONFIG.ENDPOINTS.DEVICES}/${deviceId}`);
} catch (error) {
console.error('删除设备失败:', error);
throw error;
}
}
}
// 导出设备服务实例
export default new DeviceService();