定义api

This commit is contained in:
2025-09-19 14:34:51 +08:00
parent fbf3f77229
commit 1e894b7700
5 changed files with 172 additions and 6 deletions

View File

@@ -1,5 +1,4 @@
import http from '../utils/http.js';
import API_CONFIG from '../config/api.js';
import apiClient from '../api/index.js';
class DeviceService {
/**
@@ -8,7 +7,7 @@ class DeviceService {
*/
async getDevices() {
try {
const response = await http.get(API_CONFIG.ENDPOINTS.DEVICES);
const response = await apiClient.devices.list();
return response.data || [];
} catch (error) {
console.error('获取设备列表失败:', error);
@@ -23,7 +22,7 @@ class DeviceService {
*/
async createDevice(device) {
try {
const response = await http.post(API_CONFIG.ENDPOINTS.DEVICES, device);
const response = await apiClient.devices.create(device);
return response.data;
} catch (error) {
console.error('创建设备失败:', error);
@@ -39,7 +38,7 @@ class DeviceService {
*/
async updateDevice(deviceId, device) {
try {
const response = await http.put(`${API_CONFIG.ENDPOINTS.DEVICES}/${deviceId}`, device);
const response = await apiClient.devices.update(deviceId, device);
return response.data;
} catch (error) {
console.error('更新设备失败:', error);
@@ -54,7 +53,7 @@ class DeviceService {
*/
async deleteDevice(deviceId) {
try {
await http.delete(`${API_CONFIG.ENDPOINTS.DEVICES}/${deviceId}`);
await apiClient.devices.delete(deviceId);
} catch (error) {
console.error('删除设备失败:', error);
throw error;