Initial commit
This commit is contained in:
48
electron-vue-template/src/renderer/api/device.ts
Normal file
48
electron-vue-template/src/renderer/api/device.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
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
|
||||
}
|
||||
|
||||
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 }
|
||||
})
|
||||
},
|
||||
|
||||
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[]) || []
|
||||
})
|
||||
},
|
||||
|
||||
register(payload: { username: string }) {
|
||||
return http.post(`${base}/register`, payload)
|
||||
},
|
||||
|
||||
remove(payload: { deviceId: string }) {
|
||||
return http.postVoid(`${base}/remove`, payload)
|
||||
},
|
||||
|
||||
heartbeat(payload: { username: string; deviceId: string; version?: string }) {
|
||||
return http.postVoid(`${base}/heartbeat`, payload)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user