path.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. name: string;
  11. showName: boolean;
  12. linePosition?: {
  13. position: SceneLocalPos;
  14. modelId: string;
  15. };
  16. lineWidth: number;
  17. lineColor: string;
  18. lineAltitudeAboveGround: number;
  19. fontSize: number;
  20. showDirection: boolean;
  21. reverseDirection: boolean;
  22. globalVisibility: boolean;
  23. visibilityRange: number;
  24. points: {
  25. name: string;
  26. position: SceneLocalPos;
  27. modelId: string;
  28. }[];
  29. }
  30. export type Paths = Path[];
  31. const serviceToLocal = (servicePath: ServerPath): Path => ({
  32. ...JSON.parse(servicePath.path),
  33. id: servicePath.id.toString(),
  34. });
  35. const localToService = (path: Path): ServerPath => ({
  36. id: Number(path.id),
  37. path: JSON.stringify(path),
  38. });
  39. export const fetchPaths = async () => {
  40. const staggings = await axios.get<ServerPath[]>(PATH_LIST, {
  41. params: { caseId: params.caseId },
  42. });
  43. return staggings.map(serviceToLocal);
  44. };
  45. export const postAddPath = async (path: Path) => {
  46. const stagging = await axios.post<ServerPath>(INSERT_PATH, {
  47. ...localToService(path),
  48. caseId: params.caseId,
  49. });
  50. return serviceToLocal(stagging);
  51. };
  52. export const postUpdatePath = (path: Path) => {
  53. return axios.post<undefined>(UPDATE_PATH, {
  54. ...localToService(path),
  55. caseId: params.caseId,
  56. });
  57. };
  58. export const postDeletePath = (id: Path["id"]) => {
  59. return axios.post<undefined>(DELETE_PATH, { pathId: id });
  60. };