useMarkerStore.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { getAllIncidents, IncidentItemDetail } from '@/api/incident';
  2. import { getAllResources } from '@/api/resource';
  3. import {
  4. PENDING_DISPOSAL_INCIDENT,
  5. PENDING_INCIDENT,
  6. VIDEO_SURVEILLANCE,
  7. WARNING_INCIDENT,
  8. } from '@/components/MarkerMap/constants';
  9. import { defineStore } from 'pinia';
  10. export interface MarkerType
  11. extends NonNullable<IncidentItemDetail['baseInfo']> {
  12. marker?: any;
  13. popup?: any;
  14. [key: string]: any;
  15. }
  16. export interface MarkerStateType {
  17. warningIncident: MarkerType[];
  18. pendingIncident: MarkerType[];
  19. pendingDisposalIncident: MarkerType[];
  20. videoSurveillance: MarkerType[];
  21. emergencyVehicles: MarkerType[];
  22. emergencyTeam: MarkerType[];
  23. emergencyWarehouse: MarkerType[];
  24. loading: boolean;
  25. currentIncident: MarkerType;
  26. }
  27. export interface MainActionsType {
  28. toggleLoading(): void;
  29. getAllResources(): void;
  30. getAllIncidents(): void;
  31. }
  32. export default defineStore<'marker', MarkerStateType, {}, MainActionsType>(
  33. 'marker',
  34. {
  35. state: () => ({
  36. warningIncident: [],
  37. pendingIncident: [],
  38. pendingDisposalIncident: [],
  39. videoSurveillance: VIDEO_SURVEILLANCE,
  40. emergencyVehicles: [],
  41. emergencyTeam: [],
  42. emergencyWarehouse: [],
  43. loading: false,
  44. currentIncident: {},
  45. }),
  46. actions: {
  47. toggleLoading() {
  48. this.loading = !this.loading;
  49. },
  50. async getAllResources() {
  51. try {
  52. this.toggleLoading();
  53. const { data } = await getAllResources();
  54. this.emergencyVehicles =
  55. data.应急车队.map((i) => ({
  56. ...i,
  57. locations: `${i.longitude},${i.latitude}`,
  58. })) ?? [];
  59. this.emergencyTeam =
  60. data.应急队伍.map((i) => ({
  61. ...i,
  62. locations: `${i.longitude},${i.latitude}`,
  63. })) ?? [];
  64. this.emergencyWarehouse =
  65. data.应急仓库.map((i) => ({
  66. ...i,
  67. locations: `${i.longitude},${i.latitude}`,
  68. })) ?? [];
  69. } finally {
  70. this.toggleLoading();
  71. }
  72. },
  73. async getAllIncidents() {
  74. try {
  75. this.toggleLoading();
  76. const { data } = await getAllIncidents();
  77. this.warningIncident = data.预警事件 ?? [];
  78. this.pendingIncident = data.待派发 ?? [];
  79. this.pendingDisposalIncident = data.待处置 ?? [];
  80. } finally {
  81. this.toggleLoading();
  82. }
  83. },
  84. },
  85. },
  86. );