| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -58,6 +58,29 @@ const onExceed: UploadProps['onExceed'] = () => { | |||
| 58 | 58 | const onSuccess: UploadProps['onSuccess'] = (res, file, fileList) => { | |
| 59 | 59 | emits('onSuccess', res, file, fileList) | |
| 60 | 60 | } | |
| 61 | + | ||
| 62 | + const onPreview: UploadProps['onPreview'] = (e) => { | ||
| 63 | + const getBlob = (url: string) => new Promise((resolve) => { | ||
| 64 | + const xhr = new XMLHttpRequest() | ||
| 65 | + xhr.open('GET', url, true) | ||
| 66 | + xhr.responseType = 'blob' | ||
| 67 | + xhr.onload = () => { | ||
| 68 | + if (xhr.status === 200) { | ||
| 69 | + resolve(xhr.response) | ||
| 70 | + } | ||
| 71 | + } | ||
| 72 | + xhr.send() | ||
| 73 | + }) | ||
| 74 | + getBlob(e.url!).then((blob: any) => { | ||
| 75 | + const a = document.createElement('a') | ||
| 76 | + const url = window.URL.createObjectURL(blob) | ||
| 77 | + const event = new MouseEvent('click') | ||
| 78 | + a.target = '_blank' | ||
| 79 | + a.download = e.name | ||
| 80 | + a.href = url | ||
| 81 | + a.dispatchEvent(event) | ||
| 82 | + }) | ||
| 83 | + } | ||
| 61 | 84 | </script> | |
| 62 | 85 | ||
| 63 | 86 | <template> | |
@@ -69,6 +92,7 @@ const onSuccess: UploadProps['onSuccess'] = (res, file, fileList) => { | |||
| 69 | 92 | :before-upload="beforeUpload" | |
| 70 | 93 | :on-exceed="onExceed" | |
| 71 | 94 | :on-success="onSuccess" | |
| 95 | + :on-preview="onPreview" | ||
| 72 | 96 | :http-request="httpRequest" | |
| 73 | 97 | :file-list="files" | |
| 74 | 98 | :limit="max" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments