import type { DmsAction, DmsPrincipalType, DmsResourceScope, DmsResourceType } from '#/api/x/dms/permission';
|
|
export const actionOptions: Array<{ label: string; value: DmsAction }> = [
|
{ label: '创建', value: 'CREATE' },
|
{ label: '读取', value: 'READ' },
|
{ label: '更新', value: 'UPDATE' },
|
{ label: '删除', value: 'DELETE' },
|
];
|
|
export const scopeOptions: Array<{ label: string; value: DmsResourceScope }> = [
|
{ label: '当前资源', value: 'SELF' },
|
{ label: '全部后代', value: 'SUBTREE' },
|
];
|
|
export function actionsForResource(resourceType: DmsResourceType) {
|
return actionOptions.filter((option) => resourceType === 'FOLDER' || option.value !== 'CREATE');
|
}
|
|
export function scopesForResource(resourceType: DmsResourceType) {
|
return scopeOptions.filter((option) => resourceType === 'FOLDER' || option.value === 'SELF');
|
}
|
|
export function canExcludeRead(resourceType: DmsResourceType) {
|
return resourceType === 'DOCUMENT' || resourceType === 'FILE_VERSION';
|
}
|
|
export function normalizePrincipalId(value: string) {
|
return value.replace(/--(?:org|subOrg|progenyOrg|pos|subPos|progenyPos)$/i, '');
|
}
|
|
export function principalDisplayName(name: string | undefined, id: string) {
|
return name?.trim() || id;
|
}
|
|
export function principalDisplayTitle(name: string | undefined, id: string) {
|
const normalizedName = name?.trim();
|
return normalizedName ? `${normalizedName}(ID:${id})` : `ID:${id}`;
|
}
|
|
export function principalSearchValue(name: string | undefined, id: string) {
|
return `${name?.trim() || ''} ${id}`;
|
}
|
|
export function actionLabel(action: DmsAction) {
|
return actionOptions.find((option) => option.value === action)?.label || action;
|
}
|
|
export function scopeLabel(scope: DmsResourceScope) {
|
return scopeOptions.find((option) => option.value === scope)?.label || scope;
|
}
|
|
export function principalTypeLabel(type: DmsPrincipalType) {
|
return {
|
GROUP: '权限组',
|
ORG: '组织',
|
POSITION: '岗位',
|
ROLE: '角色',
|
USER: '用户',
|
}[type];
|
}
|
|
export function statusLabel(status: string) {
|
return (
|
{
|
ACTIVE: '生效中',
|
EXHAUSTED: '次数已用尽',
|
EXPIRED: '已过期',
|
PENDING: '待生效',
|
REVOKED: '已撤销',
|
}[status] || status
|
);
|
}
|
|
export function statusColor(status: string) {
|
return (
|
{
|
ACTIVE: 'success',
|
EXHAUSTED: 'warning',
|
EXPIRED: 'default',
|
PENDING: 'processing',
|
REVOKED: 'error',
|
}[status] || 'default'
|
);
|
}
|