Browse Source

[Feat 0000] 新增模型文件信息Store

houzekong 2 days ago
parent
commit
7f919a175f
2 changed files with 49 additions and 0 deletions
  1. 11 0
      src/api/sys/modelFile.ts
  2. 38 0
      src/store/modules/modelFile.ts

+ 11 - 0
src/api/sys/modelFile.ts

@@ -0,0 +1,11 @@
+import { defHttp } from '/@/utils/http/axios';
+
+enum Api {
+  getAllModelFileJson = '/ventanaly-device/safety/modelAlarmInfo/getAllModelFileJson',
+}
+
+export const getAllModelFileJsonApi = () => {
+  return defHttp.get<Record<string, { fileName: string; filePath: string }[]>>({
+    url: Api.getAllModelFileJson,
+  });
+};

+ 38 - 0
src/store/modules/modelFile.ts

@@ -0,0 +1,38 @@
+import { defineStore } from 'pinia';
+import { getAllModelFileJsonApi } from '/@/api/sys/modelFile';
+
+interface ModelFileItem {
+  fileName: string;
+  filePath: string;
+}
+
+export const useModelFileStore = defineStore({
+  id: 'app-model-file',
+  state: () => ({
+    modelFileData: null as Record<string, ModelFileItem[]> | null,
+  }),
+  getters: {
+    getModelFileDataByKey(): (key: string) => ModelFileItem[] {
+      return (key: string) => {
+        if (!this.modelFileData || !this.modelFileData[key]) return [];
+        return this.modelFileData[key];
+      };
+    },
+    getAllModelFileData(): Record<string, ModelFileItem[]> | null {
+      return this.modelFileData;
+    },
+  },
+  actions: {
+    async fetchModelFileData() {
+      const raw = await getAllModelFileJsonApi();
+      const processed: Record<string, ModelFileItem[]> = {};
+      for (const [key, items] of Object.entries(raw)) {
+        processed[key] = items.map((item) => ({
+          fileName: item.fileName.replace(/\.[^.]+$/, ''),
+          filePath: item.filePath.replace(/^\/data\/file/, ''),
+        }));
+      }
+      this.modelFileData = processed;
+    },
+  },
+});