shuishen
5 days ago f67d43a43f6c3e58922e3c2f457dd9caafebfc67
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { defineStore } from "pinia";
 
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;
}
 
export const useArtifactStore = defineStore("artifacts", {
  state: (): ArtifactState => ({
    detectionRun: null,
    detectionImages: [],
    trajectoryRun: null,
    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;
      }
    }
  }
});