revert(common-tools): 回滚常用工具分类与三个工具页
按 2026-10-24 决定整体下线:工具目录分组、定价换算/五国ASIN/关键词共享 三页面与路由、资料下载区与测试全部移除;保留 package.json 的 test:mount 脚本(仓内测试基础设施,与后管同口径)。
This commit is contained in:
@@ -15,7 +15,6 @@ export * from "./types/modules/brand.ts";
|
||||
export * from "./types/modules/permission.ts";
|
||||
export * from "./types/modules/user-secret.ts";
|
||||
export * from "./types/modules/digital-human.ts";
|
||||
export * from "./types/modules/keyword-share.ts";
|
||||
export * from "./progress-light.ts";
|
||||
export * from "./upload.ts";
|
||||
export * from "./download-url.ts";
|
||||
|
||||
@@ -1,342 +0,0 @@
|
||||
import { del, get, post, type JavaApiResponse, unwrapJavaResponse } from '../../http.ts'
|
||||
import { JAVA_API_PREFIX } from '../../url.ts'
|
||||
|
||||
/**
|
||||
* 五国关键词共享 API(/api/keyword-share,后端并行实现,契约以本文档字段为准)。
|
||||
*
|
||||
* companyId 服务端取;鉴权与错误折叠统一走 shared/api/http 的请求封装。
|
||||
* 所有函数返回 unwrapJavaResponse 拆包后的业务数据;失败时向调用方抛错
|
||||
* (页面用 ElMessage 提示,不白屏)。
|
||||
*/
|
||||
|
||||
export type KeywordShareStatusFilter = 'all' | 'used' | 'unused'
|
||||
export type KeywordShareLogType = 'usage' | 'add' | 'delete'
|
||||
/** 已使用时间筛选:0=全部(不传参),1=今天,7/30/90/180/360=近 N 天 */
|
||||
export type KeywordShareUsedDays = 0 | 1 | 7 | 30 | 90 | 180 | 360
|
||||
|
||||
export interface KeywordShareRow {
|
||||
id: number | string
|
||||
country: string
|
||||
keyword: string
|
||||
chinese?: string | null
|
||||
category?: string | null
|
||||
subCategory?: string | null
|
||||
categoryL3?: string | null
|
||||
categoryL4?: string | null
|
||||
used?: boolean
|
||||
usedTime?: string | null
|
||||
usedUser?: string | null
|
||||
}
|
||||
|
||||
export interface KeywordShareStats {
|
||||
/** 命中总数 */
|
||||
hit: number
|
||||
used: number
|
||||
unused: number
|
||||
/** 跨国重复 */
|
||||
dup: number
|
||||
}
|
||||
|
||||
export interface KeywordShareListVo {
|
||||
total: number
|
||||
rows: KeywordShareRow[]
|
||||
stats: KeywordShareStats
|
||||
}
|
||||
|
||||
export interface KeywordShareCategoryL3 {
|
||||
name: string
|
||||
l4: string[]
|
||||
}
|
||||
|
||||
export interface KeywordShareSubCategory {
|
||||
name: string
|
||||
l3: KeywordShareCategoryL3[]
|
||||
}
|
||||
|
||||
export interface KeywordShareCategory {
|
||||
name: string
|
||||
subs: KeywordShareSubCategory[]
|
||||
}
|
||||
|
||||
export interface KeywordShareFiltersVo {
|
||||
countries: string[]
|
||||
categories: KeywordShareCategory[]
|
||||
}
|
||||
|
||||
export interface KeywordShareAddItem {
|
||||
country: string
|
||||
keyword: string
|
||||
chinese?: string
|
||||
}
|
||||
|
||||
export interface KeywordShareAddVo {
|
||||
added: number
|
||||
skipped: number
|
||||
}
|
||||
|
||||
export interface KeywordShareDeleteVo {
|
||||
deleted: number
|
||||
}
|
||||
|
||||
export interface KeywordShareMarkVo {
|
||||
marked: number
|
||||
}
|
||||
|
||||
export interface KeywordShareUnmarkVo {
|
||||
unmarked: number
|
||||
}
|
||||
|
||||
export interface KeywordShareLogRow {
|
||||
id?: number | string
|
||||
/** usage=标记使用 / add=添加 / delete=删除 */
|
||||
type?: KeywordShareLogType | string
|
||||
country?: string | null
|
||||
keyword?: string | null
|
||||
chinese?: string | null
|
||||
operator?: string | null
|
||||
createdAt?: string | null
|
||||
detail?: string | null
|
||||
}
|
||||
|
||||
export interface KeywordShareLogsVo {
|
||||
total: number
|
||||
rows: KeywordShareLogRow[]
|
||||
}
|
||||
|
||||
export interface KeywordShareListQuery {
|
||||
country?: string
|
||||
/** 一级类目 */
|
||||
category?: string
|
||||
subCategory?: string
|
||||
categoryL3?: string
|
||||
categoryL4?: string
|
||||
/** 关键词 / 中文模糊搜索 */
|
||||
search?: string
|
||||
status?: KeywordShareStatusFilter
|
||||
/** 0=全部(不传参) */
|
||||
usedDays?: KeywordShareUsedDays
|
||||
/** 仅看我使用 */
|
||||
onlyMine?: boolean
|
||||
page?: number
|
||||
size?: number
|
||||
}
|
||||
|
||||
export interface KeywordShareLogsQuery {
|
||||
type?: KeywordShareLogType
|
||||
country?: string
|
||||
page?: number
|
||||
size?: number
|
||||
}
|
||||
|
||||
/** 列表查询参数拼装:空值与「全部」不传,避免后端把空串当条件 */
|
||||
export function buildKeywordShareListParams(query: KeywordShareListQuery): Record<string, unknown> {
|
||||
const params: Record<string, unknown> = {
|
||||
page: query.page ?? 1,
|
||||
size: query.size ?? 200,
|
||||
}
|
||||
const text = (value?: string | null) => {
|
||||
const trimmed = String(value ?? '').trim()
|
||||
return trimmed ? trimmed : undefined
|
||||
}
|
||||
params.country = text(query.country)
|
||||
params.category = text(query.category)
|
||||
params.subCategory = text(query.subCategory)
|
||||
params.categoryL3 = text(query.categoryL3)
|
||||
params.categoryL4 = text(query.categoryL4)
|
||||
params.search = text(query.search)
|
||||
if (query.status && query.status !== 'all') {
|
||||
params.status = query.status
|
||||
}
|
||||
if (query.usedDays && query.usedDays > 0) {
|
||||
params.usedDays = query.usedDays
|
||||
}
|
||||
if (query.onlyMine) {
|
||||
params.onlyMine = true
|
||||
}
|
||||
return params
|
||||
}
|
||||
|
||||
export function fetchKeywordShareKeywords(query: KeywordShareListQuery) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<KeywordShareListVo>>(`${JAVA_API_PREFIX}/keyword-share/keywords`, {
|
||||
params: buildKeywordShareListParams(query),
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
export function fetchKeywordShareFilters() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<KeywordShareFiltersVo>>(`${JAVA_API_PREFIX}/keyword-share/filters`),
|
||||
)
|
||||
}
|
||||
|
||||
export function fetchKeywordShareStatsGrouped() {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<KeywordShareStatsGroupedVo>>(`${JAVA_API_PREFIX}/keyword-share/stats-grouped`),
|
||||
)
|
||||
}
|
||||
|
||||
export function addKeywordShareKeywords(items: KeywordShareAddItem[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<KeywordShareAddVo>, { items: KeywordShareAddItem[] }>(
|
||||
`${JAVA_API_PREFIX}/keyword-share/keywords`,
|
||||
{ items },
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
export function deleteKeywordShareKeywords(ids: Array<number | string>) {
|
||||
return unwrapJavaResponse(
|
||||
del<JavaApiResponse<KeywordShareDeleteVo>>(
|
||||
`${JAVA_API_PREFIX}/keyword-share/keywords`,
|
||||
{ data: { ids } },
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
export interface KeywordShareUsageItem {
|
||||
country: string
|
||||
keyword: string
|
||||
}
|
||||
|
||||
export function markKeywordShareUsage(items: KeywordShareUsageItem[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<KeywordShareMarkVo>, { items: KeywordShareUsageItem[] }>(
|
||||
`${JAVA_API_PREFIX}/keyword-share/usage/mark`,
|
||||
{ items },
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
export function unmarkKeywordShareUsage(items: KeywordShareUsageItem[]) {
|
||||
return unwrapJavaResponse(
|
||||
post<JavaApiResponse<KeywordShareUnmarkVo>, { items: KeywordShareUsageItem[] }>(
|
||||
`${JAVA_API_PREFIX}/keyword-share/usage/unmark`,
|
||||
{ items },
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
export function fetchKeywordShareLogs(query: KeywordShareLogsQuery) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<KeywordShareLogRawVo>>(`${JAVA_API_PREFIX}/keyword-share/logs`, {
|
||||
params: {
|
||||
type: query.type,
|
||||
country: query.country || undefined,
|
||||
page: query.page ?? 1,
|
||||
size: query.size ?? 20,
|
||||
},
|
||||
}),
|
||||
).then((raw) => mapKeywordShareLogs(raw, query.type))
|
||||
}
|
||||
|
||||
export function fetchKeywordShareRandom(count = 10) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<KeywordShareRow[]>>(`${JAVA_API_PREFIX}/keyword-share/random`, {
|
||||
params: { count },
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
/** 后端 /stats-grouped 的四段分布(对齐桌面版词库统计弹窗:国家 / 一级 / 二级 / 三级) */
|
||||
export interface KeywordShareStatsGroupedVo {
|
||||
byCountry?: Array<{ name?: string | null; count?: number | string | null }> | null
|
||||
byCategory?: Array<{ name?: string | null; count?: number | string | null }> | null
|
||||
bySubCategory?: Array<{ category?: string | null; name?: string | null; count?: number | string | null }> | null
|
||||
byCategoryL3?: Array<{
|
||||
category?: string | null
|
||||
subCategory?: string | null
|
||||
name?: string | null
|
||||
count?: number | string | null
|
||||
}> | null
|
||||
}
|
||||
|
||||
/** 弹窗一行:group 是所属上级(二级/三级段用),label 是本段名称 */
|
||||
export interface KeywordStatsItem {
|
||||
group: string
|
||||
label: string
|
||||
count: number
|
||||
}
|
||||
|
||||
export interface KeywordStatsSections {
|
||||
byCountry: KeywordStatsItem[]
|
||||
byCategory: KeywordStatsItem[]
|
||||
bySubCategory: KeywordStatsItem[]
|
||||
byCategoryL3: KeywordStatsItem[]
|
||||
}
|
||||
|
||||
function statsCount(value: unknown): number | null {
|
||||
// Number(null) 与 Number('') 都是 0——缺计数的脏行必须判无效丢弃,不能冒充「0 个词」
|
||||
if (value === null || value === undefined || value === '') return null
|
||||
const n = Number(value)
|
||||
return Number.isFinite(n) ? n : null
|
||||
}
|
||||
|
||||
/**
|
||||
* /stats-grouped → 四段分布。后端返回的是四份各自 GROUP BY 的清单(不是国家×类目交叉表),
|
||||
* 缺段/脏行按空处理,弹窗对应段显示「暂无数据」而不是整窗报错。
|
||||
*/
|
||||
export function buildKeywordStatsSections(raw: unknown): KeywordStatsSections {
|
||||
const source = (raw && typeof raw === 'object' ? raw : {}) as KeywordShareStatsGroupedVo
|
||||
const flat = (
|
||||
rows: Array<{ name?: string | null; count?: number | string | null }> | null | undefined,
|
||||
groupOf: (row: { name?: string | null; count?: number | string | null }) => string,
|
||||
): KeywordStatsItem[] =>
|
||||
(Array.isArray(rows) ? rows : []).flatMap((row) => {
|
||||
const label = String(row?.name ?? '').trim()
|
||||
const count = statsCount(row?.count)
|
||||
if (!label || count === null) return []
|
||||
return [{ group: groupOf(row), label, count }]
|
||||
})
|
||||
|
||||
return {
|
||||
byCountry: flat(source.byCountry, () => ''),
|
||||
byCategory: flat(source.byCategory, () => ''),
|
||||
bySubCategory: flat(source.bySubCategory, (row) => String((row as { category?: string | null }).category ?? '').trim()),
|
||||
byCategoryL3: flat(source.byCategoryL3, (row) => {
|
||||
const item = row as { category?: string | null; subCategory?: string | null }
|
||||
const category = String(item.category ?? '').trim()
|
||||
const sub = String(item.subCategory ?? '').trim()
|
||||
return [category, sub].filter(Boolean).join(' / ')
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
/** 后端日志行字段名与展示口径不同(userName/time),映射到表格用的 operator/createdAt */
|
||||
export interface KeywordShareLogRawRow {
|
||||
id?: number | string
|
||||
userName?: string | null
|
||||
country?: string | null
|
||||
keyword?: string | null
|
||||
/** Jackson 默认 ISO-8601(2026-10-23T21:12:34),也可能带毫秒 */
|
||||
time?: string | null
|
||||
}
|
||||
|
||||
export interface KeywordShareLogRawVo {
|
||||
total?: number | string
|
||||
rows?: KeywordShareLogRawRow[] | null
|
||||
}
|
||||
|
||||
/** ISO 时间 → 'YYYY-MM-DD HH:mm:ss';非 ISO 形态原样透出,空值给空串 */
|
||||
export function formatLogTime(raw?: string | null): string {
|
||||
const value = String(raw ?? '').trim()
|
||||
if (!value) return ''
|
||||
const matched = /^(\d{4}-\d{2}-\d{2})[T ](\d{2}:\d{2}:\d{2})/.exec(value)
|
||||
return matched ? `${matched[1]} ${matched[2]}` : value
|
||||
}
|
||||
|
||||
export function mapKeywordShareLogs(raw: unknown, type?: KeywordShareLogType): KeywordShareLogsVo {
|
||||
const source = (raw && typeof raw === 'object' ? raw : {}) as KeywordShareLogRawVo
|
||||
const rows = Array.isArray(source.rows) ? source.rows : []
|
||||
return {
|
||||
total: Number.isFinite(Number(source.total)) ? Number(source.total) : rows.length,
|
||||
rows: rows.map((row) => ({
|
||||
id: row?.id,
|
||||
type,
|
||||
country: row?.country ?? null,
|
||||
keyword: row?.keyword ?? null,
|
||||
operator: row?.userName ?? null,
|
||||
createdAt: formatLogTime(row?.time),
|
||||
})),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user