审计日志并入系统管理、规范项目成员获取逻辑
This commit is contained in:
@@ -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,
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user