task-59(账号/权限页面): 实现数据权限分组列表和摘要
新增 shop-group-model.ts 解析 Java ShopManageGroupItemVo(camel)并汇总(groupCount/memberTotal); shop-group-api.ts GET /api/admin/shop-manages/groups;GroupsPage 去内联 http,改走 adapter 展示分组列表 + 顶部摘要统计卡。8 用例全过,435 单测 + build 绿。
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
/** 数据权限分组列表模型(任务 59):解析 Java ShopManageGroupItemVo + 摘要统计,纯逻辑。 */
|
||||
import { unwrap } from '../../api/envelope.ts'
|
||||
|
||||
export interface ShopGroupItem {
|
||||
id: number
|
||||
name: string
|
||||
leaderUsername: string
|
||||
memberCount: number
|
||||
memberUsernames: string[]
|
||||
createdAt?: string
|
||||
}
|
||||
|
||||
function text(value: unknown): string {
|
||||
return typeof value === 'string' ? value.trim() : ''
|
||||
}
|
||||
|
||||
function numberOrNull(value: unknown): number | null {
|
||||
return typeof value === 'number' && Number.isFinite(value) ? Math.floor(value) : null
|
||||
}
|
||||
|
||||
/** 解析单条分组项;缺 id 视为无效。 */
|
||||
export function parseShopGroupItem(raw: unknown): ShopGroupItem | null {
|
||||
if (!raw || typeof raw !== 'object') return null
|
||||
const record = raw as Record<string, unknown>
|
||||
const id = numberOrNull(record.id)
|
||||
if (id === null) return null
|
||||
const names = Array.isArray(record.memberUsernames)
|
||||
? record.memberUsernames.map((v) => text(v)).filter(Boolean)
|
||||
: []
|
||||
const count = numberOrNull(record.memberCount)
|
||||
const item: ShopGroupItem = {
|
||||
id,
|
||||
name: text(record.groupName ?? record.name) || `分组${id}`,
|
||||
leaderUsername: text(record.leaderUsername ?? record.leader_name),
|
||||
memberCount: count === null ? names.length : count,
|
||||
memberUsernames: names,
|
||||
}
|
||||
const createdAt = text(record.createdAt ?? record.created_at)
|
||||
if (createdAt) item.createdAt = createdAt
|
||||
return item
|
||||
}
|
||||
|
||||
/** 归一化分组列表响应(信封或裸数组)。 */
|
||||
export function parseShopGroupList(payload: unknown): ShopGroupItem[] {
|
||||
const data = unwrap<unknown>(payload)
|
||||
if (!Array.isArray(data)) return []
|
||||
return data
|
||||
.map((raw) => parseShopGroupItem(raw))
|
||||
.filter((item): item is ShopGroupItem => item !== null)
|
||||
}
|
||||
|
||||
/** 分组摘要:分组总数 + 组员总数。 */
|
||||
export function shopGroupSummary(groups: ShopGroupItem[]): { groupCount: number; memberTotal: number } {
|
||||
let memberTotal = 0
|
||||
for (const group of groups) memberTotal += group.memberCount || 0
|
||||
return { groupCount: groups.length, memberTotal }
|
||||
}
|
||||
Reference in New Issue
Block a user