更换下载方式
This commit is contained in:
parent
a75b47c218
commit
0bcc07119e
|
@ -74,6 +74,7 @@
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
import { exportFileLstApi, excelFileType } from "@/api/order";
|
import { exportFileLstApi, excelFileType } from "@/api/order";
|
||||||
|
import axios from 'axios';
|
||||||
export default {
|
export default {
|
||||||
name: "FileList",
|
name: "FileList",
|
||||||
data() {
|
data() {
|
||||||
|
@ -126,14 +127,33 @@ export default {
|
||||||
|
|
||||||
},
|
},
|
||||||
// 下载
|
// 下载
|
||||||
downLoad(path) {
|
// downLoad(path) {
|
||||||
// window.open(path)
|
// // window.open(path)
|
||||||
const fileUrl = path; // 替换为实际的文件 URL
|
// const fileUrl = path; // 替换为实际的文件 URL
|
||||||
const link = document.createElement('a');
|
// const link = document.createElement('a');
|
||||||
link.href = fileUrl;
|
// link.href = fileUrl;
|
||||||
document.body.appendChild(link);
|
// document.body.appendChild(link);
|
||||||
link.click();
|
// link.click();
|
||||||
document.body.removeChild(link);
|
// document.body.removeChild(link);
|
||||||
|
// },
|
||||||
|
// 下载
|
||||||
|
async downLoad(path) {
|
||||||
|
try {
|
||||||
|
const response = await axios.get(path, {
|
||||||
|
responseType: 'blob'
|
||||||
|
});
|
||||||
|
const url = window.URL.createObjectURL(new Blob([response.data]));
|
||||||
|
const a = document.createElement('a');
|
||||||
|
a.href = url;
|
||||||
|
a.download = path.split('/').pop(); // 使用路径的最后一部分作为文件名
|
||||||
|
document.body.appendChild(a);
|
||||||
|
a.click();
|
||||||
|
document.body.removeChild(a);
|
||||||
|
window.URL.revokeObjectURL(url);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('下载错误:', error);
|
||||||
|
this.$message.error('文件下载失败');
|
||||||
|
}
|
||||||
},
|
},
|
||||||
pageChange(page) {
|
pageChange(page) {
|
||||||
this.tableFrom.page = page;
|
this.tableFrom.page = page;
|
||||||
|
|
Loading…
Reference in New Issue