刘光辉
9 小时以前 0dfe84494048ce27ba8449831782128412d3eb13
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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'
  );
}