54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import type { RobotGroup } from '@api/robot';
|
|
import http from '@core/http';
|
|
|
|
import type { SceneDetail, SceneInfo } from './type';
|
|
|
|
const enum API {
|
|
获取场景 = '/scene/getById',
|
|
保存场景 = '/scene/saveById',
|
|
|
|
获取组场景 = '/scene/getByGroupId',
|
|
}
|
|
|
|
export async function getSceneById(id: SceneInfo['id']): Promise<SceneDetail | null> {
|
|
if (!id) return null;
|
|
type B = { id: string };
|
|
type D = SceneDetail;
|
|
try {
|
|
const body = { id };
|
|
const data = await http.post<D, B>(API.获取场景, body);
|
|
return data ?? null;
|
|
} catch (error) {
|
|
console.debug(error);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|