setting.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { GET_SETTING, UPDATE_SETTING } from "./constant";
  2. import defaultCover from "@/assets/cover.png";
  3. import { params } from "@/env";
  4. import axios from "./instance";
  5. import { fetchMapTiles } from "./map-tile";
  6. type ServeSetting = {
  7. settingsId?: string;
  8. pose?: string;
  9. cover?: string;
  10. mapType?: 'satellite' | 'standard',
  11. back?: string | null;
  12. mapId?: number | null
  13. };
  14. export type Setting = {
  15. id?: string;
  16. title?: string
  17. initGPS?: string
  18. pose?: {
  19. position: SceneLocalPos;
  20. target: SceneLocalPos;
  21. panoInfo?: {
  22. panoId: any;
  23. modelId: string;
  24. posInModel: SceneLocalPos;
  25. rotInModel: SceneLocalPos;
  26. };
  27. };
  28. mapType: 'satellite' | 'standard',
  29. cover: string;
  30. back?: string | null;
  31. fov?: number;
  32. openCompass?: boolean;
  33. mapId?: number | null
  34. };
  35. const toLocal = (serviceSetting: ServeSetting): Setting => ({
  36. id: serviceSetting.settingsId,
  37. pose: serviceSetting.pose && JSON.parse(serviceSetting.pose),
  38. cover: serviceSetting.cover || defaultCover,
  39. back: serviceSetting.back || undefined,
  40. mapType: serviceSetting.mapType || 'satellite',
  41. mapId: serviceSetting.mapId || undefined,
  42. });
  43. const toService = (setting: Setting): ServeSetting => ({
  44. settingsId: setting.id,
  45. mapId: setting.mapId || null,
  46. pose: setting.pose && JSON.stringify(setting.pose),
  47. cover: setting.cover,
  48. back: setting.back || null,
  49. mapType: setting.mapType,
  50. });
  51. export const fetchSetting = async () => {
  52. let data = await axios.get<ServeSetting[]>(GET_SETTING, {
  53. params: { fusionId: params.caseId },
  54. });
  55. const tData = toLocal(data[0] || {})
  56. if (!tData.back && !tData.mapId) {
  57. const tiles = await fetchMapTiles()
  58. tData.mapId = tiles[0].id
  59. }
  60. return tData
  61. };
  62. export const updateSetting = async (setting: Setting) => {
  63. await axios.post(UPDATE_SETTING, {
  64. fusionId: params.caseId,
  65. ...toService(setting),
  66. });
  67. };