Skip to content

Commit 8553175

Browse files
authored
feat: download file when click in readonly mode (#443)
1 parent d3c6df9 commit 8553175

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

packages/fluent-editor/src/modules/file/modules/file-module.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ export class FileModule {
2222

2323
if (fileDom) {
2424
event.preventDefault()
25-
// 在只读模式下不显示 file-bar
25+
// 在只读模式下直接下载文件
2626
if (!this.quill.isEnabled()) {
27+
this.downloadFile(fileDom)
2728
return
2829
}
2930
if (this.fileBar) {
@@ -37,4 +38,20 @@ export class FileModule {
3738
this.fileBar = null
3839
}
3940
}
41+
42+
downloadFile(fileDom: HTMLElement) {
43+
const fileName = fileDom.dataset.title || ''
44+
const fileDownloadUrl = fileDom.getAttribute('href') || ''
45+
if (fileDownloadUrl) {
46+
const a = document.createElement('a')
47+
a.href = fileDownloadUrl
48+
a.target = '_blank'
49+
a.id = 'exppub'
50+
a.download = fileName
51+
document.body.appendChild(a)
52+
const alink = document.getElementById('exppub')
53+
alink?.click()
54+
alink?.parentNode?.removeChild(a)
55+
}
56+
}
4057
}

0 commit comments

Comments
 (0)