2025-05-10 15:41:21 +08:00
|
|
|
import type { RobotGroup } from '@api/robot';
|
2025-04-30 00:17:09 +08:00
|
|
|
import http from '@core/http';
|
|
|
|
|
|
|
|
import type { SceneDetail, SceneInfo } from './type';
|
|
|
|
|
2025-04-29 20:08:08 +08:00
|
|
|
const enum API {
|
|
|
|
获取场景 = '/scene/getById',
|
2025-05-10 00:49:45 +08:00
|
|
|
保存场景 = '/scene/saveById',
|
2025-05-10 15:41:21 +08:00
|
|
|
|
|
|
|
获取组场景 = '/scene/getByGroupId',
|
2025-04-29 20:08:08 +08:00
|
|
|
}
|
|
|
|
|
2025-04-30 00:17:09 +08:00
|
|
|
export async function getSceneById(id: SceneInfo['id']): Promise<SceneDetail | null> {
|
|
|
|
if (!id) return null;
|
|
|
|
type B = { id: string };
|
|
|
|
type D = SceneDetail;
|
2025-05-05 01:06:09 +08:00
|
|
|
try {
|
|
|
|
const body = { id };
|
|
|
|
const data = await http.post<D, B>(API.获取场景, body);
|
|
|
|
return data ?? null;
|
|
|
|
} catch (error) {
|
|
|
|
console.debug(error);
|
|
|
|
return null;
|
|
|
|
}
|
2025-04-30 00:17:09 +08:00
|
|
|
}
|
2025-05-10 00:49:45 +08:00
|
|
|
|
|
|
|
export async function saveSceneById(id: SceneInfo['id'], json: string): Promise<boolean> {
|
|
|
|
if (!id) return false;
|
|
|
|
type B = { id: string; json: string };
|
|
|
|
type D = void;
|
|
|
|
try {
|
|
|
|
const body = { id, json };
|
|
|
|
await http.post<D, B>(API.保存场景, body);
|
|
|
|
return true;
|
|
|
|
} catch (error) {
|
|
|
|
console.debug(error);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2025-05-10 15:41:21 +08:00
|
|
|
|
|
|
|
export async function getSceneByGroupId(id: RobotGroup['id'], sid: RobotGroup['sid']): Promise<SceneDetail | null> {
|
|
|
|
if (!id) return null;
|
|
|
|
type B = { id: string; sid?: string };
|
|
|
|
type D = SceneDetail;
|
|
|
|
try {
|
|
|
|
const body = { id, sid };
|
|
|
|
const data = await http.post<D, B>(API.获取场景, body);
|
|
|
|
return data ?? null;
|
|
|
|
} catch (error) {
|
|
|
|
console.debug(error);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|