Step F2:项目列表 & 当前项目上下文
This commit is contained in:
@@ -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,
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user