From 6dcf7aae60e26d15eda4f5ff95a353b75f705fab Mon Sep 17 00:00:00 2001 From: zhouzy062 Date: Thu, 7 Mar 2024 13:31:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=B9=E7=94=A8=E7=BB=93=E7=AE=97=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=8E=A5=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sgzb-ui/src/main.js | 3 +- sgzb-ui/src/utils/request.js | 26 +++++++++++++ .../cost/csotSettlement/costApplyAdd.vue | 38 ++++++++++++++----- .../views/cost/csotSettlement/costExame.vue | 38 ++++++++++++++----- 4 files changed, 84 insertions(+), 21 deletions(-) diff --git a/sgzb-ui/src/main.js b/sgzb-ui/src/main.js index 52a726e8..95523e37 100644 --- a/sgzb-ui/src/main.js +++ b/sgzb-ui/src/main.js @@ -12,7 +12,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 { download,downloadCost } from '@/utils/request' import './assets/icons' // icon import './permission' // permission control @@ -48,6 +48,7 @@ Vue.prototype.addDateRange = addDateRange Vue.prototype.selectDictLabel = selectDictLabel Vue.prototype.selectDictLabels = selectDictLabels Vue.prototype.download = download +Vue.prototype.downloadCost = downloadCost Vue.prototype.handleTree = handleTree // 全局组件挂载 diff --git a/sgzb-ui/src/utils/request.js b/sgzb-ui/src/utils/request.js index f09c940a..cf22e1fb 100644 --- a/sgzb-ui/src/utils/request.js +++ b/sgzb-ui/src/utils/request.js @@ -149,4 +149,30 @@ export function download(url, params, filename, config) { }) } +// 通用下载方法 +export function downloadCost(url, params, filename, config) { + downloadLoadingInstance = Loading.service({ text: "正在下载数据,请稍候", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)", }) + return service.post(url, params, { + transformRequest: [(params) => { return params }], + headers: { 'Content-Type': 'application/json' }, + responseType: 'blob', + ...config + }).then(async (data) => { + const isBlob = blobValidate(data); + if (isBlob) { + const blob = new Blob([data]) + saveAs(blob, filename) + } else { + const resText = await data.text(); + const rspObj = JSON.parse(resText); + const errMsg = errorCode[rspObj.code] || rspObj.msg || errorCode['default'] + Message.error(errMsg); + } + downloadLoadingInstance.close(); + }).catch((r) => { + console.error(r) + Message.error('下载文件出现错误,请联系管理员!') + downloadLoadingInstance.close(); + }) +} export default service diff --git a/sgzb-ui/src/views/cost/csotSettlement/costApplyAdd.vue b/sgzb-ui/src/views/cost/csotSettlement/costApplyAdd.vue index a8723d78..6bea5c0e 100644 --- a/sgzb-ui/src/views/cost/csotSettlement/costApplyAdd.vue +++ b/sgzb-ui/src/views/cost/csotSettlement/costApplyAdd.vue @@ -3,11 +3,11 @@ - 租赁明细导出 - 丢失明细导出 - 维修明细导出 - 报废明细导出 - 全部明细导出 + 租赁明细导出 + 丢失明细导出 + 维修明细导出 + 报废明细导出 + 全部明细导出 提交 @@ -158,7 +158,7 @@