Files
boursecu_admin/src/store/userStore.ts
T

50 lines
1.4 KiB
TypeScript
Raw Normal View History

2026-01-24 17:45:54 +03:30
import { type ComputedRef, ref } from 'vue'
import type { User } from '@/model/user'
import { getMyInformation } from '@/api/user'
import { get } from 'lodash'
2026-06-21 20:27:13 +03:30
import { isDeployAdmin } from '@/utils/deployAdmin'
2026-07-04 14:21:27 +03:30
import { hasSmsPanelAccess, isSmsBillingEnabled } from '@/utils/smsPanelAccess'
2026-01-24 17:45:54 +03:30
export const useUserStore = defineStore('user', () => {
const userInfo = ref<User | undefined>(undefined)
async function getMyInfo() {
try {
userInfo.value = await getMyInformation()
return userInfo.value
} catch (e) {
console.log(e)
}
}
const permissions: ComputedRef<string[]> = computed(() => {
const permissions: string[] = get(userInfo.value, 'permission', [])
const excludes: string[] = get(userInfo.value, 'exclude', [])
return permissions.filter((item) => !excludes.includes(item))
})
function canAccess(permissionKey: string) {
if (isAdmin.value) return true
return permissions.value.includes(permissionKey)
}
const isAdmin = computed(() => {
return userInfo.value?.is_admin
})
2026-06-21 20:27:13 +03:30
const isDeployAdminUser = computed(() => isDeployAdmin(userInfo.value?.mobile))
2026-07-04 14:21:27 +03:30
const smsPanelAccess = computed(() => hasSmsPanelAccess(userInfo.value))
const smsBillingEnabled = computed(() => isSmsBillingEnabled(userInfo.value))
return {
userInfo,
getMyInfo,
permissions,
canAccess,
isAdmin,
isDeployAdminUser,
smsPanelAccess,
smsBillingEnabled
}
2026-01-24 17:45:54 +03:30
})