diff --git a/packages/fluent-editor/src/modules/file/modules/file-module.ts b/packages/fluent-editor/src/modules/file/modules/file-module.ts index a6612720..56946b93 100644 --- a/packages/fluent-editor/src/modules/file/modules/file-module.ts +++ b/packages/fluent-editor/src/modules/file/modules/file-module.ts @@ -22,8 +22,9 @@ export class FileModule { if (fileDom) { event.preventDefault() - // 在只读模式下不显示 file-bar + // 在只读模式下直接下载文件 if (!this.quill.isEnabled()) { + this.downloadFile(fileDom) return } if (this.fileBar) { @@ -37,4 +38,20 @@ export class FileModule { this.fileBar = null } } + + downloadFile(fileDom: HTMLElement) { + const fileName = fileDom.dataset.title || '' + const fileDownloadUrl = fileDom.getAttribute('href') || '' + if (fileDownloadUrl) { + const a = document.createElement('a') + a.href = fileDownloadUrl + a.target = '_blank' + a.id = 'exppub' + a.download = fileName + document.body.appendChild(a) + const alink = document.getElementById('exppub') + alink?.click() + alink?.parentNode?.removeChild(a) + } + } }