Step F2:项目列表 & 当前项目上下文

This commit is contained in:
Cheng Zhou
2025-12-16 20:31:20 +08:00
parent 78d13d077c
commit cc54d80b3a
19 changed files with 239 additions and 24 deletions
+37
View File
@@ -0,0 +1,37 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import type { Study } from "../types/api";
const STUDY_KEY = "ctms_current_study";
export const useStudyStore = defineStore("study", () => {
const currentStudy = ref<Study | null>(null);
const setCurrentStudy = (study: Study) => {
currentStudy.value = study;
localStorage.setItem(STUDY_KEY, JSON.stringify(study));
};
const loadCurrentStudy = () => {
const raw = localStorage.getItem(STUDY_KEY);
if (raw) {
try {
currentStudy.value = JSON.parse(raw) as Study;
} catch {
currentStudy.value = null;
}
}
};
const clearCurrentStudy = () => {
currentStudy.value = null;
localStorage.removeItem(STUDY_KEY);
};
return {
currentStudy,
setCurrentStudy,
loadCurrentStudy,
clearCurrentStudy,
};
});