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)" >查看 + 下载