points.ts 1.07 KB
/**
 * 权限点(permission point):以 `资源:动作` 表达的扁平字符串。
 *  - 页面级用裸资源(= view 可见),如 'store.approve'
 *  - 完全操作权用 ':manage',如 'store.approve:manage'
 *  - 按钮/操作级用具体动作,如 'store.approve:audit' / 'store.approve:reject'
 * 后端返回的权限集合只要包含这些点,前端即可据此显隐。
 */
export type PermissionPoint = string;

export const P = {
  // 门店审批
  STORE_APPROVE: 'store.approve',
  STORE_APPROVE_VIEW: 'store.approve:view',
  STORE_APPROVE_MANAGE: 'store.approve:manage',
  STORE_APPROVE_AUDIT: 'store.approve:audit',
  STORE_APPROVE_REJECT: 'store.approve:reject',
  // 门店列表
  STORE_LISTING: 'store.listing',
  STORE_LISTING_EXPORT: 'store.listing:export',
  STORE_LISTING_DELETE: 'store.listing:delete',
  // 复用片段
  VIEW: ':view',
  MANAGE: ':manage',
} as const;

/** 便捷构造:point('store.approve', 'audit') => 'store.approve:audit' */
export function point(resource: string, action: string): string {
  return `${resource}:${action}`;
}