b963561043
- CR-04:全局代理加 proxy_uid 归属,跨账号不再静默回退/补报 - CR-12:取消静默继承,设置页显式确认;同 OS 作用域、locked 代理排除、无效快照清除、uid+epoch 双校验、登出 capture 超时 - CR-26/27:关键词分页初始值与档位一致;两页面请求序号闸丢弃旧响应 vue-tsc 两前端 rc=0;定向 35 + 8 + 2 例全绿。
141 lines
3.8 KiB
TypeScript
141 lines
3.8 KiB
TypeScript
/** 关键词使用记录(独立菜单 admin_keyword_usage):与 /api/admin/keyword-usage 的 camel 契约对齐,纯逻辑。 */
|
|
|
|
export interface KeywordUsageQuery {
|
|
companyId?: number | null
|
|
user?: string
|
|
country?: string
|
|
keyword?: string
|
|
scene?: string
|
|
page?: number
|
|
pageSize?: number
|
|
}
|
|
|
|
export interface KeywordUsageFilter {
|
|
user: string
|
|
country: string
|
|
keyword: string
|
|
scene: string
|
|
}
|
|
|
|
export interface KeywordUsageRow {
|
|
userName: string
|
|
country: string
|
|
keyword: string
|
|
scene: string
|
|
time: string
|
|
}
|
|
|
|
export interface KeywordUsageCounts {
|
|
copy: number
|
|
copyExisting: number
|
|
copyDeleted: number
|
|
add: number
|
|
}
|
|
|
|
export interface KeywordUsagePage {
|
|
total: number
|
|
rows: KeywordUsageRow[]
|
|
counts: KeywordUsageCounts
|
|
}
|
|
|
|
export interface KeywordUsageStats {
|
|
used: number
|
|
exist: number
|
|
deletedKw: number
|
|
added: number
|
|
totalUse: number
|
|
deletes: number
|
|
}
|
|
|
|
export interface KeywordUsageOverview {
|
|
stats: KeywordUsageStats
|
|
users: string[]
|
|
countries: string[]
|
|
}
|
|
|
|
export const KEYWORD_USAGE_SCENES = ['已使用', '添加关键词'] as const
|
|
|
|
/** 初始每页条数:必须落在 OldPagination 的档位(10/20/50/100)里(CR-26)。 */
|
|
export const KEYWORD_USAGE_PAGE_SIZE = 10
|
|
|
|
export function createKeywordUsageFilter(): KeywordUsageFilter {
|
|
return { user: '', country: '', keyword: '', scene: '' }
|
|
}
|
|
|
|
function asRecord(value: unknown): Record<string, unknown> | null {
|
|
return value && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : null
|
|
}
|
|
|
|
function text(value: unknown): string {
|
|
return typeof value === 'string' ? value : value == null ? '' : String(value)
|
|
}
|
|
|
|
function count(value: unknown): number {
|
|
const n = Number(value)
|
|
return Number.isFinite(n) && n >= 0 ? n : 0
|
|
}
|
|
|
|
function textList(value: unknown): string[] {
|
|
return Array.isArray(value) ? value.map(text).filter((item) => item !== '') : []
|
|
}
|
|
|
|
export function parseKeywordUsageRow(value: unknown): KeywordUsageRow | null {
|
|
const row = asRecord(value)
|
|
if (!row) return null
|
|
return {
|
|
userName: text(row.userName),
|
|
country: text(row.country),
|
|
keyword: text(row.keyword),
|
|
scene: text(row.scene),
|
|
time: text(row.time),
|
|
}
|
|
}
|
|
|
|
export function parseKeywordUsagePage(value: unknown): KeywordUsagePage {
|
|
const page = asRecord(value)
|
|
const counts = asRecord(page?.counts)
|
|
const rows = Array.isArray(page?.rows)
|
|
? page.rows.map(parseKeywordUsageRow).filter((row): row is KeywordUsageRow => row !== null)
|
|
: []
|
|
return {
|
|
total: count(page?.total),
|
|
rows,
|
|
counts: {
|
|
copy: count(counts?.copy),
|
|
copyExisting: count(counts?.copyExisting),
|
|
copyDeleted: count(counts?.copyDeleted),
|
|
add: count(counts?.add),
|
|
},
|
|
}
|
|
}
|
|
|
|
export function parseKeywordUsageOverview(value: unknown): KeywordUsageOverview {
|
|
const overview = asRecord(value)
|
|
const stats = asRecord(overview?.stats)
|
|
return {
|
|
stats: {
|
|
used: count(stats?.used),
|
|
exist: count(stats?.exist),
|
|
deletedKw: count(stats?.deletedKw),
|
|
added: count(stats?.added),
|
|
totalUse: count(stats?.totalUse),
|
|
deletes: count(stats?.deletes),
|
|
},
|
|
users: textList(overview?.users),
|
|
countries: textList(overview?.countries),
|
|
}
|
|
}
|
|
|
|
export function keywordUsageSceneLabel(scene: string): string {
|
|
if (scene === '复制关键词') return '已使用(复制)'
|
|
if (scene === '添加关键词') return '添加关键词'
|
|
if (scene === '删除关键词') return '删除关键词'
|
|
return scene || '—'
|
|
}
|
|
|
|
/** 使用记录口径:复制 = 现存词 + 已删除词留痕;添加单列。 */
|
|
export function keywordUsageCountsText(counts: KeywordUsageCounts, total: number): string {
|
|
return `复制关键词 ${counts.copy} = 现存词 ${counts.copyExisting} + 已删除词 ${counts.copyDeleted}`
|
|
+ ` · 添加关键词 ${counts.add} · 合计 ${total} 条`
|
|
}
|