feat(jd-database): 工具栏「导出 CSV」按钮摘除(2026-11-21 用户拍板「删除掉」导出按钮)

This commit is contained in:
2026-11-21 23:17:59 +08:00
parent bbadc445af
commit 3184d6696d
7 changed files with 22 additions and 204 deletions
@@ -1,6 +1,7 @@
/** 京东数据库查询适配(v1.4 Phase 5 → v1.7 对齐原型):GET /api/admin/jd-products +
* 删除(DELETE /{id} + POST /batch-delete)+ CSV 导出(POST /export,2026-11-21 拍板
* 「只恢复 CSV」)+ 分组端点 /api/admin/jd-product-groups。
* 删除(DELETE /{id} + POST /batch-delete)+ 分组端点 /api/admin/jd-product-groups。
* CSV 导出已下线(2026-11-21 用户拍板「删除掉」导出按钮,exportJdProductsCsv 同步摘除;
* 后端 POST /export 端点暂留,下一 jar 发版窗再收)。
* 公司口径(2026-11-16 用户定案「删除掉公司 tab,参考品牌数据库」):全页零公司维度——
* 只读列表与类目下拉的 company_id 发送口已随公司 tab 摘除(后端读侧谓词同窗撤,重上时
* 从 git 历史找回),详情/编辑/删除/分组管理本就不带;行 company_id 列仍是同步来源标记、
@@ -385,52 +386,3 @@ export async function fetchJdAvailableShops(
? core.filter((shop): shop is string => typeof shop === 'string' && shop.trim() !== '')
: []
}
/** CSV 导出的本地兜底文件名(yyyyMMddHHmm,与后端导出文件名同一格式;秒位不要——
* 同一分钟内的两次导出覆盖旧文件是可接受语义,别拿毫秒名刷屏下载目录)。 */
function csvFilenameTimestamp(): string {
const now = new Date()
const pad = (n: number) => String(n).padStart(2, '0')
return `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}` +
`${pad(now.getHours())}${pad(now.getMinutes())}`
}
/** 从 Content-Disposition 里取 filename*=UTF-8'' 中文名(DownloadHeaderUtil 的形状:
* `attachment; filename="ascii回退"; filename*=UTF-8''%E4%BA%AC...`);取不到回 null。 */
function csvFilenameFromDisposition(disposition: unknown): string | null {
if (typeof disposition !== 'string') return null
const match = disposition.match(/filename\*=(?:UTF-8|utf-8)''([^;]+)/)
if (!match) return null
try {
return decodeURIComponent(match[1].trim())
} catch {
return null
}
}
/** 导出勾选商品为 CSV(v1.7 恢复导出,2026-11-21 拍板「只恢复 CSV」;2026-11-15 客户口径
* 「导出也不用」被本窗推翻):POST /api/admin/jd-products/export body {ids}(上限 1000,
* 后端 requireJdAccess 读闸),blob 下载 jd_products_<yyyyMMddHHmm>.csv——文件名优先取
* 后端 Content-Disposition 的 filename*(服务端是唯一出处),取不到回落本地同名格式。
* 文件头带 UTF-8 BOM,Excel 直开中文不乱码(AC-1)。业务失败(空勾选/超限)后端回
* JSON 信封但 HTTP 200 ⇒ blob 里是错误负载,交给调用方按非 CSV 内容提示(页面统一走
* try/catch 文案,此处只管传输与落盘)。 */
export async function exportJdProductsCsv(ids: number[]): Promise<void> {
const response = await http.post<Blob>(`${JD_PRODUCT_ENDPOINT}/export`, { ids }, { responseType: 'blob' })
const blob = response.data instanceof Blob
? response.data
: new Blob([response.data as BlobPart], { type: 'text/csv;charset=UTF-8' })
const filename = csvFilenameFromDisposition(response.headers?.['content-disposition'])
?? `jd_products_${csvFilenameTimestamp()}.csv`
const url = URL.createObjectURL(blob)
try {
const link = document.createElement('a')
link.href = url
link.download = filename
document.body.appendChild(link)
link.click()
link.remove()
} finally {
URL.revokeObjectURL(url)
}
}