未知(继上次中断)

This commit is contained in:
Cheng Zhou
2026-02-04 10:52:34 +08:00
parent 8e258d21a7
commit 737f84bf54
99 changed files with 5497 additions and 2143 deletions
+35
View File
@@ -5,12 +5,18 @@ import type { Study } from "../types/api";
const STUDY_KEY = "ctms_current_study";
const STUDY_ROLE_KEY = "ctms_current_study_role";
const SITE_KEY = "ctms_current_site";
export const useStudyStore = defineStore("study", () => {
const currentStudy = ref<Study | null>(null);
const currentStudyRole = ref<string | null>(null);
const currentSite = ref<any | null>(null);
const viewContext = ref<{ siteName?: string } | null>(null);
const setCurrentStudy = (study: Study) => {
currentStudy.value = study;
currentSite.value = null; // 切换项目时清空中心
localStorage.removeItem(SITE_KEY);
currentStudy.value = study;
const role = (study as any).role_in_study || (study as any).role || null;
currentStudyRole.value = role;
@@ -31,6 +37,15 @@ export const useStudyStore = defineStore("study", () => {
}
const savedRole = localStorage.getItem(STUDY_ROLE_KEY);
currentStudyRole.value = savedRole || null;
const savedSite = localStorage.getItem(SITE_KEY);
if (savedSite) {
try {
currentSite.value = JSON.parse(savedSite);
} catch {
currentSite.value = null;
}
}
};
const ensureDefaultStudy = async () => {
@@ -51,8 +66,11 @@ export const useStudyStore = defineStore("study", () => {
const clearCurrentStudy = () => {
currentStudy.value = null;
currentStudyRole.value = null;
currentSite.value = null;
viewContext.value = null;
localStorage.removeItem(STUDY_KEY);
localStorage.removeItem(STUDY_ROLE_KEY);
localStorage.removeItem(SITE_KEY);
};
const setCurrentStudyRole = (role: string | null) => {
@@ -64,11 +82,28 @@ export const useStudyStore = defineStore("study", () => {
}
};
const setCurrentSite = (site: any | null) => {
currentSite.value = site;
if (site) {
localStorage.setItem(SITE_KEY, JSON.stringify(site));
} else {
localStorage.removeItem(SITE_KEY);
}
};
const setViewContext = (ctx: { siteName?: string } | null) => {
viewContext.value = ctx;
};
return {
currentStudy,
currentStudyRole,
currentSite,
viewContext,
setCurrentStudy,
setCurrentStudyRole,
setCurrentSite,
setViewContext,
loadCurrentStudy,
ensureDefaultStudy,
clearCurrentStudy,