align(去重汇总): 页顶数据权限分组汇总卡(超管全部分组·N个/组员chips组长·组员/未加入分组)、导出改流式下载+等待遮罩(正在生成导出文件/已等待N秒)、分组空值显示未分组(对齐 admin.js renderDedupeGroupSummary/showDedupeTotalDataExportWait)
This commit is contained in:
@@ -74,3 +74,60 @@ export function parseDedupeTotalPage(payload: unknown): DedupeTotalPageResult {
|
||||
export function emptyDedupePageParams(): Partial<AsinListParams> {
|
||||
return { page: 1, pageSize: ASIN_PAGE_DEFAULT_SIZE }
|
||||
}
|
||||
|
||||
/** 数据权限分组选项(GET /api/admin/shop-manages/groups items)。 */
|
||||
export interface DedupeGroupOption {
|
||||
id: number
|
||||
name: string
|
||||
leaderUserId?: number | null
|
||||
}
|
||||
|
||||
/** 归一化分组选项负载(信封 items 或裸数组),缺 id 行丢弃;解析组长 id 供汇总卡判定组长/组员。 */
|
||||
export function parseDedupeGroupOptionList(payload: unknown): DedupeGroupOption[] {
|
||||
const core = unwrap<unknown>(payload)
|
||||
const rawList = Array.isArray(core)
|
||||
? core
|
||||
: core && typeof core === 'object'
|
||||
? (core as Record<string, unknown>).items
|
||||
: []
|
||||
if (!Array.isArray(rawList)) return []
|
||||
const options: DedupeGroupOption[] = []
|
||||
for (const raw of rawList) {
|
||||
if (!raw || typeof raw !== 'object') continue
|
||||
const record = raw as Record<string, unknown>
|
||||
const id = typeof record.id === 'number' ? Math.floor(record.id) : Number(record.group_id)
|
||||
if (!Number.isFinite(id) || id <= 0) continue
|
||||
const nameRaw = record.group_name ?? record.name
|
||||
const name = typeof nameRaw === 'string' ? nameRaw.trim() : ''
|
||||
const option: DedupeGroupOption = { id, name: name || `分组${id}` }
|
||||
const leaderRaw = record.leader_user_id ?? record.leaderUserId
|
||||
const leaderUserId = typeof leaderRaw === 'number' ? Math.floor(leaderRaw) : Number(leaderRaw)
|
||||
if (Number.isFinite(leaderUserId) && leaderUserId > 0) option.leaderUserId = leaderUserId
|
||||
options.push(option)
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
/** 页顶数据权限分组汇总(对齐 admin.js renderDedupeGroupSummary)。 */
|
||||
export type DedupeGroupSummary =
|
||||
| { kind: 'all'; count: number }
|
||||
| { kind: 'none' }
|
||||
| { kind: 'chips'; chips: Array<{ name: string; relation: string }>; extra: number }
|
||||
|
||||
export function dedupeGroupSummaryOf(
|
||||
groups: DedupeGroupOption[],
|
||||
currentUserId: number | null,
|
||||
operatorRole: string,
|
||||
): DedupeGroupSummary {
|
||||
if ((operatorRole || '').toLowerCase() === 'super_admin') {
|
||||
return { kind: 'all', count: groups.length }
|
||||
}
|
||||
if (!groups.length) return { kind: 'none' }
|
||||
const visible = groups.slice(0, 4)
|
||||
const currentKey = currentUserId != null ? String(currentUserId) : ''
|
||||
const chips = visible.map((group) => ({
|
||||
name: group.name,
|
||||
relation: String(group.leaderUserId ?? '') === currentKey ? '组长' : '组员',
|
||||
}))
|
||||
return { kind: 'chips', chips, extra: Math.max(groups.length - visible.length, 0) }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user