first commit
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { computed, ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
import { tokenService } from '@/services/api/token-service'
|
||||
|
||||
export const useAuthStore = defineStore('auth', () => {
|
||||
const user = ref(tokenService.getUserInfo())
|
||||
|
||||
const isAuthenticated = computed(() => !!tokenService.getToken() && !!user.value)
|
||||
const role = computed(() => user.value?.role || user.value?.roleName || null)
|
||||
|
||||
const setUser = (userData) => {
|
||||
user.value = userData
|
||||
tokenService.saveUserInfo(userData)
|
||||
}
|
||||
|
||||
const clearUser = () => {
|
||||
user.value = null
|
||||
tokenService.clearAll()
|
||||
}
|
||||
|
||||
return {
|
||||
user,
|
||||
role,
|
||||
isAuthenticated,
|
||||
setUser,
|
||||
clearUser,
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,33 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
export const useModalStore = defineStore('modal', () => {
|
||||
const modals = ref([])
|
||||
|
||||
const isModal = (name) => modals.value.some((x) => x.name === name)
|
||||
const getModal = (name) => modals.value.find((x) => x.name === name)
|
||||
const getActiveModal = computed(() => modals.value.at(-1))
|
||||
|
||||
const openModal = (name, data) => {
|
||||
if (!modals.value.some((x) => x.name === name)) {
|
||||
modals.value.push({ name, data })
|
||||
}
|
||||
}
|
||||
|
||||
const closeModal = (name) => {
|
||||
if (name) {
|
||||
modals.value = modals.value.filter((x) => x.name !== name)
|
||||
} else if (modals.value.length > 0) {
|
||||
modals.value.pop()
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
modals,
|
||||
getActiveModal,
|
||||
isModal,
|
||||
getModal,
|
||||
openModal,
|
||||
closeModal,
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,27 @@
|
||||
import { ref } from 'vue'
|
||||
import { defineStore } from 'pinia'
|
||||
|
||||
export const useUIStore = defineStore('ui', () => {
|
||||
const isSidebarOpen = ref(false)
|
||||
const pageTitle = ref('')
|
||||
|
||||
const toggleSidebar = () => {
|
||||
isSidebarOpen.value = !isSidebarOpen.value
|
||||
}
|
||||
|
||||
const setSidebarState = (open) => {
|
||||
isSidebarOpen.value = open
|
||||
}
|
||||
|
||||
const setPageTitle = (title) => {
|
||||
pageTitle.value = title
|
||||
}
|
||||
|
||||
return {
|
||||
isSidebarOpen,
|
||||
pageTitle,
|
||||
toggleSidebar,
|
||||
setSidebarState,
|
||||
setPageTitle,
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user