points.ts 1.4 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:view',
  STORE_APPROVE_VIEW: 'store:approve:view',
  STORE_APPROVE_MANAGE: 'store.approve:manage',
  STORE_APPROVE_AUDIT: 'store:approve:pass',
  STORE_APPROVE_REJECT: 'store:approve:reject',
  // 门店列表
  STORE_LISTING: 'store:list:view',
  STORE_LISTING_VIEW: 'store:list:view',
  STORE_LISTING_EXPORT: 'store:list:export',
  STORE_LISTING_DELETE: 'store.listing:delete',
  /** 角色管理
   * system:role:view	- 查看角色详情
   * system:role:save	- 新增/编辑/删除角色
   */
  SYSTEM_ROLE_VIEW: 'system:role:view',
  SYSTEM_ROLE_SAVE: 'system:role:save',
  /** 账号管理 */
  SYSTEM_USER_VIEW: 'system:user:view',
  SYSTEM_USER_SAVE: 'system:user:save',
  // 复用片段
  VIEW: ':view',
  MANAGE: ':manage',
} as const;

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