123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import { getAllIncidents, IncidentItemDetail } from '@/api/incident';
- import { getAllResources } from '@/api/resource';
- import {
- PENDING_DISPOSAL_INCIDENT,
- PENDING_INCIDENT,
- VIDEO_SURVEILLANCE,
- WARNING_INCIDENT,
- } from '@/components/MarkerMap/constants';
- import { defineStore } from 'pinia';
- export interface MarkerType
- extends NonNullable<IncidentItemDetail['baseInfo']> {
- marker?: any;
- popup?: any;
- [key: string]: any;
- }
- export interface MarkerStateType {
- warningIncident: MarkerType[];
- pendingIncident: MarkerType[];
- pendingDisposalIncident: MarkerType[];
- videoSurveillance: MarkerType[];
- emergencyVehicles: MarkerType[];
- emergencyTeam: MarkerType[];
- emergencyWarehouse: MarkerType[];
- loading: boolean;
- currentIncident: MarkerType;
- }
- export interface MainActionsType {
- toggleLoading(): void;
- getAllResources(): void;
- getAllIncidents(): void;
- }
- export default defineStore<'marker', MarkerStateType, {}, MainActionsType>(
- 'marker',
- {
- state: () => ({
- warningIncident: [],
- pendingIncident: [],
- pendingDisposalIncident: [],
- videoSurveillance: VIDEO_SURVEILLANCE,
- emergencyVehicles: [],
- emergencyTeam: [],
- emergencyWarehouse: [],
- loading: false,
- currentIncident: {},
- }),
- actions: {
- toggleLoading() {
- this.loading = !this.loading;
- },
- async getAllResources() {
- try {
- this.toggleLoading();
- const { data } = await getAllResources();
- this.emergencyVehicles =
- data.应急车队.map((i) => ({
- ...i,
- locations: `${i.longitude},${i.latitude}`,
- })) ?? [];
- this.emergencyTeam =
- data.应急队伍.map((i) => ({
- ...i,
- locations: `${i.longitude},${i.latitude}`,
- })) ?? [];
- this.emergencyWarehouse =
- data.应急仓库.map((i) => ({
- ...i,
- locations: `${i.longitude},${i.latitude}`,
- })) ?? [];
- } finally {
- this.toggleLoading();
- }
- },
- async getAllIncidents() {
- try {
- this.toggleLoading();
- const { data } = await getAllIncidents();
- this.warningIncident = data.预警事件 ?? [];
- this.pendingIncident = data.待派发 ?? [];
- this.pendingDisposalIncident = data.待处置 ?? [];
- } finally {
- this.toggleLoading();
- }
- },
- },
- },
- );
|