1
This commit is contained in:
@@ -15,37 +15,37 @@ export interface DeviceItem {
|
||||
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) {
|
||||
return http.get<DeviceQuota | any>(`${base}/quota`, { username }).then((res: any) => {
|
||||
if (res && typeof res.limit !== 'undefined') return res as DeviceQuota
|
||||
if (res && typeof res.code === 'number') return (res.data as DeviceQuota) || { limit: 0, used: 0 }
|
||||
return (res?.data as DeviceQuota) || { limit: 0, used: 0 }
|
||||
})
|
||||
getQuota(username: string): Promise<DeviceQuota> {
|
||||
return http.get(`${base}/quota`, { username }).then(handleAjaxResult)
|
||||
},
|
||||
|
||||
list(username: string) {
|
||||
return http.get<DeviceItem[] | any>(`${base}/list`, { username }).then((res: any) => {
|
||||
if (Array.isArray(res)) return res as DeviceItem[]
|
||||
if (res && typeof res.code === 'number') return (res.data as DeviceItem[]) || []
|
||||
return (res?.data as DeviceItem[]) || []
|
||||
})
|
||||
list(username: string): Promise<DeviceItem[]> {
|
||||
return http.get(`${base}/list`, { username }).then(handleAjaxResult)
|
||||
},
|
||||
|
||||
register(payload: { username: string }) {
|
||||
return http.post(`${base}/register`, payload)
|
||||
return http.post(`${base}/register`, payload).then(handleAjaxResult)
|
||||
},
|
||||
|
||||
remove(payload: { deviceId: string }) {
|
||||
return http.postVoid(`${base}/remove`, payload)
|
||||
return http.post(`${base}/remove`, payload).then(handleAjaxResult)
|
||||
},
|
||||
|
||||
heartbeat(payload: { username: string; deviceId: string; version?: string }) {
|
||||
return http.postVoid(`${base}/heartbeat`, payload)
|
||||
return http.post(`${base}/heartbeat`, payload).then(handleAjaxResult)
|
||||
},
|
||||
|
||||
offline(payload: { deviceId: string }) {
|
||||
return http.postVoid(`${base}/offline`, payload)
|
||||
return http.post(`${base}/offline`, payload).then(handleAjaxResult)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user