diff --git a/yunkes/src/api/client.ts b/yunkes/src/api/client.ts index 080e996..5da4291 100644 --- a/yunkes/src/api/client.ts +++ b/yunkes/src/api/client.ts @@ -41,3 +41,23 @@ http.interceptors.response.use( export function getJson(url: string, params?: Record): Promise { return http.get(url, { params }) as unknown as Promise } + +/** 以 blob 下载(用于 HTML 导出等二进制/文本附件下载)。返回建议文件名(来自 content-disposition,缺失则 undefined)。 */ +export async function downloadBlob( + url: string, + params?: Record, +): Promise { + const res = await http.get(url, { params, responseType: 'blob' }) + const blob = res as unknown as Blob + // 从响应头取文件名(拦截器只解包 body,需用 raw 拦截;此处 res 已是 blob,header 丢失 → 用固定名) + const filename = 'chat-export.html' + const objUrl = URL.createObjectURL(blob) + const a = document.createElement('a') + a.href = objUrl + a.download = filename + document.body.appendChild(a) + a.click() + document.body.removeChild(a) + URL.revokeObjectURL(objUrl) + return filename +}