From 481df58681b39ad056f80a06904284f2cdab9b41 Mon Sep 17 00:00:00 2001
From: MO <448233645@qq.com>
Date: Thu, 9 Nov 2023 17:33:05 +0800
Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=8B=E8=BD=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/main.js | 2 ++
src/utils/request.js | 15 +++++++++++++++
src/views/accounting/book/index.vue | 2 +-
src/views/accounting/report/index.vue | 11 +++++++++++
4 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/src/main.js b/src/main.js
index 1577aa47..2f48900c 100644
--- a/src/main.js
+++ b/src/main.js
@@ -10,6 +10,7 @@ import store from './store'
import router from './router'
import directive from './directive' // directive
import plugins from './plugins' // plugins
+import { download } from '@/utils/request'
import './assets/icons' // icon
import './permission' // permission control
@@ -39,6 +40,7 @@ Vue.prototype.DICT_TYPE = DICT_TYPE
Vue.prototype.handleTree = handleTree
Vue.prototype.addBeginAndEndTime = addBeginAndEndTime
Vue.prototype.divide = divide
+Vue.prototype.download = download
// 全局组件挂载
diff --git a/src/utils/request.js b/src/utils/request.js
index a501686c..8f94c094 100644
--- a/src/utils/request.js
+++ b/src/utils/request.js
@@ -196,4 +196,19 @@ function handleAuthorized() {
return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
}
+export function download(url, filename) {
+ const x = new window.XMLHttpRequest();
+ x.open('GET', url, true);
+ x.responseType = 'blob';
+ x.onload = () => {
+ let time = new Date().toLocaleDateString();
+ const url = window.URL.createObjectURL(x.response);
+ const a = document.createElement('a');
+ a.href = url;
+ a.download = filename ;
+ a.click();
+ };
+ x.send();
+}
+
export default service
diff --git a/src/views/accounting/book/index.vue b/src/views/accounting/book/index.vue
index 6e769cdd..cfd2b627 100644
--- a/src/views/accounting/book/index.vue
+++ b/src/views/accounting/book/index.vue
@@ -617,7 +617,7 @@ export default {
},
// 下载
handleDownload(row) {
- window.open(row.uri);
+ this.download(row.uri, row.name);
},
/** 提交按钮 */
submitForm() {
diff --git a/src/views/accounting/report/index.vue b/src/views/accounting/report/index.vue
index 027fee19..846a733c 100644
--- a/src/views/accounting/report/index.vue
+++ b/src/views/accounting/report/index.vue
@@ -178,6 +178,13 @@
@click="handleView(scope.row)"
>查看
+ 下载