import request, { CommonListResponse, IListWorkspaceResponse, IPage, IWorkspaceResponse } from '/@/api/http/request' const HTTP_PREFIX = '/manage/api/v1' // login export interface LoginBody { username: string, password: string, flag: number, } export interface BindBody { device_sn: string, user_id: string, workspace_id: string, domain?: string } export interface HmsQueryBody { sns: string[], children_sn: string, device_sn: string, language: string, level: number | string, begin_time: number, end_time: number, message: string, domain: string, } export const login = async function (body: LoginBody): Promise> { const url = `${HTTP_PREFIX}/login` const result = await request.post(url, body) return result.data } // Refresh Token export const refreshToken = async function (body: {}): Promise> { const url = `${HTTP_PREFIX}/token/refresh` const result = await request.post(url, body) return result.data } // Get Platform Info export const getPlatformInfo = async function (): Promise> { const url = `${HTTP_PREFIX}/workspaces/current` const result = await request.get(url) return result.data } // Get User Info export const getUserInfo = async function (): Promise> { const url = `${HTTP_PREFIX}/users/current` const result = await request.get(url) return result.data } // Get Device Topo export const getDeviceTopo = async function (workspace_id: string): Promise> { const url = `${HTTP_PREFIX}/devices/${workspace_id}/devices` const result = await request.get(url) return result.data } // Get Livestream Capacity export const getLiveCapacity = async function (body: {}): Promise> { const url = `${HTTP_PREFIX}/live/capacity` const result = await request.get(url, body) return result.data } // Start Livestream export const startLivestream = async function (body: {}): Promise> { const url = `${HTTP_PREFIX}/live/streams/start` const result = await request.post(url, body) return result.data } // Stop Livestream export const stopLivestream = async function (body: {}): Promise> { const url = `${HTTP_PREFIX}/live/streams/stop` const result = await request.post(url, body) return result.data } // Update Quality export const setLivestreamQuality = async function (body: {}): Promise> { const url = `${HTTP_PREFIX}/live/streams/update` const result = await request.post(url, body) return result.data } export const getAllUsersInfo = async function (wid: string, body: IPage): Promise> { const url = `${HTTP_PREFIX}/users/${wid}/users?&page=${body.page}&page_size=${body.page_size}` const result = await request.get(url) return result.data } export const updateUserInfo = async function (wid: string, user_id: string, body: {}): Promise> { const url = `${HTTP_PREFIX}/users/${wid}/users/${user_id}` const result = await request.put(url, body) return result.data } export const bindDevice = async function (body: BindBody): Promise> { const url = `${HTTP_PREFIX}/devices/${body.device_sn}/binding` const result = await request.post(url, body) return result.data } export const unbindDevice = async function (device_sn: string): Promise> { const url = `${HTTP_PREFIX}/devices/${device_sn}/unbinding` const result = await request.delete(url) return result.data } export const getDeviceBySn = async function (workspace_id: string, device_sn: string): Promise> { const url = `${HTTP_PREFIX}/devices/${workspace_id}/devices/${device_sn}` const result = await request.get(url) return result.data } export const getBindingDevices = async function (workspace_id: string, body: IPage, domain: string): Promise> { const url = `${HTTP_PREFIX}/devices/${workspace_id}/devices/bound?&page=${body.page}&page_size=${body.page_size}&domain=${domain}` const result = await request.get(url) return result.data } export const updateDevice = async function (body: {}, workspace_id: string, device_sn: string): Promise> { const url = `${HTTP_PREFIX}/devices/${workspace_id}/devices/${device_sn}` const result = await request.put(url, body) return result.data } export const getUnreadDeviceHms = async function (workspace_id: string, device_sn: string): Promise> { const url = `${HTTP_PREFIX}/devices/${workspace_id}/devices/hms/${device_sn}` const result = await request.get(url) return result.data } export const updateDeviceHms = async function (workspace_id: string, device_sn: string): Promise> { const url = `${HTTP_PREFIX}/devices/${workspace_id}/devices/hms/${device_sn}` const result = await request.put(url) return result.data } export const getDeviceHms = async function (body: HmsQueryBody, workspace_id: string, pagination: IPage): Promise> { let url = `${HTTP_PREFIX}/devices/${workspace_id}/devices/hms?page=${pagination.page}&pageSize=${pagination.page_size}` + `&level=${body.level ?? ''}&beginTime=${body.begin_time ?? ''}&endTime=${body.end_time ?? ''}&message=${body.message ?? ''}&language=${body.language}` body.sns.forEach((sn: string) => { if (sn !== '') { url = url.concat(`&deviceSn=${sn}`) } }) const result = await request.get(url) return result.data }