task-259(admin.html观感对齐): 生成记录页对齐(指定用户下拉+起止时间筛选/类型中文/≤3缩略图/空态)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
/** 历史页“指定用户”下拉选项解析(module 13 task 259):/api/admin/users?page_size=999 的用户精简选项。纯逻辑。 */
|
||||
import { unwrap } from '../../api/envelope.ts'
|
||||
|
||||
export interface HistoryUserOption {
|
||||
id: number
|
||||
username: string
|
||||
}
|
||||
|
||||
function idOf(value: unknown): number | null {
|
||||
return typeof value === 'number' && Number.isFinite(value) && value >= 1 ? Math.floor(value) : null
|
||||
}
|
||||
|
||||
function text(value: unknown): string {
|
||||
return typeof value === 'string' ? value.trim() : ''
|
||||
}
|
||||
|
||||
export function parseHistoryUserOptions(payload: unknown): HistoryUserOption[] {
|
||||
const core = unwrap<unknown>(payload)
|
||||
if (!core || typeof core !== 'object') return []
|
||||
const items = (core as Record<string, unknown>).items
|
||||
if (!Array.isArray(items)) return []
|
||||
const options: HistoryUserOption[] = []
|
||||
for (const raw of items) {
|
||||
if (!raw || typeof raw !== 'object') continue
|
||||
const row = raw as Record<string, unknown>
|
||||
const id = idOf(row.id)
|
||||
if (id === null) continue
|
||||
options.push({ id, username: text(row.username) || `#${id}` })
|
||||
}
|
||||
return options
|
||||
}
|
||||
Reference in New Issue
Block a user