/* eslint-disable max-lines-per-function -- 详情面板按头部/摘要/范围/特殊/绑定用户分区,集中便于对齐原型 */ import { Button } from '@douyinfe/semi-ui-19'; import type { PermissionTree, RoleDetail } from '@lingxi/shared'; import { ErrorState, PageEmpty, PageSkeleton } from '@lingxi/ui'; import { IconCopy, IconEdit, IconPause, IconPlay, IconShield, IconStar, IconView, } from '@lingxi/ui/icons'; import type { ReactNode } from 'react'; import { useState } from 'react'; import { buildPermissionMetaMap, formatRoleDateTime, permissionNameOf, scopeDescriptionOf, scopeLabelOf, summarizePermissionModules, } from './role-display'; import { RoleStatusTag } from './RoleStatusTag'; export interface RoleDetailPanelProps { roleId: string | null; detail: RoleDetail | undefined; tree: PermissionTree | undefined; loading: boolean; error: Error | null; canManage: boolean; onRetry: () => void; onEdit: (roleId: string) => void; onCopy: (role: RoleDetail) => void; onRename: (role: RoleDetail) => void; onDisable: (role: RoleDetail) => void; onEnable: (role: RoleDetail) => void; } function RoleAvatar({ status }: { status: 'active' | 'disabled' }): ReactNode { return ( ); } function DetailHead({ role, canManage, onEdit, onCopy, onRename, onDisable, onEnable, }: Pick< RoleDetailPanelProps, 'canManage' | 'onEdit' | 'onCopy' | 'onRename' | 'onDisable' | 'onEnable' > & { role: RoleDetail; }): ReactNode { return (

{role.name}

{role.isSystem ? 内置 : null}

{role.description}

{canManage ? ( <> {role.isSystem ? ( ) : role.status === 'active' ? ( ) : ( )} ) : null}
); } function PermissionSummary({ role, tree, }: { role: RoleDetail; tree: PermissionTree | undefined; }): ReactNode { const selected = [...role.permissions, ...role.specialPermissions]; const modules = tree === undefined ? [] : summarizePermissionModules(tree, selected); return (

权限点摘要

已选 {role.permissionCount + role.specialPermissionCount} /{' '} {tree?.totalPermissions ?? '—'}
{modules.length === 0 ? (

权限点目录加载中…

) : (
{modules.map((module) => (
{module.moduleLabel} {module.selected} / {module.total}
))}
)}
); } function ScopeAndSpecial({ role, tree, }: { role: RoleDetail; tree: PermissionTree | undefined; }): ReactNode { const meta = tree === undefined ? undefined : buildPermissionMetaMap(tree); return (

数据范围

{scopeLabelOf(role.dataScope.type)} {scopeDescriptionOf(role.dataScope.type)}

{role.dataScope.type === 'customer_groups' ? (

{(role.dataScope.targetIds ?? []).length === 0 ? '暂未指定客户组,客户组将在客户模块上线后可选择。' : `已指定 ${String((role.dataScope.targetIds ?? []).length)} 个客户组,客户组名称将在客户模块上线后展示。`}

) : null}

特殊权限

{role.specialPermissions.length} / 6
{role.specialPermissions.length === 0 ? (

未授予特殊权限,6 项均默认关闭,需单独授予并记录审计。

) : (
{role.specialPermissions.map((code) => ( {meta === undefined ? code : permissionNameOf(meta, code)} ))}
)}
); } function BoundUsers({ role }: { role: RoleDetail }): ReactNode { const [expanded, setExpanded] = useState(false); const shown = expanded ? role.boundUsers : role.boundUsers.slice(0, 3); return (

绑定用户

{role.boundUsers.length > 3 ? ( ) : null}
{role.boundUsers.length === 0 ? (

暂未绑定用户,可停用或删除该角色。

) : ( )}
); } function DetailState({ roleId, loading, error, onRetry, }: Pick): ReactNode { if (roleId === null) { return ( ); } if (loading) { return (
); } if (error !== null) { return ( ); } return null; } /** 右侧角色详情面板(只读):权限摘要、数据范围、特殊权限、绑定用户与编辑入口 */ export function RoleDetailPanel(props: RoleDetailPanelProps): ReactNode { const ready = props.roleId !== null && props.detail !== undefined && props.error === null; const detail = props.detail; return (
{ready && detail !== undefined ? ( <>
编码 {detail.code} 绑定用户 {detail.userCount} 名 最近更新 {formatRoleDateTime(detail.updatedAt)}
) : (
)}
); }