提交
This commit is contained in:
1 parent
f269a994f4
commit
93cd506a90
71 files changed
+8297
-2207
No files matched your search
@@ -0,0 +1,45 @@
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { fetchAttachmentDownloadUrl } from '@/api/business'
|
||||
|
||||
export type AttachmentDownloadItem = {
|
||||
fileUrl?: string
|
||||
fileName?: string
|
||||
}
|
||||
|
||||
function triggerAnchorDownload(href: string, fileName: string) {
|
||||
const a = document.createElement('a')
|
||||
a.href = href
|
||||
a.download = fileName
|
||||
a.rel = 'noopener'
|
||||
document.body.appendChild(a)
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
}
|
||||
|
||||
/** 附件下载:优先走后端预签名 URL,保证跨域场景下保留原始文件名与后缀。 */
|
||||
export async function downloadAttachmentFile(
|
||||
file: AttachmentDownloadItem,
|
||||
options?: { fullFileUrl?: (url: string) => string }
|
||||
) {
|
||||
const fileUrl = String(file.fileUrl || '').trim()
|
||||
if (!fileUrl) return
|
||||
const fileName = String(file.fileName || '').trim() || fileUrl.split('/').pop() || 'download'
|
||||
|
||||
try {
|
||||
const res = await fetchAttachmentDownloadUrl({ fileUrl, fileName })
|
||||
if (res?.downloadUrl) {
|
||||
triggerAnchorDownload(res.downloadUrl, fileName)
|
||||
return
|
||||
}
|
||||
} catch {
|
||||
// 预签名失败时回退直连
|
||||
}
|
||||
|
||||
const resolveUrl = options?.fullFileUrl || ((url: string) => url)
|
||||
const href = resolveUrl(fileUrl)
|
||||
if (!href) {
|
||||
ElMessage.error('无法下载附件')
|
||||
return
|
||||
}
|
||||
triggerAnchorDownload(href, fileName)
|
||||
}
|
||||
@@ -22,5 +22,8 @@ export const fullscreenLoadingText = {
|
||||
save: '正在保存,请稍候…',
|
||||
delete: '正在删除,请稍候…',
|
||||
batchDelete: '正在批量删除,请稍候…',
|
||||
batchAudit: '正在提交审核,请稍候…'
|
||||
batchAudit: '正在提交审核,请稍候…',
|
||||
activate: '正在生效,请稍候…',
|
||||
voidAgreement: '正在作废,请稍候…',
|
||||
addItems: '正在添加,请稍候…'
|
||||
} as const
|
||||
Reference in new issue
Block a user