diff --git a/acupuncture-前台/src/main.js b/acupuncture-前台/src/main.js index 1fa0ce5d..95bdd829 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 faa87275..0f4920a7 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 ea184336..59652b18 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" > - +