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 { 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(); } }, }, }, );