916f179fca
新增 user-list-state.ts 纯 phase 归一(loading>error>empty>ready)与空/错提示; UsersPage 显式 loadError 态 + 错误 el-alert(带重试)、加载/错误/空相位决策、 删除按钮对超管禁用。8 用例全过,379 单测 + build 绿。
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
/** 用户列表加载/空/错状态(任务 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}` : '加载失败,请稍后重试'
|
|
}
|