chore: final Minor polish — export filename/test断言, downloadBlob 类型/清理, plan docs
address review Minors: drop redundant filename replace, assert 暂无消息, tighten downloadBlob return type + try/finally, fix plan group time-picker wording. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -42,11 +42,11 @@ export function getJson<T>(url: string, params?: Record<string, unknown>): Promi
|
||||
return http.get(url, { params }) as unknown as Promise<T>
|
||||
}
|
||||
|
||||
/** 以 blob 下载(用于 HTML 导出等二进制/文本附件下载)。返回建议文件名(来自 content-disposition,缺失则 undefined)。 */
|
||||
/** 以 blob 下载(用于 HTML 导出等二进制/文本附件下载)。返回固定文件名(响应拦截器丢失 content-disposition 头)。 */
|
||||
export async function downloadBlob(
|
||||
url: string,
|
||||
params?: Record<string, unknown>,
|
||||
): Promise<string | undefined> {
|
||||
): Promise<string> {
|
||||
const res = await http.get(url, { params, responseType: 'blob' })
|
||||
const blob = res as unknown as Blob
|
||||
// 从响应头取文件名(拦截器只解包 body,需用 raw 拦截;此处 res 已是 blob,header 丢失 → 用固定名)
|
||||
@@ -56,8 +56,11 @@ export async function downloadBlob(
|
||||
a.href = objUrl
|
||||
a.download = filename
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
URL.revokeObjectURL(objUrl)
|
||||
try {
|
||||
a.click()
|
||||
} finally {
|
||||
document.body.removeChild(a)
|
||||
URL.revokeObjectURL(objUrl)
|
||||
}
|
||||
return filename
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user