UX-2(操作级权限控制)

This commit is contained in:
Cheng Zhou
2025-12-17 15:11:02 +08:00
parent dd51f56707
commit 9ca30d12f8
29 changed files with 288 additions and 131 deletions
+22
View File
@@ -3,13 +3,20 @@ import { ref } from "vue";
import type { Study } from "../types/api";
const STUDY_KEY = "ctms_current_study";
const STUDY_ROLE_KEY = "ctms_current_study_role";
export const useStudyStore = defineStore("study", () => {
const currentStudy = ref<Study | null>(null);
const currentStudyRole = ref<string | null>(null);
const setCurrentStudy = (study: Study) => {
currentStudy.value = study;
const role = (study as any).role_in_study || (study as any).role || null;
currentStudyRole.value = role;
localStorage.setItem(STUDY_KEY, JSON.stringify(study));
if (role) {
localStorage.setItem(STUDY_ROLE_KEY, role);
}
};
const loadCurrentStudy = () => {
@@ -21,16 +28,31 @@ export const useStudyStore = defineStore("study", () => {
currentStudy.value = null;
}
}
const savedRole = localStorage.getItem(STUDY_ROLE_KEY);
currentStudyRole.value = savedRole || null;
};
const clearCurrentStudy = () => {
currentStudy.value = null;
currentStudyRole.value = null;
localStorage.removeItem(STUDY_KEY);
localStorage.removeItem(STUDY_ROLE_KEY);
};
const setCurrentStudyRole = (role: string | null) => {
currentStudyRole.value = role;
if (role) {
localStorage.setItem(STUDY_ROLE_KEY, role);
} else {
localStorage.removeItem(STUDY_ROLE_KEY);
}
};
return {
currentStudy,
currentStudyRole,
setCurrentStudy,
setCurrentStudyRole,
loadCurrentStudy,
clearCurrentStudy,
};