feat(common-tools): 工具台新增常用工具分类,三个桌面工具网页化
- tool-catalog 最前插入「常用工具」组(brand_common_tools,23 工具·4 大分类), 三工具各自权限键:pricing-calc / five-asin / keyword-share - /pricing-calc:站点(英 GBP÷9、德法 EUR÷8)+ 买货价/运费 → 营业额/利润/ 利润率/换算汇率,公式与精度照抄桌面版,纯函数 node --test 钉住 - /five-asin:五国常量 + ASIN 10 位校验 → 亚马逊商品链接,window.open 与 :href 出口全部过 safeHttpUrl(url-outlet 棘轮),邮编一键复制 - /keyword-share:筛选/四级类目级联/统计卡/表格分页 200/标记与取消使用/ 添加/删除/随机抽词/共享记录,对接 keywordshare 后端九端点 - 顶栏与 BrandTopBar 导航同步;router 注册三路由;补 test:mount 脚本 (vitest mount 套件入口,与后管同口径)
This commit is contained in:
@@ -15,6 +15,7 @@ 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";
|
||||
|
||||
@@ -0,0 +1,290 @@
|
||||
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<unknown>>(`${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<KeywordShareLogsVo>>(`${JAVA_API_PREFIX}/keyword-share/logs`, {
|
||||
params: {
|
||||
type: query.type,
|
||||
country: query.country || undefined,
|
||||
page: query.page ?? 1,
|
||||
size: query.size ?? 20,
|
||||
},
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
export function fetchKeywordShareRandom(count = 10) {
|
||||
return unwrapJavaResponse(
|
||||
get<JavaApiResponse<KeywordShareRow[]>>(`${JAVA_API_PREFIX}/keyword-share/random`, {
|
||||
params: { count },
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
export interface KeywordStatsGroupedRow {
|
||||
country: string
|
||||
category: string
|
||||
count: number
|
||||
}
|
||||
|
||||
/**
|
||||
* 词库统计弹窗的兼容映射:/stats-grouped 的返回结构按后端实现演进,
|
||||
* 这里把已知形状统一拍平成「国家 × 一级类目 → 计数」行:
|
||||
* ① { rows: [{country, category, count}] };
|
||||
* ② [{country, category, count}] 数组;
|
||||
* ③ { 国家: { 类目: 数值 } } 二层映射。
|
||||
* 其余形状返回空数组(弹窗显示「暂无数据」,不报错)。
|
||||
*/
|
||||
export function normalizeKeywordStatsGrouped(raw: unknown): KeywordStatsGroupedRow[] {
|
||||
const rows: KeywordStatsGroupedRow[] = []
|
||||
|
||||
const pushRow = (country: unknown, category: unknown, count: unknown) => {
|
||||
const c = String(country ?? '').trim()
|
||||
const cat = String(category ?? '').trim()
|
||||
const n = Number(count)
|
||||
if (!c || !cat || !Number.isFinite(n)) return
|
||||
rows.push({ country: c, category: cat, count: n })
|
||||
}
|
||||
|
||||
if (Array.isArray(raw)) {
|
||||
for (const item of raw) {
|
||||
if (item && typeof item === 'object') {
|
||||
const record = item as Record<string, unknown>
|
||||
pushRow(record.country, record.category, record.count)
|
||||
}
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
if (raw && typeof raw === 'object') {
|
||||
const record = raw as Record<string, unknown>
|
||||
if (Array.isArray(record.rows)) {
|
||||
return normalizeKeywordStatsGrouped(record.rows)
|
||||
}
|
||||
for (const [country, value] of Object.entries(record)) {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) continue
|
||||
for (const [category, count] of Object.entries(value as Record<string, unknown>)) {
|
||||
pushRow(country, category, count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rows
|
||||
}
|
||||
Reference in New Issue
Block a user