useMarkerStore.ts 4.5 KB

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