提交 9053926b 编写于 作者: lzlhxj's avatar lzlhxj

修改下载时文件名中文乱码

上级 e8095860
......@@ -68,6 +68,8 @@
<!-- 自定义弹框 -->
<div class="dialogDiv">
<el-dialog
:title="dialogTitle"
center
width="70%"
top="5vh"
:visible="showDialog"
......@@ -245,23 +247,40 @@
*/
public isCreate: boolean = true;
/**
* 自定义弹框标题
*
* @type {*}
* @memberof DiskFileUpload
*/
public dialogTitle: any = '';
/**
* 是否显示自定义弹框
*
* @type {boolean}
* @memberof DiskFileUpload
*/
public showDialog = false;
public showDialog: boolean = false;
/**
* 嵌入自定义弹框中iframe的url
*
* @type {*}
* @memberof DiskFileUpload
*/
public iframeUrl: any = '';
/**
* 关闭自定义弹框
*
* @memberof DiskFileUpload
*/
public dialogClose() {
this.dialogTitle = '';
this.showDialog = false;
this.iframeUrl = '';
let iframe:any = document.getElementById("fileIframe");
let iframe: any = document.getElementById("fileIframe");
iframe.parentNode.removeChild("fileIframe");
}
......@@ -302,7 +321,7 @@
}
/**
*
* vue创建
*
* @memberof DiskFileUpload
*/
......@@ -334,7 +353,7 @@
if (Object.is($event.type, 'save')) {
// 批量更新文件表中的ownerid
if (this.isUpdateBatch == true && this.uploadFileList.length > 0) {
this.updateFileBatch(this.uploadFileList, 'update');
this.updateFileBatch(this.uploadFileList);
}
}
});
......@@ -355,7 +374,7 @@
ownertype: this.getOwnertype(),
ownerid: this.getOwnerid(),
},
}).then(response => {
}).then((response: any) => {
if (!response || response.status != 200) {
Message.error(_this.$t('components.diskFileUpload.getFileFailure') + '!');
return;
......@@ -367,7 +386,7 @@
this.uploadFileList.push.apply(this.uploadFileList, files);
}
}
}).catch(error => {
}).catch((error: any) => {
Message.error(_this.$t('components.diskFileUpload.getFileFailure') + ':' + error);
});
}
......@@ -388,7 +407,7 @@
// 拼接url
const uploadUrl = this.getAction();
// 发送post请求
Axios.post(uploadUrl, formData, {timeout: 2000}).then(response => {
Axios.post(uploadUrl, formData, {timeout: 2000}).then((response: any) => {
if (!response || response.status != 200) {
Message.error(_this.$t('components.diskFileUpload.loadFailure') + '!');
}
......@@ -406,8 +425,8 @@
this.$emit('formitemvaluechange', {name: this.formItemName, value: value});
}
}
}).catch(err => {
Message.error(_this.$t('components.diskFileUpload.loadFailure') + ':' + err);
}).catch((error: any) => {
Message.error(_this.$t('components.diskFileUpload.loadFailure') + ':' + error);
})
}
......@@ -426,10 +445,10 @@
// 发送get请求
Axios.get(downloadUrl, {
headers: {
'authcode': item.authcode
'authcode': item.authcode,
},
responseType: 'arraybuffer',
}).then(response => {
}).then((response: any) => {
if (!response || response.status != 200) {
Message.error(_this.$t('components.diskFileUpload.downloadFile') + '!');
return;
......@@ -440,13 +459,17 @@
const disposition = response.headers['content-disposition'];
const filename = disposition.split('filename=')[1];
// 用blob对象获取文件流
var blob = new Blob([response.data], {type: response.headers['content-type']});
// 创建下载链接
let blob = new Blob([response.data], {type: response.headers['content-type']});
// 通过文件流创建下载链接
var href = URL.createObjectURL(blob);
// 创建一个a元素并设置相关属性
var a = document.createElement('a');
let a = document.createElement('a');
a.href = href;
a.download = filename;
if (name) {
a.download = name;
}else {
a.download = filename;
}
// 添加a元素到当前网页
document.body.appendChild(a);
// 触发a元素的点击事件,实现下载
......@@ -458,7 +481,7 @@
} else {
Message.error(_this.$t('components.diskFileUpload.downloadFile1'));
}
}).catch(error => {
}).catch((error: any) => {
Message.error(_this.$t('components.diskFileUpload.downloadFile') + ':' + error);
});
}
......@@ -475,6 +498,7 @@
const name = typeof item.name == "string" ? item.name : JSON.stringify(item.name);
const previewUrl = '/net-disk/preview/' + this.getFolder() + '/' + id + '/' + name + '?authcode=' + item.authcode;
// 自定义弹框打开url
this.dialogTitle = name;
this.showDialog = true;
this.iframeUrl = previewUrl;
}
......@@ -506,6 +530,7 @@
const name = typeof item.name == "string" ? item.name : JSON.stringify(item.name);
const ocrUrl = '/net-disk/ocrview/' + this.getFolder() + '/' + id + '/' + name + '?authcode=' + item.authcode;
// 自定义弹框打开url
this.dialogTitle = name;
this.showDialog = true;
this.iframeUrl = ocrUrl;
}
......@@ -528,7 +553,7 @@
// 拼接url
const deleteUrl = '/net-disk/files/' + item.id;
// 发送delete请求
Axios.delete(deleteUrl).then(response => {
Axios.delete(deleteUrl).then((response: any) => {
if (!response || response.status != 200) {
Message.error(_this.$t('components.diskFileUpload.deleteFileFailure') + '!');
}
......@@ -539,7 +564,7 @@
const value = JSON.stringify(this.uploadFileList);
this.$emit('formitemvaluechange', {name: this.formItemName, value: value});
}
}).catch(error => {
}).catch((error: any) => {
// 提示删除失败
Message.error(_this.$t('components.diskFileUpload.deleteFileFailure') + ':' + error);
});
......@@ -552,7 +577,7 @@
*
* @memberof DiskFileUpload
*/
public updateFileBatch(files: any, opt: any) {
public updateFileBatch(files: any) {
let _this: any = this;
// 拼接url
const updateUrl = '/net-disk/files/' + this.getFolder() + '?ownertype=' + this.getOwnertype() + "&ownerid=" + this.getOwnerid();
......@@ -567,12 +592,12 @@
"Content-Type": "application/json;charset=UTF-8"
},
timeout: 2000
}).then(response => {
}).then((response: any) => {
if (!response || response.status != 200) {
Message.error(_this.$t('components.diskFileUpload.updateFailure') + '!');
return;
}
}).catch(error => {
}).catch((error: any) => {
Message.error(_this.$t('components.diskFileUpload.updateFailure') + ':' + error);
});
}
......@@ -629,11 +654,12 @@
margin-left: 10px;
}
.dialogDiv{
.dialogDiv {
// el-dialog头部
.el-dialog__header{
height:40px;
.el-dialog__header {
height: 40px;
}
// el-dialog面板
.el-dialog__wrapper {
height: 90vh;
......@@ -649,7 +675,8 @@
.el-dialog__body {
height: inherit;
}
#fileIframe{
#fileIframe {
height: calc(100% - 40px);
}
}
......
......@@ -45,6 +45,8 @@
<!-- 自定义弹框 -->
<div class="dialogDiv">
<el-dialog
:title="dialogTitle"
center
width="70%"
top="5vh"
:visible="showDialog"
......@@ -231,23 +233,40 @@
*/
public imageFileids: Array<any> = [];
/**
* 自定义弹框标题
*
* @type {*}
* @memberof DiskImageUplaod
*/
public dialogTitle: any = '';
/**
* 是否显示自定义弹框
*
* @type {boolean}
* @memberof DiskImageUplaod
*/
public showDialog = false;
public showDialog: boolean = false;
/**
* 嵌入自定义弹框中iframe的url
*
* @type {*}
* @memberof DiskImageUplaod
*/
public iframeUrl: any = '';
/**
* 关闭自定义弹框
*
* @memberof DiskImageUplaod
*/
public dialogClose() {
this.dialogTitle = '';
this.showDialog = false;
this.iframeUrl = '';
let iframe:any = document.getElementById("fileIframe");
let iframe: any = document.getElementById("fileIframe");
iframe.parentNode.removeChild("fileIframe");
}
......@@ -288,7 +307,7 @@
}
/**
* vue生命周期create
* vue创建
*
* @memberof DiskImageUplaod
*/
......@@ -344,7 +363,7 @@
ownertype: this.getOwnertype(),
ownerid: this.getOwnerid(),
},
}).then(response => {
}).then((response: any) => {
if (!response || response.status != 200) {
Message.error(_this.$t('components.diskImageUpload.getImageFailure') + "!");
return;
......@@ -361,7 +380,7 @@
});
}
}
}).catch(error => {
}).catch((error: any) => {
Message.error(_this.$t('components.diskImageUpload.getImageFailure') + ':' + error);
});
}
......@@ -382,14 +401,14 @@
'authcode': fileData.authcode
},
responseType: 'blob',
}).then(res => {
if (!res || res.status != 200) {
}).then((response: any) => {
if (!response || response.status != 200) {
Message.error(_this.$t('components.diskImageUpload.loadImageFailure') + '!');
}
// 请求成功,后台返回的是一个文件流
if (res.data) {
if (response.data) {
// 用blob对象获取文件流
var blob = new Blob([res.data], {type: res.headers['content-type']});
var blob = new Blob([response.data], {type: response.headers['content-type']});
// 通过文件流创建下载链接
var href = URL.createObjectURL(blob);
// 将下载链接保存到图片中
......@@ -408,7 +427,7 @@
} else {
Message.error(_this.$t('components.diskImageUpload.loadImageFailure1'));
}
}).catch(error => {
}).catch((error: any) => {
Message.error(_this.$t('components.diskImageUpload.loadImageFailure') + ':' + error);
});
}
......@@ -442,7 +461,7 @@
// 拼接url
const uploadUrl = this.getAction();
// 发送post请求
Axios.post(uploadUrl, formData, {timeout: 2000}).then(response => {
Axios.post(uploadUrl, formData, {timeout: 2000}).then((response: any) => {
if (!response || response.status != 200) {
Message.error(_this.$t('components.diskImageUpload.uploadImageFailure') + "!");
}
......@@ -457,15 +476,15 @@
'authcode': returnData.authcode
},
responseType: 'blob',
}).then(res => {
if (!res || res.status != 200) {
}).then((response2) => {
if (!response2 || response2.status != 200) {
Message.error(_this.$t('components.diskImageUpload.loadImageFailure') + "!");
return;
}
// 请求成功,后台返回的是一个文件流
if (res.data) {
if (response2.data) {
// 用blob对象获取文件流
var blob = new Blob([res.data], {type: res.headers['content-type']});
var blob = new Blob([response2.data], {type: response2.headers['content-type']});
// 通过文件流创建下载链接
var href = URL.createObjectURL(blob);
// 将下载链接保存到本次上传成功后返回的jsonobject中
......@@ -493,12 +512,12 @@
} else {
Message.error(_this.$t('components.diskImageUpload.loadImageFailure1'));
}
}).catch(error => {
Message.error(_this.$t('components.diskImageUpload.loadImageFailure') + ':' + error);
}).catch((error2: any) => {
Message.error(_this.$t('components.diskImageUpload.loadImageFailure') + ':' + error2);
});
}
}).catch(err => {
Message.error(_this.$t('components.diskImageUpload.uploadImageFailure') + ':' + err);
}).catch((error: any) => {
Message.error(_this.$t('components.diskImageUpload.uploadImageFailure') + ':' + error);
});
}
......@@ -529,6 +548,7 @@
const name = typeof file.name == "string" ? file.name : JSON.stringify(file.name);
const ocrUrl = '/net-disk/ocrview/' + this.getFolder() + '/' + id + '/' + name + '?authcode=' + file.authcode;
// 自定义弹框打开url
this.dialogTitle = name;
this.showDialog = true;
this.iframeUrl = ocrUrl;
}
......@@ -550,7 +570,7 @@
'authcode': file.authcode
},
responseType: 'blob',
}).then(response => {
}).then((response: any) => {
if (!response || response.status != 200) {
Message.error(_this.$t('components.diskImageUpload.loadImageFailure2') + '!');
return;
......@@ -567,7 +587,11 @@
// 创建一个a元素并设置相关属性
var a = document.createElement('a');
a.href = href;
a.download = filename;
if (name) {
a.download = name;
}else {
a.download = filename;
}
// 添加a元素到当前网页
document.body.appendChild(a);
// 触发a元素的点击事件,实现下载
......@@ -579,7 +603,7 @@
} else {
Message.error(_this.$t('components.diskImageUpload.loadImageFailure3'));
}
}).catch(error => {
}).catch((error: any) => {
Message.error(_this.$t('components.diskImageUpload.loadImageFailure2') + ':' + error);
});
}
......@@ -604,7 +628,7 @@
// 拼接url
const deleteUrl = '/net-disk/files/' + file.id;
// 发送delete请求
Axios.delete(deleteUrl).then(response => {
Axios.delete(deleteUrl).then((response: any) => {
if (!response || response.status != 200) {
Message.error(_this.$t('components.diskImageUpload.deleteImageFailure') + '!');
}
......@@ -617,7 +641,7 @@
const value = JSON.stringify(this.imageList);
this.$emit('formitemvaluechange', {name: this.formItemName, value: value});
}
}).catch(error => {
}).catch((error: any) => {
// 提示删除失败
Message.error(_this.$t('components.diskImageUpload.deleteImageFailure') + ':' + error);
});
......@@ -647,12 +671,12 @@
"Content-Type": "application/json;charset=UTF-8"
},
timeout: 2000
}).then(response => {
}).then((response: any) => {
if (!response || response.status != 200) {
Message.error(_this.$t('components.diskImageUpload.updateFailure') + '!');
return;
}
}).catch(error => {
}).catch((error: any) => {
Message.error(_this.$t('components.diskImageUpload.updateFailure') + ':' + error);
});
}
......@@ -684,6 +708,7 @@
height: inherit;
}
// iframe
#fileIframe {
height: calc(100% - 40px);
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册