Обновлен стартовый экран
Переписаны запросы для статистики, отчетов Добавлена интеграция отчета сестры
This commit is contained in:
@@ -26,19 +26,30 @@ export const useAuthStore = defineStore('authStore', () => {
|
||||
|
||||
// Вычисляемые свойства
|
||||
const isAuthenticated = computed(() => !!user.value && !!token.value)
|
||||
const isAdmin = computed(() => role.value?.slug === 'admin')
|
||||
const isDoctor = computed(() => role.value?.slug === 'doctor')
|
||||
const isHeadOfDepartment = computed(() => role.value?.slug === 'head_of_department')
|
||||
const userDepartment = computed(() => user.value?.current_department || '')
|
||||
|
||||
// Проверка роли по слагу
|
||||
const hasRole = (slug) => role.value?.slug === slug
|
||||
const isAdmin = computed(() => hasRole('admin'))
|
||||
const isChiefDoctor = computed(() => hasRole('gv'))
|
||||
const isDeputyChief = computed(() => hasRole('zam'))
|
||||
const isHeadOfDepartment = computed(() => hasRole('zav'))
|
||||
const isDoctor = computed(() => hasRole('dej'))
|
||||
const isNurse = computed(() => hasRole('nurse'))
|
||||
const isSeniorStaff = computed(() => isAdmin.value || isChiefDoctor.value || isDeputyChief.value || isHeadOfDepartment.value)
|
||||
|
||||
// Проверка права (permissions — массив строк от Spatie)
|
||||
const hasPermission = (permission) => {
|
||||
return permissions.value?.includes(permission) ?? false
|
||||
}
|
||||
|
||||
const canAccessDepartment = (department) => {
|
||||
if (isSeniorStaff.value) return true
|
||||
return availableDepartments.value.includes(department)
|
||||
}
|
||||
|
||||
const clearAuthData = () => {
|
||||
user.value = null
|
||||
token.value = null
|
||||
permissions.value = {}
|
||||
availableDepartments.value = []
|
||||
|
||||
localStorage.removeItem('token')
|
||||
localStorage.removeItem('user')
|
||||
delete axios.defaults.headers.common['Authorization']
|
||||
}
|
||||
|
||||
@@ -52,16 +63,6 @@ export const useAuthStore = defineStore('authStore', () => {
|
||||
}
|
||||
}
|
||||
|
||||
// Проверка прав
|
||||
const hasPermission = (permission) => {
|
||||
return permissions.value[permission] === true
|
||||
}
|
||||
|
||||
const canAccessDepartment = (department) => {
|
||||
if (isAdmin.value || isHeadOfDepartment.value) return true
|
||||
return availableDepartments.value.includes(department)
|
||||
}
|
||||
|
||||
return {
|
||||
user,
|
||||
token,
|
||||
@@ -70,12 +71,18 @@ export const useAuthStore = defineStore('authStore', () => {
|
||||
availableRoles,
|
||||
isAuthenticated,
|
||||
isAdmin,
|
||||
isDoctor,
|
||||
isChiefDoctor,
|
||||
isDeputyChief,
|
||||
isHeadOfDepartment,
|
||||
isDoctor,
|
||||
isNurse,
|
||||
isSeniorStaff,
|
||||
userDepartment,
|
||||
|
||||
clearAuthData,
|
||||
hasRole,
|
||||
hasPermission,
|
||||
canAccessDepartment
|
||||
canAccessDepartment,
|
||||
clearAuthData,
|
||||
logout,
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user