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)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-30 18:30:32 +03:30
|
|
|
function findSettingByKey(key: string) {
|
|
|
|
|
return userInfo.value?.settings?.find((setting: any) => setting.key === key)?.value
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-24 17:45:54 +03:30
|
|
|
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,
|
2026-07-30 18:30:32 +03:30
|
|
|
findSettingByKey,
|
2026-07-04 14:21:27 +03:30
|
|
|
permissions,
|
|
|
|
|
canAccess,
|
|
|
|
|
isAdmin,
|
|
|
|
|
isDeployAdminUser,
|
|
|
|
|
smsPanelAccess,
|
|
|
|
|
smsBillingEnabled
|
|
|
|
|
}
|
2026-01-24 17:45:54 +03:30
|
|
|
})
|