This commit is contained in:
2025-09-30 17:16:11 +08:00
parent e650a7c7f3
commit 52ce0e1969
25 changed files with 689 additions and 989 deletions

View File

@@ -1,52 +1,27 @@
import { http } from './http'
// 与老版保持相同的接口路径与参数
const base = '/api/device'
export interface DeviceQuota {
limit: number
used: number
}
export interface DeviceItem {
deviceId: string
name?: string
status?: 'online' | 'offline'
lastActiveAt?: string
}
// 统一处理AjaxResult格式
function handleAjaxResult(res: any) {
if (res?.code !== 200) {
throw new Error(res?.msg || '操作失败')
}
return res.data
}
export const deviceApi = {
getQuota(username: string): Promise<DeviceQuota> {
return http.get(`${base}/quota`, { username }).then(handleAjaxResult)
getQuota(username: string) {
return http.get('/api/device/quota', { username })
},
list(username: string): Promise<DeviceItem[]> {
return http.get(`${base}/list`, { username }).then(handleAjaxResult)
list(username: string) {
return http.get('/api/device/list', { username })
},
register(payload: { username: string }) {
return http.post(`${base}/register`, payload).then(handleAjaxResult)
return http.post('/api/device/register', payload)
},
remove(payload: { deviceId: string }) {
return http.post(`${base}/remove`, payload).then(handleAjaxResult)
return http.post('/api/device/remove', payload)
},
heartbeat(payload: { username: string; deviceId: string; version?: string }) {
return http.post(`${base}/heartbeat`, payload).then(handleAjaxResult)
return http.post('/api/device/heartbeat', payload)
},
offline(payload: { deviceId: string }) {
return http.post(`${base}/offline`, payload).then(handleAjaxResult)
},
}
return http.post('/api/device/offline', payload)
}
}