审计日志并入系统管理、规范项目成员获取逻辑

This commit is contained in:
Cheng Zhou
2025-12-26 14:57:57 +08:00
parent 7c9befc3c9
commit 71db309e12
17 changed files with 94 additions and 116 deletions
+17
View File
@@ -1,5 +1,6 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import { fetchStudies } from "../api/studies";
import type { Study } from "../types/api";
const STUDY_KEY = "ctms_current_study";
@@ -32,6 +33,21 @@ export const useStudyStore = defineStore("study", () => {
currentStudyRole.value = savedRole || null;
};
const ensureDefaultStudy = async () => {
if (currentStudy.value) return currentStudy.value;
try {
const { data } = await fetchStudies();
const items = (data as any).items || [];
if (items.length) {
setCurrentStudy(items[0] as Study);
return items[0] as Study;
}
} catch {
return null;
}
return null;
};
const clearCurrentStudy = () => {
currentStudy.value = null;
currentStudyRole.value = null;
@@ -54,6 +70,7 @@ export const useStudyStore = defineStore("study", () => {
setCurrentStudy,
setCurrentStudyRole,
loadCurrentStudy,
ensureDefaultStudy,
clearCurrentStudy,
};
});