From 131163330c64292f77d8f073e04ca58d9fc49398 Mon Sep 17 00:00:00 2001 From: "1747191978@qq.com" <1942943850@qq.com> Date: Tue, 18 Feb 2025 14:40:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E5=87=BD=E6=95=B0=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- acupuncture-前台/src/main.js | 3 +- acupuncture-前台/src/utils/request.js | 33 +++++++++++++++ .../src/views/patientFile/index.vue | 42 +++++++++++++------ 3 files changed, 64 insertions(+), 14 deletions(-) diff --git a/acupuncture-前台/src/main.js b/acupuncture-前台/src/main.js index 1fa0ce5d8..95bdd8292 100644 --- a/acupuncture-前台/src/main.js +++ b/acupuncture-前台/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, download1} from '@/utils/request' import moment from 'moment'; import './assets/icons' // icon @@ -48,6 +48,7 @@ Vue.prototype.addDateRange = addDateRange Vue.prototype.selectDictLabel = selectDictLabel Vue.prototype.selectDictLabels = selectDictLabels Vue.prototype.download = download +Vue.prototype.download1 = download1 Vue.prototype.handleTree = handleTree Vue.prototype.$moment = moment diff --git a/acupuncture-前台/src/utils/request.js b/acupuncture-前台/src/utils/request.js index faa87275e..0f4920a7d 100644 --- a/acupuncture-前台/src/utils/request.js +++ b/acupuncture-前台/src/utils/request.js @@ -148,5 +148,38 @@ export function download(url, params, filename, config) { downloadLoadingInstance.close(); }) } +// 通用下载方法 +export function download1(url, params, filename, config) { + downloadLoadingInstance = Loading.service({ + text: "正在下载数据,请稍候", + spinner: "el-icon-loading", + background: "rgba(0, 0, 0, 0.7)", + }); + return service + .post(url, params, { + headers: { "Content-Type": "application/json;charset=utf-8" }, + + responseType: "blob", + }) + .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/acupuncture-前台/src/views/patientFile/index.vue b/acupuncture-前台/src/views/patientFile/index.vue index ea184336c..59652b18d 100644 --- a/acupuncture-前台/src/views/patientFile/index.vue +++ b/acupuncture-前台/src/views/patientFile/index.vue @@ -33,7 +33,7 @@ /> - + 下载模版 @@ -133,13 +133,14 @@ max-height="600" > - +