/** 用户列表加载/空/错状态(任务 52):纯 phase 归一无 UI 依赖,供页面展示决策复用。 */ export type ListPhase = 'loading' | 'error' | 'empty' | 'ready' export interface UserListPhaseInput { loading?: boolean error?: string items?: unknown[] total?: number } /** 归一列表展示相位:loading 优先,其次 error,其次空,否则 ready。 */ export function listPhaseOf(input: UserListPhaseInput): ListPhase { if (input.loading) return 'loading' if (typeof input.error === 'string' && input.error.trim()) return 'error' const items = Array.isArray(input.items) ? input.items : [] const total = typeof input.total === 'number' ? input.total : items.length if (items.length === 0 || total === 0) return 'empty' return 'ready' } /** 空态提示文案。 */ export function userListEmptyHint(): string { return '暂无用户数据' } /** 错误态可操作提示:带上具体原因,缺省给通用文案。 */ export function userListErrorHint(message?: string | null): string { const text = (message || '').trim() return text ? `加载失败:${text}` : '加载失败,请稍后重试' }