path.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import axios from "./instance";
  2. import { params } from "@/env";
  3. import { PATH_LIST, DELETE_PATH, INSERT_PATH, UPDATE_PATH } from "./constant";
  4. interface ServerPath {
  5. id: number;
  6. path: string;
  7. }
  8. export interface Path {
  9. id: string;
  10. isAnimate: boolean;
  11. name: string;
  12. showName: boolean;
  13. linePosition?: {
  14. position: SceneLocalPos;
  15. modelId: string;
  16. };
  17. lineWidth: number;
  18. lineColor: string;
  19. lineAltitudeAboveGround: number;
  20. fontSize: number;
  21. showDirection: boolean;
  22. reverseDirection: boolean;
  23. globalVisibility: boolean;
  24. visibilityRange: number;
  25. points: {
  26. name: string;
  27. position: SceneLocalPos;
  28. modelId: string;
  29. }[];
  30. }
  31. export type Paths = Path[];
  32. const serviceToLocal = (servicePath: ServerPath): Path => ({
  33. ...JSON.parse(servicePath.path),
  34. id: servicePath.id.toString(),
  35. });
  36. const localToService = (path: Path): ServerPath => ({
  37. id: Number(path.id),
  38. path: JSON.stringify(path),
  39. });
  40. export const fetchPaths = async () => {
  41. const staggings = await axios.get<ServerPath[]>(PATH_LIST, {
  42. params: { caseId: params.caseId },
  43. });
  44. return staggings.map(serviceToLocal);
  45. };
  46. export const postAddPath = async (path: Path) => {
  47. const stagging = await axios.post<ServerPath>(INSERT_PATH, {
  48. ...localToService(path),
  49. caseId: params.caseId,
  50. });
  51. return serviceToLocal(stagging);
  52. };
  53. export const postAddPathInPosition = async (path: Path, recordStartTime: any, recordEndTime: any) => {
  54. const stagging = await axios.post<ServerPath>(INSERT_PATH, {
  55. ...localToService(path),
  56. caseId: params.caseId,
  57. recordStartTime,
  58. recordEndTime
  59. });
  60. return serviceToLocal(stagging);
  61. };
  62. export const postUpdatePath = (path: Path) => {
  63. return axios.post<undefined>(UPDATE_PATH, {
  64. ...localToService(path),
  65. caseId: params.caseId,
  66. });
  67. };
  68. export const postDeletePath = (id: Path["id"]) => {
  69. return axios.post<undefined>(DELETE_PATH, { id: id });
  70. };