feat: 可视化大屏展示
This commit is contained in:
@@ -0,0 +1,164 @@
|
||||
import { request } from 'umi';
|
||||
|
||||
export interface DeviceItem {
|
||||
deviceSn?: string;
|
||||
deviceName?: string;
|
||||
boundStatus?: number;
|
||||
createTime?: string;
|
||||
status?: number; // 0-离线 1-在线
|
||||
deviceType?: string; // drone/dock/camera
|
||||
}
|
||||
|
||||
export interface TakeoffParams {
|
||||
deviceSn: string;
|
||||
targetLatitude: number;
|
||||
targetLongitude: number;
|
||||
targetHeight?: number;
|
||||
securityTakeoffHeight?: number;
|
||||
rthMode?: number;
|
||||
rthAltitude?: number;
|
||||
rcLostAction?: number;
|
||||
commanderModeLostAction?: number;
|
||||
commanderFlightMode?: number;
|
||||
commanderFlightHeight?: number;
|
||||
flightId?: string;
|
||||
maxSpeed?: number;
|
||||
flightSafetyAdvanceCheck?: number;
|
||||
}
|
||||
|
||||
export interface StickControlParams {
|
||||
deviceSn: string;
|
||||
roll?: number;
|
||||
pitch?: number;
|
||||
throttle?: number;
|
||||
yaw?: number;
|
||||
}
|
||||
|
||||
export interface GimbalControlParams {
|
||||
deviceSn: string;
|
||||
pitchSpeed?: number;
|
||||
yawSpeed?: number;
|
||||
locked?: boolean;
|
||||
}
|
||||
|
||||
export interface CommandResult {
|
||||
code?: number;
|
||||
msg?: string;
|
||||
resp_code?: number;
|
||||
resp_msg?: string;
|
||||
data?: string;
|
||||
}
|
||||
|
||||
function normalizeResponse(response: any): { code: number; msg: string; data?: any } {
|
||||
const code = response.resp_code !== undefined ? response.resp_code : response.code;
|
||||
const msg = response.resp_msg !== undefined ? response.resp_msg : response.msg;
|
||||
const data = response.data;
|
||||
return { code: code !== undefined ? code : 1, msg: msg || '', data };
|
||||
}
|
||||
|
||||
export const deviceApi = {
|
||||
// 设备列表
|
||||
deviceList: async (params: { page?: number; limit?: number; [k:string]: any }) => {
|
||||
const res = await request('/api-device/device', { method: 'GET', params });
|
||||
return { data: (res as any).data, total: (res as any).count } as { data: DeviceItem[]; total: number };
|
||||
},
|
||||
|
||||
// 航线列表
|
||||
wayline: async (params: { current?: number; pageSize?: number; [k:string]: any }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-device/wayline', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
return { data: (res as any).data, total: (res as any).count };
|
||||
},
|
||||
|
||||
// 一键起飞
|
||||
takeoff: async (params: TakeoffParams): Promise<CommandResult> => {
|
||||
const res = await request('/api-device/device/command/takeoff', { method: 'POST', data: params });
|
||||
return normalizeResponse(res);
|
||||
},
|
||||
|
||||
// 一键返航
|
||||
returnHome: async (deviceSn: string): Promise<CommandResult> => {
|
||||
const res = await request('/api-device/device/command/return', { method: 'POST', params: { deviceSn } });
|
||||
return normalizeResponse(res);
|
||||
},
|
||||
|
||||
// 取消返航
|
||||
cancelReturnHome: async (deviceSn: string): Promise<CommandResult> => {
|
||||
const res = await request('/api-device/device/command/return/cancel', { method: 'POST', params: { deviceSn } });
|
||||
return res as CommandResult;
|
||||
},
|
||||
|
||||
// 暂停
|
||||
pause: async (deviceSn: string): Promise<CommandResult> => {
|
||||
const res = await request('/api-device/device/command/pause', { method: 'POST', params: { deviceSn } });
|
||||
return res as CommandResult;
|
||||
},
|
||||
|
||||
// 恢复
|
||||
resume: async (deviceSn: string): Promise<CommandResult> => {
|
||||
const res = await request('/api-device/device/command/resume', { method: 'POST', params: { deviceSn } });
|
||||
return res as CommandResult;
|
||||
},
|
||||
|
||||
// 拍照
|
||||
takePhoto: async (deviceSn: string): Promise<CommandResult> => {
|
||||
const res = await request('/api-device/device/command/photo', { method: 'POST', params: { deviceSn } });
|
||||
return res as CommandResult;
|
||||
},
|
||||
|
||||
// 开始录像
|
||||
startRecording: async (deviceSn: string): Promise<CommandResult> => {
|
||||
const res = await request('/api-device/device/command/recording/start', { method: 'POST', params: { deviceSn } });
|
||||
return res as CommandResult;
|
||||
},
|
||||
|
||||
// 停止录像
|
||||
stopRecording: async (deviceSn: string): Promise<CommandResult> => {
|
||||
const res = await request('/api-device/device/command/recording/stop', { method: 'POST', params: { deviceSn } });
|
||||
return res as CommandResult;
|
||||
},
|
||||
|
||||
// 切换相机模式(0=拍照模式,1=录像模式)
|
||||
switchCameraMode: async (deviceSn: string, cameraMode: number): Promise<CommandResult> => {
|
||||
const res = await request('/api-device/device/command/camera/mode', { method: 'POST', params: { deviceSn, cameraMode } });
|
||||
return res as CommandResult;
|
||||
},
|
||||
|
||||
// 进入DRC模式
|
||||
enterDrcMode: async (deviceSn: string): Promise<CommandResult> => {
|
||||
const res = await request('/api-device/device/command/drc/enter', { method: 'POST', params: { deviceSn } });
|
||||
return res as CommandResult;
|
||||
},
|
||||
|
||||
// 杆量控制
|
||||
stickControl: async (params: StickControlParams): Promise<CommandResult> => {
|
||||
const res = await request('/api-device/device/command/drc/stick', { method: 'POST', data: params });
|
||||
return res as CommandResult;
|
||||
},
|
||||
|
||||
// 云台控制
|
||||
gimbalControl: async (params: GimbalControlParams): Promise<CommandResult> => {
|
||||
const res = await request('/api-device/device/command/gimbal', { method: 'POST', data: params });
|
||||
return res as CommandResult;
|
||||
},
|
||||
|
||||
// 订阅无人机遥测
|
||||
subscribeDroneTelemetry: async (deviceSn: string): Promise<{ success: boolean; message?: string }> => {
|
||||
try {
|
||||
const res = await request(`/api-device/sse/drone-telemetry/${deviceSn}/subscribe`, { method: 'POST' });
|
||||
return { success: true, message: res as string };
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error.message };
|
||||
}
|
||||
},
|
||||
|
||||
// 取消订阅
|
||||
unsubscribeDroneTelemetry: async (deviceSn: string): Promise<{ success: boolean; message?: string }> => {
|
||||
try {
|
||||
const res = await request(`/api-device/sse/drone-telemetry/${deviceSn}/unsubscribe`, { method: 'POST' });
|
||||
return { success: true, message: res as string };
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error.message };
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user