feat(shared): 扩展权限系统相关类型定义

添加菜单、角色、权限相关的类型和接口定义,支持前后端共享。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
charilezhou
2026-01-17 14:04:49 +08:00
parent c2d9aaedc9
commit ffb16efa62
2 changed files with 272 additions and 0 deletions

View File

@@ -174,3 +174,33 @@ export interface HealthCheckResponse {
/** 各服务健康状态 */
services: ServicesHealth;
}
// ==================== 权限管理相关类型 ====================
export {
// 枚举常量
MenuType,
SystemRoleCode,
PermissionAction,
// 角色类型
type RoleResponse,
type RoleDetailResponse,
type CreateRoleDto,
type UpdateRoleDto,
// 权限类型
type PermissionResponse,
type CreatePermissionDto,
type UpdatePermissionDto,
// 菜单类型
type MenuMeta,
type MenuResponse,
type MenuTreeNode,
type CreateMenuDto,
type UpdateMenuDto,
// 用户权限类型
type AssignRolesDto,
type AuthUserWithPermissions,
type UserMenusAndPermissionsResponse,
type UserRoleResponse,
type UserWithRolesResponse,
} from './permission';

View File

@@ -0,0 +1,242 @@
// ==================== 权限管理类型定义 ====================
// ==================== 枚举常量 ====================
/** 菜单类型 */
export const MenuType = {
/** 目录 */
DIR: 'dir',
/** 菜单 */
MENU: 'menu',
/** 按钮 */
BUTTON: 'button',
} as const;
export type MenuType = (typeof MenuType)[keyof typeof MenuType];
/** 系统内置角色编码 */
export const SystemRoleCode = {
/** 超级管理员 */
SUPER_ADMIN: 'super_admin',
/** 管理员 */
ADMIN: 'admin',
/** 普通用户 */
USER: 'user',
} as const;
export type SystemRoleCode = (typeof SystemRoleCode)[keyof typeof SystemRoleCode];
/** 权限操作类型 */
export const PermissionAction = {
/** 创建 */
CREATE: 'create',
/** 读取 */
READ: 'read',
/** 更新 */
UPDATE: 'update',
/** 删除 */
DELETE: 'delete',
} as const;
export type PermissionAction = (typeof PermissionAction)[keyof typeof PermissionAction];
// ==================== 角色相关类型 ====================
/** 角色响应 */
export interface RoleResponse {
id: string;
code: string;
name: string;
description: string | null;
isSystem: boolean;
isEnabled: boolean;
sort: number;
createdAt: string;
updatedAt: string;
}
/** 角色详情响应(包含权限和菜单) */
export interface RoleDetailResponse extends RoleResponse {
permissions: PermissionResponse[];
menus: MenuResponse[];
}
/** 创建角色请求 */
export interface CreateRoleDto {
code: string;
name: string;
description?: string;
isEnabled?: boolean;
sort?: number;
permissionIds?: string[];
menuIds?: string[];
}
/** 更新角色请求 */
export interface UpdateRoleDto {
name?: string;
description?: string;
isEnabled?: boolean;
sort?: number;
permissionIds?: string[];
menuIds?: string[];
}
// ==================== 权限相关类型 ====================
/** 权限响应 */
export interface PermissionResponse {
id: string;
code: string;
name: string;
description: string | null;
resource: string;
action: string;
isEnabled: boolean;
createdAt: string;
updatedAt: string;
}
/** 创建权限请求 */
export interface CreatePermissionDto {
code: string;
name: string;
description?: string;
resource: string;
action: string;
isEnabled?: boolean;
}
/** 更新权限请求 */
export interface UpdatePermissionDto {
name?: string;
description?: string;
isEnabled?: boolean;
}
// ==================== 菜单相关类型 ====================
/** 菜单元<E58D95><E58583>据 */
export interface MenuMeta {
/** 是否缓存组件 */
keepAlive?: boolean;
/** 是否固定标签页 */
affix?: boolean;
/** 其他自定义属性 */
[key: string]: unknown;
}
/** 菜单响应 */
export interface MenuResponse {
id: string;
parentId: string | null;
code: string;
name: string;
type: MenuType;
path: string | null;
icon: string | null;
component: string | null;
permission: string | null;
isExternal: boolean;
isHidden: boolean;
isEnabled: boolean;
isStatic: boolean;
sort: number;
meta: MenuMeta | null;
createdAt: string;
updatedAt: string;
}
/** 菜单树节点(用于前端渲染) */
export interface MenuTreeNode {
id: string;
parentId: string | null;
code: string;
name: string;
type: MenuType;
path: string | null;
icon: string | null;
permission: string | null;
isHidden: boolean;
meta: MenuMeta | null;
children?: MenuTreeNode[];
}
/** 创建菜单请求 */
export interface CreateMenuDto {
parentId?: string;
code: string;
name: string;
type?: MenuType;
path?: string;
icon?: string;
component?: string;
permission?: string;
isExternal?: boolean;
isHidden?: boolean;
isEnabled?: boolean;
isStatic?: boolean;
sort?: number;
meta?: MenuMeta;
}
/** 更新菜单请求 */
export interface UpdateMenuDto {
parentId?: string | null;
name?: string;
type?: MenuType;
path?: string;
icon?: string;
component?: string;
permission?: string;
isExternal?: boolean;
isHidden?: boolean;
isEnabled?: boolean;
sort?: number;
meta?: MenuMeta;
}
// ==================== 用户权限相关类型 ====================
/** 用户角色分配请求 */
export interface AssignRolesDto {
roleIds: string[];
}
/** 带权限信息的认证用户 */
export interface AuthUserWithPermissions {
id: string;
email: string;
name: string | null;
isSuperAdmin: boolean;
roles: string[];
roleIds: string[];
permissions: string[];
}
/** 用户菜单和权限响应 */
export interface UserMenusAndPermissionsResponse {
/** 用户可访问的菜单树 */
menus: MenuTreeNode[];
/** 用户拥有的权限编码列表 */
permissions: string[];
/** 是否为超级管理员 */
isSuperAdmin: boolean;
}
// ==================== 用户角色响应类型 ====================
/** 用户角色信息 */
export interface UserRoleResponse {
id: string;
code: string;
name: string;
}
/** 用户详情(包含角色) */
export interface UserWithRolesResponse {
id: string;
email: string;
name: string | null;
isSuperAdmin: boolean;
roles: UserRoleResponse[];
createdAt: string;
updatedAt: string;
}