File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
packages/fluent-editor/src/modules/file/modules Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments