feat(keywordusage): 新增关键词使用记录并归位店铺管理菜单
V175 把品牌Gating库从数据管理组迁到店铺管理组(排序85),并在其后新增 关键词使用记录独立菜单(排序86)。后端新增只读查询模块,按公司范围读取 keyword_usage/keyword_add_log/keyword_delete_log,前端提供使用/删除记录、 统计卡与筛选。
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
/** 关键词使用记录(独立菜单 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
|
||||
|
||||
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} 条`
|
||||
}
|
||||
Reference in New Issue
Block a user