重构Salon后台单管理员与经营驾驶舱
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { permissionApi } from '@/api/permission'
|
||||
import { computed, ref } from 'vue'
|
||||
import { isBootstrapAdminUser, loadCachedAdminUserInfo } from '@/utils/admin-session'
|
||||
import { isAllowedForShoplessPlatformAdmin } from '@/utils/platform-admin-permissions'
|
||||
import { loadCachedAdminUserInfo } from '@/utils/admin-session'
|
||||
|
||||
/**
|
||||
* Purpose: USER_PERMISSIONS_STORAGE_KEY supports permission.ts by holding or executing the user permissions storage key page or API role.
|
||||
@@ -76,6 +75,9 @@ export const clearStoredPermissions = () => {
|
||||
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
export const fetchUserPermissionsStrict = async () => {
|
||||
if (isPlatformAdminUser()) {
|
||||
return setStoredUserPermissions([])
|
||||
}
|
||||
loadingPermissions.value = true
|
||||
try {
|
||||
const permissions = await permissionApi.getUserPermissions()
|
||||
@@ -95,32 +97,17 @@ export const fetchUserPermissionsStrict = async () => {
|
||||
*/
|
||||
export const usePermission = () => {
|
||||
const hasPermission = (permissionCode: string) => {
|
||||
if (isBootstrapAdminUser(loadCachedAdminUserInfo())) {
|
||||
return isAllowedForShoplessPlatformAdmin(permissionCode)
|
||||
}
|
||||
if (isPlatformAdminUser() && isAllowedForShoplessPlatformAdmin(permissionCode)) {
|
||||
return isAllowedForShoplessPlatformAdmin(permissionCode)
|
||||
}
|
||||
if (isPlatformAdminUser()) return true
|
||||
return userPermissions.value.includes(permissionCode)
|
||||
}
|
||||
|
||||
const hasAnyPermission = (permissionCodes: string[]) => {
|
||||
if (isBootstrapAdminUser(loadCachedAdminUserInfo())) {
|
||||
return permissionCodes.some(isAllowedForShoplessPlatformAdmin)
|
||||
}
|
||||
if (isPlatformAdminUser() && permissionCodes.some(isAllowedForShoplessPlatformAdmin)) {
|
||||
return permissionCodes.some(isAllowedForShoplessPlatformAdmin)
|
||||
}
|
||||
if (isPlatformAdminUser()) return true
|
||||
return permissionCodes.some(code => userPermissions.value.includes(code))
|
||||
}
|
||||
|
||||
const hasAllPermissions = (permissionCodes: string[]) => {
|
||||
if (isBootstrapAdminUser(loadCachedAdminUserInfo())) {
|
||||
return permissionCodes.every(isAllowedForShoplessPlatformAdmin)
|
||||
}
|
||||
if (isPlatformAdminUser() && permissionCodes.every(isAllowedForShoplessPlatformAdmin)) {
|
||||
return permissionCodes.every(isAllowedForShoplessPlatformAdmin)
|
||||
}
|
||||
if (isPlatformAdminUser()) return true
|
||||
return permissionCodes.every(code => userPermissions.value.includes(code))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user