This commit is contained in:
149
src/api/modules/device.ts
Normal file
149
src/api/modules/device.ts
Normal file
@@ -0,0 +1,149 @@
|
||||
/**
|
||||
* 设备管理相关 API
|
||||
*/
|
||||
|
||||
import { BaseService } from '../BaseService'
|
||||
import type {
|
||||
Device,
|
||||
DeviceQueryParams,
|
||||
DeviceListResponse,
|
||||
DeviceCardsResponse,
|
||||
BindCardToDeviceRequest,
|
||||
BindCardToDeviceResponse,
|
||||
UnbindCardFromDeviceResponse,
|
||||
AllocateDevicesRequest,
|
||||
AllocateDevicesResponse,
|
||||
RecallDevicesRequest,
|
||||
RecallDevicesResponse,
|
||||
ImportDeviceRequest,
|
||||
ImportDeviceResponse,
|
||||
DeviceImportTaskQueryParams,
|
||||
DeviceImportTaskListResponse,
|
||||
DeviceImportTaskDetail,
|
||||
BaseResponse
|
||||
} from '@/types/api'
|
||||
|
||||
export class DeviceService extends BaseService {
|
||||
// ========== 设备基础管理 ==========
|
||||
|
||||
/**
|
||||
* 获取设备列表
|
||||
* @param params 查询参数
|
||||
*/
|
||||
static getDevices(params?: DeviceQueryParams): Promise<BaseResponse<DeviceListResponse>> {
|
||||
return this.get<BaseResponse<DeviceListResponse>>('/api/admin/devices', params)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备详情
|
||||
* @param id 设备ID
|
||||
*/
|
||||
static getDeviceById(id: number): Promise<BaseResponse<Device>> {
|
||||
return this.getOne<Device>(`/api/admin/devices/${id}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备
|
||||
* @param id 设备ID
|
||||
*/
|
||||
static deleteDevice(id: number): Promise<BaseResponse> {
|
||||
return this.remove(`/api/admin/devices/${id}`)
|
||||
}
|
||||
|
||||
// ========== 设备卡绑定管理 ==========
|
||||
|
||||
/**
|
||||
* 获取设备绑定的卡列表
|
||||
* @param id 设备ID
|
||||
*/
|
||||
static getDeviceCards(id: number): Promise<BaseResponse<DeviceCardsResponse>> {
|
||||
return this.getOne<DeviceCardsResponse>(`/api/admin/devices/${id}/cards`)
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定卡到设备
|
||||
* @param id 设备ID
|
||||
* @param data 绑定参数
|
||||
*/
|
||||
static bindCard(
|
||||
id: number,
|
||||
data: BindCardToDeviceRequest
|
||||
): Promise<BaseResponse<BindCardToDeviceResponse>> {
|
||||
return this.post<BaseResponse<BindCardToDeviceResponse>>(
|
||||
`/api/admin/devices/${id}/cards`,
|
||||
data
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 解绑设备上的卡
|
||||
* @param deviceId 设备ID
|
||||
* @param cardId IoT卡ID
|
||||
*/
|
||||
static unbindCard(
|
||||
deviceId: number,
|
||||
cardId: number
|
||||
): Promise<BaseResponse<UnbindCardFromDeviceResponse>> {
|
||||
return this.delete<BaseResponse<UnbindCardFromDeviceResponse>>(
|
||||
`/api/admin/devices/${deviceId}/cards/${cardId}`
|
||||
)
|
||||
}
|
||||
|
||||
// ========== 批量分配和回收 ==========
|
||||
|
||||
/**
|
||||
* 批量分配设备
|
||||
* @param data 分配参数
|
||||
*/
|
||||
static allocateDevices(
|
||||
data: AllocateDevicesRequest
|
||||
): Promise<BaseResponse<AllocateDevicesResponse>> {
|
||||
return this.post<BaseResponse<AllocateDevicesResponse>>(
|
||||
'/api/admin/devices/allocate',
|
||||
data
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量回收设备
|
||||
* @param data 回收参数
|
||||
*/
|
||||
static recallDevices(
|
||||
data: RecallDevicesRequest
|
||||
): Promise<BaseResponse<RecallDevicesResponse>> {
|
||||
return this.post<BaseResponse<RecallDevicesResponse>>('/api/admin/devices/recall', data)
|
||||
}
|
||||
|
||||
// ========== 设备导入 ==========
|
||||
|
||||
/**
|
||||
* 批量导入设备
|
||||
* @param data 导入参数
|
||||
*/
|
||||
static importDevices(
|
||||
data: ImportDeviceRequest
|
||||
): Promise<BaseResponse<ImportDeviceResponse>> {
|
||||
return this.post<BaseResponse<ImportDeviceResponse>>('/api/admin/devices/import', data)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取导入任务列表
|
||||
* @param params 查询参数
|
||||
*/
|
||||
static getImportTasks(
|
||||
params?: DeviceImportTaskQueryParams
|
||||
): Promise<BaseResponse<DeviceImportTaskListResponse>> {
|
||||
return this.get<BaseResponse<DeviceImportTaskListResponse>>(
|
||||
'/api/admin/devices/import/tasks',
|
||||
params
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取导入任务详情
|
||||
* @param id 任务ID
|
||||
*/
|
||||
static getImportTaskDetail(id: number): Promise<BaseResponse<DeviceImportTaskDetail>> {
|
||||
return this.getOne<DeviceImportTaskDetail>(`/api/admin/devices/import/tasks/${id}`)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user