解决文件下载问题
Showing
4 changed files
with
16 additions
and
13 deletions
| ... | @@ -23,6 +23,7 @@ export const parseAndDecodeUrl = (url:string) => { | ... | @@ -23,6 +23,7 @@ export const parseAndDecodeUrl = (url:string) => { |
| 23 | 23 | ||
| 24 | // 返回去掉主机信息和开头斜杠后的解码部分以及最后一个斜杠后面的内容 | 24 | // 返回去掉主机信息和开头斜杠后的解码部分以及最后一个斜杠后面的内容 |
| 25 | return { | 25 | return { |
| 26 | fileName: pathname, | ||
| 26 | decodedPath: pathname + search + hash, | 27 | decodedPath: pathname + search + hash, |
| 27 | lastPart: lastPart | 28 | lastPart: lastPart |
| 28 | }; | 29 | }; | ... | ... |
| ... | @@ -337,7 +337,8 @@ const handlePictureCardPreview = (file, item) => { | ... | @@ -337,7 +337,8 @@ const handlePictureCardPreview = (file, item) => { |
| 337 | const onUploadFilePreview = async (file, item) => { | 337 | const onUploadFilePreview = async (file, item) => { |
| 338 | let f = formInline.value[item.field].find(i => i.name == file.name); | 338 | let f = formInline.value[item.field].find(i => i.name == file.name); |
| 339 | let url = f.url; | 339 | let url = f.url; |
| 340 | const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(url).decodedPath); | 340 | let fileName: string = parseAndDecodeUrl(url).fileName; |
| 341 | const refSignInfo: any = await getDownFileSignByUrl(fileName); | ||
| 341 | if (!refSignInfo?.data) { | 342 | if (!refSignInfo?.data) { |
| 342 | refSignInfo?.msg && ElMessage.error(refSignInfo?.msg); | 343 | refSignInfo?.msg && ElMessage.error(refSignInfo?.msg); |
| 343 | return; | 344 | return; |
| ... | @@ -360,7 +361,7 @@ const onUploadFilePreview = async (file, item) => { | ... | @@ -360,7 +361,7 @@ const onUploadFilePreview = async (file, item) => { |
| 360 | } | 361 | } |
| 361 | 362 | ||
| 362 | const downloadTemplate = async (url) => { | 363 | const downloadTemplate = async (url) => { |
| 363 | const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(url).decodedPath); | 364 | const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(url).fileName); |
| 364 | if (!refSignInfo?.data) { | 365 | if (!refSignInfo?.data) { |
| 365 | refSignInfo?.msg && ElMessage.error(refSignInfo?.msg); | 366 | refSignInfo?.msg && ElMessage.error(refSignInfo?.msg); |
| 366 | return; | 367 | return; |
| ... | @@ -379,7 +380,7 @@ const downloadTemplate = async (url) => { | ... | @@ -379,7 +380,7 @@ const downloadTemplate = async (url) => { |
| 379 | 380 | ||
| 380 | const onUploadFileDownload = async (file, item) => { | 381 | const onUploadFileDownload = async (file, item) => { |
| 381 | let url = file.url; | 382 | let url = file.url; |
| 382 | const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(url).decodedPath); | 383 | const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(url).fileName); |
| 383 | if (!refSignInfo?.data) { | 384 | if (!refSignInfo?.data) { |
| 384 | refSignInfo?.msg && ElMessage.error(refSignInfo?.msg); | 385 | refSignInfo?.msg && ElMessage.error(refSignInfo?.msg); |
| 385 | return; | 386 | return; | ... | ... |
| ... | @@ -129,19 +129,19 @@ const tableBtnClick = async (scope, btn) => { | ... | @@ -129,19 +129,19 @@ const tableBtnClick = async (scope, btn) => { |
| 129 | rowData.value = row | 129 | rowData.value = row |
| 130 | currTableData.value = row; | 130 | currTableData.value = row; |
| 131 | if (type == 'view') { | 131 | if (type == 'view') { |
| 132 | const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(row.analysisReportUrl).decodedPath); | 132 | let fileName: string = parseAndDecodeUrl(row.analysisReportUrl).fileName; |
| 133 | const refSignInfo: any = await getDownFileSignByUrl(fileName); | ||
| 133 | if (!refSignInfo?.data) { | 134 | if (!refSignInfo?.data) { |
| 134 | refSignInfo?.msg && ElMessage.error(refSignInfo?.msg); | 135 | refSignInfo?.msg && ElMessage.error(refSignInfo?.msg); |
| 135 | return; | 136 | return; |
| 136 | } | 137 | } |
| 137 | obsDownloadRequest(refSignInfo?.data).then((res: any) => { | 138 | obsDownloadRequest(refSignInfo?.data).then((res: any) => { |
| 138 | if (res && !res.msg) { | 139 | if (res && !res.msg) { |
| 139 | let name = row.analysisReportUrl; | 140 | var fileSuffix = fileName ? fileName.substring(fileName.lastIndexOf('.') + 1) : ''; |
| 140 | var fileSuffix = name ? name.substring(name.lastIndexOf('.') + 1) : ''; | ||
| 141 | if (fileSuffix === 'png') { //浏览器可以支持图片和pdf预览 | 141 | if (fileSuffix === 'png') { //浏览器可以支持图片和pdf预览 |
| 142 | let fileUrl = <string>getDownloadUrl(res, name, fileSuffix); | 142 | let fileUrl = <string>getDownloadUrl(res, name, fileSuffix); |
| 143 | let win = window.open(fileUrl, name); | 143 | let win = window.open(fileUrl, row.analysisReportName + fileSuffix); |
| 144 | win && (win.document.title = name); | 144 | win && (win.document.title = row.analysisReportName + fileSuffix); |
| 145 | } else { | 145 | } else { |
| 146 | download(res, row.analysisReportName, fileSuffix); | 146 | download(res, row.analysisReportName, fileSuffix); |
| 147 | } | 147 | } |
| ... | @@ -150,15 +150,16 @@ const tableBtnClick = async (scope, btn) => { | ... | @@ -150,15 +150,16 @@ const tableBtnClick = async (scope, btn) => { |
| 150 | } | 150 | } |
| 151 | }); | 151 | }); |
| 152 | } else if (type == 'export') { | 152 | } else if (type == 'export') { |
| 153 | const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(row.analysisReportUrl).decodedPath); | 153 | let fileName: string = parseAndDecodeUrl(row.analysisReportUrl).fileName; |
| 154 | const refSignInfo: any = await getDownFileSignByUrl(fileName); | ||
| 154 | if (!refSignInfo?.data) { | 155 | if (!refSignInfo?.data) { |
| 155 | refSignInfo?.msg && ElMessage.error(refSignInfo?.msg); | 156 | refSignInfo?.msg && ElMessage.error(refSignInfo?.msg); |
| 156 | return; | 157 | return; |
| 157 | } | 158 | } |
| 158 | obsDownloadRequest(refSignInfo?.data).then((res: any) => { | 159 | obsDownloadRequest(refSignInfo?.data).then((res: any) => { |
| 159 | if (res && !res.msg) { | 160 | if (res && !res.msg) { |
| 160 | let name = row.analysisReportUrl; | 161 | // let name = row.analysisReportUrl; |
| 161 | var fileSuffix = name ? name.substring(name.lastIndexOf('.') + 1) : ''; | 162 | var fileSuffix = fileName ? fileName.substring(fileName.lastIndexOf('.') + 1) : ''; |
| 162 | download(res, row.analysisReportName, fileSuffix); | 163 | download(res, row.analysisReportName, fileSuffix); |
| 163 | } else { | 164 | } else { |
| 164 | res?.msg && ElMessage.error(res?.msg); | 165 | res?.msg && ElMessage.error(res?.msg); | ... | ... |
| ... | @@ -221,7 +221,7 @@ const tableBtnClick = async (scope, btn) => { | ... | @@ -221,7 +221,7 @@ const tableBtnClick = async (scope, btn) => { |
| 221 | const row = scope.row; | 221 | const row = scope.row; |
| 222 | currTableData.value = row; | 222 | currTableData.value = row; |
| 223 | if (type == "export_file") { | 223 | if (type == "export_file") { |
| 224 | const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(row.filePath).decodedPath); | 224 | const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(row.filePath).fileName); |
| 225 | if (!refSignInfo?.data) { | 225 | if (!refSignInfo?.data) { |
| 226 | refSignInfo?.msg && ElMessage.error(refSignInfo?.msg); | 226 | refSignInfo?.msg && ElMessage.error(refSignInfo?.msg); |
| 227 | return; | 227 | return; |
| ... | @@ -236,7 +236,7 @@ const tableBtnClick = async (scope, btn) => { | ... | @@ -236,7 +236,7 @@ const tableBtnClick = async (scope, btn) => { |
| 236 | //downFile(row.filePath, row.fileName) | 236 | //downFile(row.filePath, row.fileName) |
| 237 | } else if (type == 'export_abnormal_data') { | 237 | } else if (type == 'export_abnormal_data') { |
| 238 | //downFile(row.errorFilePath, '') | 238 | //downFile(row.errorFilePath, '') |
| 239 | const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(row.errorFilePath).decodedPath); | 239 | const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(row.errorFilePath).fileName); |
| 240 | if (!refSignInfo?.data) { | 240 | if (!refSignInfo?.data) { |
| 241 | refSignInfo?.msg && ElMessage.error(refSignInfo?.msg); | 241 | refSignInfo?.msg && ElMessage.error(refSignInfo?.msg); |
| 242 | return; | 242 | return; | ... | ... |
-
Please register or sign in to post a comment