更新
This commit is contained in:
@@ -2,7 +2,8 @@ import { createPinia } from 'pinia'
|
||||
import { useAppStore } from '@/pinia/modules/app'
|
||||
import { useUserStore } from '@/pinia/modules/user'
|
||||
import { useDictionaryStore } from '@/pinia/modules/dictionary'
|
||||
import { useProjectStore } from '@/pinia/modules/project'
|
||||
|
||||
const store = createPinia()
|
||||
|
||||
export { store, useAppStore, useUserStore, useDictionaryStore }
|
||||
export { store, useAppStore, useUserStore, useDictionaryStore, useProjectStore }
|
||||
|
||||
26
src/pinia/modules/project.js
Normal file
26
src/pinia/modules/project.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
const PROJECT_STORAGE_KEY = 'masterStation_current_project_id'
|
||||
|
||||
export const useProjectStore = defineStore('project', () => {
|
||||
const currentProject = ref(null)
|
||||
|
||||
const setCurrentProject = (project) => {
|
||||
currentProject.value = project || null
|
||||
if (project?.id) {
|
||||
localStorage.setItem(PROJECT_STORAGE_KEY, String(project.id))
|
||||
}
|
||||
}
|
||||
|
||||
const getSavedProjectId = () => {
|
||||
const savedId = Number(localStorage.getItem(PROJECT_STORAGE_KEY))
|
||||
return savedId || null
|
||||
}
|
||||
|
||||
return {
|
||||
currentProject,
|
||||
setCurrentProject,
|
||||
getSavedProjectId
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user