useMarkerStore.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import {
  2. getHDIncidentList,
  3. IncidentItem,
  4. IncidentItemDetail,
  5. } from '@/api/incident';
  6. import {
  7. getAllResources,
  8. getAllsingleDevice, ResourceItemDetail,
  9. SingleDeviceItem,getAllvideoDevice
  10. } from "@/api/resource";
  11. import {
  12. PENDING_DISPOSAL_INCIDENT,
  13. PENDING_INCIDENT,
  14. // EMERGENCY_VEHICLES,
  15. VIDEO_SURVEILLANCE,
  16. WARNING_INCIDENT,
  17. SINGLE_PAWN,
  18. // EMERGENCY_TEAM,
  19. } from '@/components/MarkerMap/constants';
  20. import { type } from 'os';
  21. import { defineStore } from 'pinia';
  22. type AllResources = NonNullable<IncidentItemDetail['baseInfo']> &
  23. NonNullable<SingleDeviceItem> & ResourceItemDetail;
  24. type Simply<T> = { [K in keyof T]: T[K] };
  25. export interface MarkerType extends Simply<AllResources> {
  26. locations?: string;
  27. marker?: any;
  28. popup?: any;
  29. // [key: string]: any;
  30. }
  31. export interface MarkerStateType {
  32. warningIncident: MarkerType[];
  33. pendingIncident: MarkerType[];
  34. pendingDisposalIncident: MarkerType[];
  35. videoSurveillance: MarkerType[];
  36. emergencyVehicles: MarkerType[];
  37. emergencyTeam: MarkerType[];
  38. emergencyWarehouse: MarkerType[];
  39. singleDevice: SingleDeviceItem[];
  40. /** 详情页面 点击监控点位 打开视频 */
  41. livevideovisible: boolean;
  42. livevideos: MarkerType[];
  43. incident: MarkerType[];
  44. loading: boolean;
  45. currentIncident: MarkerType;
  46. }
  47. export interface MainActionsType {
  48. toggleLoading(): void;
  49. getHDIncidentList(): void;
  50. getAllResources(): void;
  51. getAllsingleDevice(): void;
  52. }
  53. export default defineStore<'marker', MarkerStateType, {}, MainActionsType>(
  54. 'marker',
  55. {
  56. state: () => ({
  57. currentIncident: {},
  58. incident: [],
  59. warningIncident: [],
  60. pendingIncident: [],
  61. pendingDisposalIncident: [],
  62. videoSurveillance: [],
  63. emergencyVehicles: [],
  64. emergencyTeam: [],
  65. singleDevice: [],
  66. emergencyWarehouse: [],
  67. livevideos: [],
  68. livevideovisible: false,
  69. loading: false,
  70. }),
  71. actions: {
  72. toggleLoading() {
  73. this.loading = !this.loading;
  74. },
  75. async getHDIncidentList() {
  76. try {
  77. this.toggleLoading();
  78. const { data } = await getHDIncidentList();
  79. this.incident = (data as MarkerType[]) ?? [];
  80. } finally {
  81. this.toggleLoading();
  82. }
  83. },
  84. async getAllsingleDevice() {
  85. try {
  86. this.toggleLoading();
  87. const { data } = await getAllsingleDevice();
  88. this.singleDevice = [];
  89. this.singleDevice = Object.values(data).map((item) => ({
  90. ...item,
  91. locations: `${item.gpsX},${item.gpsY}`,
  92. }));
  93. console.log(this.singleDevice);
  94. } finally {
  95. this.toggleLoading();
  96. }
  97. },
  98. async getAllvideoDevice() {
  99. try {
  100. this.toggleLoading();
  101. const { data } = await getAllvideoDevice();
  102. let videoData = [];
  103. for(var index in data){
  104. if(data[index].gpsX){
  105. console.log(index);
  106. videoData.push(data[index]);
  107. }
  108. }
  109. this.videoSurveillance = [];
  110. this.videoSurveillance = Object.values(videoData).map((item) => ({
  111. ...item,
  112. locations: `${item.gpsX},${item.gpsY}`,
  113. }));
  114. console.log(this.videoSurveillance);
  115. } finally {
  116. this.toggleLoading();
  117. }
  118. },
  119. async getAllResources() {
  120. try {
  121. this.toggleLoading();
  122. const { data } = await getAllResources();
  123. // @ts-ignore
  124. this.emergencyVehicles =
  125. data.应急车队.map((i) => ({
  126. ...i,
  127. locations: `${i.longitude},${i.latitude}`,
  128. })) ?? [];
  129. // @ts-ignore
  130. this.emergencyTeam =
  131. data.应急队伍.map((i) => ({
  132. ...i,
  133. locations: `${i.longitude},${i.latitude}`,
  134. })) ?? [];
  135. // @ts-ignore
  136. this.emergencyWarehouse =
  137. data.应急仓库.map((i) => ({
  138. ...i,
  139. locations: `${i.longitude},${i.latitude}`,
  140. })) ?? [];
  141. } finally {
  142. this.toggleLoading();
  143. }
  144. },
  145. },
  146. },
  147. );