Files
crawler-plugin/admin-frontend-vue/src/pages/patent/appearance-patent-clean-api.ts
T

105 lines
4.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/** 外观专利无侵权数据列表查询适配(v1.3 AC-5):GET /api/admin/appearance-patent-clean-items。
* 只读页+导出(2026-11-11 客户需求「数据得导出来」):公司 tab 的值由本发送口从原始入参自己下传
* (白名单构造不认识 company_id),取值口形状由 company-tab-wiring 护栏钉住。
* 2026-11-11 晚间恢复明细表:主管聚合(/supervisors)与按主管删除的前端发送口随卡片视图一并
* 下架(客户「不是这种格式 按照昨天那个格式」+删除入口先撤);后端两接口保留,要恢复时
* 从 git 历史(e1767faf)找回。 */
import { http } from '@/api/http'
import { errorTextOf, unwrap } from '../../api/envelope.ts'
import {
toAppearancePatentCleanExportParams,
toAppearancePatentCleanListParams,
type AppearancePatentCleanExportParams,
type AppearancePatentCleanExportQuery,
type AppearancePatentCleanListParams,
} from './appearance-patent-clean-filter.ts'
import {
parseAppearancePatentCleanPage,
type AppearancePatentCleanPageResult,
} from './appearance-patent-clean-model.ts'
export const APPEARANCE_PATENT_CLEAN_ENDPOINT = '/api/admin/appearance-patent-clean-items'
export async function fetchAppearancePatentCleanList(
params: AppearancePatentCleanListParams,
): Promise<AppearancePatentCleanPageResult> {
const query = toAppearancePatentCleanListParams(
{
taskId: params.taskId ?? '',
asin: params.asin ?? '',
country: params.country ?? '',
groupId: params.groupId ?? '',
startDate: params.startDate ?? '',
endDate: params.endDate ?? '',
},
params.page,
params.pageSize,
)
if (params.companyId != null) query.company_id = params.companyId
const { data } = await http.get<unknown>(APPEARANCE_PATENT_CLEAN_ENDPOINT, { params: query })
return parseAppearancePatentCleanPage(data)
}
export interface AppearancePatentCleanExportResult {
blob: Blob
filename: string
}
/** 从 Content-Disposition 取 filename*(UTF-8 轨,后端 DownloadHeaderUtil 双轨口径),取不到回退常量名。 */
function exportFilenameOf(disposition: unknown): string {
const raw = typeof disposition === 'string' ? disposition : ''
const star = /filename\*=(?:UTF-8'')?([^;]+)/i.exec(raw)
if (star?.[1]) {
try {
return decodeURIComponent(star[1].trim().replace(/^"|"$/g, '')) || '外观专利数据库.xlsx'
} catch {
// 编码坏的 filename* 当作没有,走 ASCII 轨或常量名
}
}
const plain = /filename="([^"]+)"/i.exec(raw)
return plain?.[1] || '外观专利数据库.xlsx'
}
/** 导出当前过滤面全量明细:与列表共用同一过滤面取值口(含公司 tab),blob 下载交给页面触发保存。 */
export async function exportAppearancePatentCleanList(
params: AppearancePatentCleanExportParams,
): Promise<AppearancePatentCleanExportResult> {
const query: AppearancePatentCleanExportQuery = toAppearancePatentCleanExportParams({
taskId: params.taskId ?? '',
asin: params.asin ?? '',
country: params.country ?? '',
groupId: params.groupId ?? '',
startDate: params.startDate ?? '',
endDate: params.endDate ?? '',
})
if (params.companyId != null) query.company_id = params.companyId
const response = await http.get<Blob>(`${APPEARANCE_PATENT_CLEAN_ENDPOINT}/export`, {
params: query,
responseType: 'blob',
timeout: 120_000,
})
const disposition = response.headers?.['content-disposition']
if (!disposition) {
// 没有附件头=服务端回了业务错误信封(HTTP 200 + JSON),把 blob 文本解回错误文案抛给页面
const blob = response.data
let payload: unknown = null
if (blob && typeof blob.text === 'function') {
const text = await blob.text()
try {
payload = JSON.parse(text)
} catch {
payload = text
}
}
throw new Error(errorTextOf(payload))
}
return { blob: response.data, filename: exportFilenameOf(disposition) }
}
/** 分组(主管)下拉选项:复用既有 GET /shop-manages/groups(与去重页/店铺管理共用同一分组集,
* 不下新端点)。2026-11-11 客户口径「主管就是组长,可以筛选组长来导出,就是分组」——
* 选项是分组管理里那一行(DedupeGroupOption {id, name, leaderUserId}),选中后以 group_id
* 走本文件 list/export 同一过滤面。 */
export { fetchDedupeTotalGroups } from '../asin/dedupe-total-api.ts'
export type { DedupeGroupOption } from '../asin/dedupe-total-api.ts'