shuishen
13 hours ago 2ae460fc4a4c2419cf44329783d49a739e2a04ea
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { defineStore } from "pinia";
 
import {
  loadDetectionArtifacts,
  loadChangeArtifacts,
  loadSemanticArtifacts,
  loadMeasurementArtifacts,
  loadTrajectoryArtifacts,
  loadAnomalyArtifacts,
  type DetectionCase,
  type ChangeCase,
  type SemanticCase,
  type MeasurementCase,
  type TrajectoryCase,
  type AnomalyCase
} from "@/api/artifacts";
 
interface ArtifactState {
  detectionCases: Record<string, DetectionCase>;
  trajectoryCases: Record<string, TrajectoryCase>;
  semanticCases: Record<string, SemanticCase>;
  measurementCases: Record<string, MeasurementCase>;
  changeCases: Record<string, ChangeCase>;
  anomalyCases: Record<string, AnomalyCase>;
  loading: boolean;
  error: string | null;
}
 
export const useArtifactStore = defineStore("artifacts", {
  getters: {
    detectionRun: (state) => Object.values(state.detectionCases)[0]?.run ?? null,
    detectionImages: (state) => Object.values(state.detectionCases)[0]?.images ?? []
  },
  state: (): ArtifactState => ({ detectionCases: {}, trajectoryCases: {}, semanticCases: {}, measurementCases: {}, changeCases: {}, anomalyCases: {}, loading: false, error: null }),
  actions: {
    async loadChange(force = false) {
      if (!force && Object.keys(this.changeCases).length) return;
      this.loading = true; this.error = null;
      try { this.changeCases = await loadChangeArtifacts(); }
      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; }
    },
    async loadSemantic(force = false) {
      if (!force && Object.keys(this.semanticCases).length) return;
      this.loading = true; this.error = null;
      try { this.semanticCases = await loadSemanticArtifacts(); }
      catch (error) { this.error = error instanceof Error ? error.message : "语义分割结果读取失败"; }
      finally { this.loading = false; }
    },
    async loadMeasurement(force = false) {
      if (!force && Object.keys(this.measurementCases).length) return;
      this.loading = true; this.error = null;
      try { this.measurementCases = await loadMeasurementArtifacts(); }
      catch (error) { this.error = error instanceof Error ? error.message : "空间测量结果读取失败"; }
      finally { this.loading = false; }
    },
    async loadAnomaly(force = false) {
      if (!force && Object.keys(this.anomalyCases).length) return;
      this.loading = true; this.error = null;
      try { this.anomalyCases = await loadAnomalyArtifacts(); }
      catch (error) { this.error = error instanceof Error ? error.message : "异常检测结果读取失败"; }
      finally { this.loading = false; }
    }
  }
});