b4f46b1b by lihua

解决文件下载问题

1 parent 9bca7e98
......@@ -23,6 +23,7 @@ export const parseAndDecodeUrl = (url:string) => {
// 返回去掉主机信息和开头斜杠后的解码部分以及最后一个斜杠后面的内容
return {
fileName: pathname,
decodedPath: pathname + search + hash,
lastPart: lastPart
};
......
......@@ -337,7 +337,8 @@ const handlePictureCardPreview = (file, item) => {
const onUploadFilePreview = async (file, item) => {
let f = formInline.value[item.field].find(i => i.name == file.name);
let url = f.url;
const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(url).decodedPath);
let fileName: string = parseAndDecodeUrl(url).fileName;
const refSignInfo: any = await getDownFileSignByUrl(fileName);
if (!refSignInfo?.data) {
refSignInfo?.msg && ElMessage.error(refSignInfo?.msg);
return;
......@@ -360,7 +361,7 @@ const onUploadFilePreview = async (file, item) => {
}
const downloadTemplate = async (url) => {
const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(url).decodedPath);
const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(url).fileName);
if (!refSignInfo?.data) {
refSignInfo?.msg && ElMessage.error(refSignInfo?.msg);
return;
......@@ -379,7 +380,7 @@ const downloadTemplate = async (url) => {
const onUploadFileDownload = async (file, item) => {
let url = file.url;
const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(url).decodedPath);
const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(url).fileName);
if (!refSignInfo?.data) {
refSignInfo?.msg && ElMessage.error(refSignInfo?.msg);
return;
......
......@@ -129,19 +129,19 @@ const tableBtnClick = async (scope, btn) => {
rowData.value = row
currTableData.value = row;
if (type == 'view') {
const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(row.analysisReportUrl).decodedPath);
let fileName: string = parseAndDecodeUrl(row.analysisReportUrl).fileName;
const refSignInfo: any = await getDownFileSignByUrl(fileName);
if (!refSignInfo?.data) {
refSignInfo?.msg && ElMessage.error(refSignInfo?.msg);
return;
}
obsDownloadRequest(refSignInfo?.data).then((res: any) => {
if (res && !res.msg) {
let name = row.analysisReportUrl;
var fileSuffix = name ? name.substring(name.lastIndexOf('.') + 1) : '';
var fileSuffix = fileName ? fileName.substring(fileName.lastIndexOf('.') + 1) : '';
if (fileSuffix === 'png') { //浏览器可以支持图片和pdf预览
let fileUrl = <string>getDownloadUrl(res, name, fileSuffix);
let win = window.open(fileUrl, name);
win && (win.document.title = name);
let win = window.open(fileUrl, row.analysisReportName + fileSuffix);
win && (win.document.title = row.analysisReportName + fileSuffix);
} else {
download(res, row.analysisReportName, fileSuffix);
}
......@@ -150,15 +150,16 @@ const tableBtnClick = async (scope, btn) => {
}
});
} else if (type == 'export') {
const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(row.analysisReportUrl).decodedPath);
let fileName: string = parseAndDecodeUrl(row.analysisReportUrl).fileName;
const refSignInfo: any = await getDownFileSignByUrl(fileName);
if (!refSignInfo?.data) {
refSignInfo?.msg && ElMessage.error(refSignInfo?.msg);
return;
}
obsDownloadRequest(refSignInfo?.data).then((res: any) => {
if (res && !res.msg) {
let name = row.analysisReportUrl;
var fileSuffix = name ? name.substring(name.lastIndexOf('.') + 1) : '';
// let name = row.analysisReportUrl;
var fileSuffix = fileName ? fileName.substring(fileName.lastIndexOf('.') + 1) : '';
download(res, row.analysisReportName, fileSuffix);
} else {
res?.msg && ElMessage.error(res?.msg);
......
......@@ -221,7 +221,7 @@ const tableBtnClick = async (scope, btn) => {
const row = scope.row;
currTableData.value = row;
if (type == "export_file") {
const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(row.filePath).decodedPath);
const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(row.filePath).fileName);
if (!refSignInfo?.data) {
refSignInfo?.msg && ElMessage.error(refSignInfo?.msg);
return;
......@@ -236,7 +236,7 @@ const tableBtnClick = async (scope, btn) => {
//downFile(row.filePath, row.fileName)
} else if (type == 'export_abnormal_data') {
//downFile(row.errorFilePath, '')
const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(row.errorFilePath).decodedPath);
const refSignInfo: any = await getDownFileSignByUrl(parseAndDecodeUrl(row.errorFilePath).fileName);
if (!refSignInfo?.data) {
refSignInfo?.msg && ElMessage.error(refSignInfo?.msg);
return;
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!