权限相关调整
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
import { computed } from "vue";
|
||||
import { useAuthStore } from "@/stores/modules/auth";
|
||||
import { useUserStore } from "@/stores/modules/user";
|
||||
|
||||
export interface OnboardingOwnedRecord {
|
||||
createUserId?: number | string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 入职业务页面统一权限判断:按钮权限控制功能入口,创建人/管理全部权限控制数据操作范围。
|
||||
*/
|
||||
export function useOnboardingPermission(manageAllCode: string) {
|
||||
const authStore = useAuthStore();
|
||||
const userStore = useUserStore();
|
||||
|
||||
const isSuperAdmin = computed(() =>
|
||||
(userStore.userInfoGet?.roleCodeList || []).includes("superAdmin")
|
||||
);
|
||||
const canManageAll = computed(
|
||||
() =>
|
||||
isSuperAdmin.value ||
|
||||
authStore.authButtonListGet.includes(manageAllCode)
|
||||
);
|
||||
|
||||
const hasAction = (code: string) =>
|
||||
isSuperAdmin.value || authStore.authButtonListGet.includes(code);
|
||||
|
||||
const canManage = (record?: OnboardingOwnedRecord | null) => {
|
||||
if (canManageAll.value) return true;
|
||||
if (record?.createUserId == null || userStore.userInfoGet?.id == null)
|
||||
return false;
|
||||
return String(record.createUserId) === String(userStore.userInfoGet.id);
|
||||
};
|
||||
|
||||
const disabledReason = (record?: OnboardingOwnedRecord | null) =>
|
||||
canManage(record) ? "" : "只能操作本人创建的数据";
|
||||
|
||||
return {
|
||||
isSuperAdmin,
|
||||
canManageAll,
|
||||
hasAction,
|
||||
canManage,
|
||||
disabledReason
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user