| | |
| | | import { defineStore } from "pinia"; |
| | | import { loadDetectionArtifacts, loadTrajectoryArtifacts, type DetectionCase, type TrajectoryCase } from "@/api/artifacts"; |
| | | |
| | | import { |
| | | loadDetectionArtifacts, |
| | | loadTrajectoryArtifacts, |
| | | type DetectionImage, |
| | | type DetectionRun, |
| | | type TrajectoryRun, |
| | | type TrajectorySummary, |
| | | type TrajectoryEvent |
| | | } from "@/api/artifacts"; |
| | | |
| | | interface ArtifactState { |
| | | detectionRun: DetectionRun | null; |
| | | detectionImages: DetectionImage[]; |
| | | trajectoryRun: TrajectoryRun | null; |
| | | trajectoryCases: Record<string, { events: TrajectoryEvent[]; summary: TrajectorySummary[] }>; |
| | | loading: boolean; |
| | | error: string | null; |
| | | } |
| | | |
| | | interface ArtifactState { detectionCases: Record<string, DetectionCase>; trajectoryCases: Record<string, TrajectoryCase>; loading: boolean; error: string | null; } |
| | | export const useArtifactStore = defineStore("artifacts", { |
| | | state: (): ArtifactState => ({ |
| | | detectionRun: null, |
| | | detectionImages: [], |
| | | trajectoryRun: null, |
| | | trajectoryCases: {}, |
| | | loading: false, |
| | | error: null |
| | | }), |
| | | getters: { |
| | | detectionRun: (state) => Object.values(state.detectionCases)[0]?.run ?? null, |
| | | detectionImages: (state) => Object.values(state.detectionCases)[0]?.images ?? [] |
| | | }, |
| | | state: (): ArtifactState => ({ detectionCases: {}, trajectoryCases: {}, loading: false, error: null }), |
| | | actions: { |
| | | async loadDetection() { |
| | | if (this.detectionRun) return; |
| | | this.loading = true; |
| | | this.error = null; |
| | | try { |
| | | const result = await loadDetectionArtifacts(); |
| | | this.detectionRun = result.run; |
| | | this.detectionImages = result.images; |
| | | } catch (error) { |
| | | this.error = error instanceof Error ? error.message : "目标检测结果读取失败"; |
| | | } finally { |
| | | this.loading = false; |
| | | } |
| | | }, |
| | | async loadTrajectory() { |
| | | if (this.trajectoryRun) return; |
| | | this.loading = true; |
| | | this.error = null; |
| | | try { |
| | | const result = await loadTrajectoryArtifacts(); |
| | | this.trajectoryRun = result.run; |
| | | this.trajectoryCases = result.cases; |
| | | } catch (error) { |
| | | this.error = error instanceof Error ? error.message : "轨迹分析结果读取失败"; |
| | | } finally { |
| | | this.loading = false; |
| | | } |
| | | } |
| | | async loadDetection(force = false) { if (!force && Object.keys(this.detectionCases).length) return; this.loading = true; this.error = null; try { this.detectionCases = await loadDetectionArtifacts(); } catch (error) { this.error = error instanceof Error ? error.message : "目标检测结果读取失败"; } finally { this.loading = false; } }, |
| | | async loadTrajectory(force = false) { if (!force && Object.keys(this.trajectoryCases).length) return; this.loading = true; this.error = null; try { this.trajectoryCases = await loadTrajectoryArtifacts(); } catch (error) { this.error = error instanceof Error ? error.message : "轨迹分析结果读取失败"; } finally { this.loading = false; } } |
| | | } |
| | | }); |