Răsfoiți Sursa

登记簿批量导出代码提交

jingyuanchao 1 an în urmă
părinte
comite
2d40128732

+ 9 - 5
src/api/registerbook/registerBook.js

@@ -1,4 +1,6 @@
 import request from '@/utils/request'
+import {exportFile} from '@/utils/request'
+import {download} from '@/utils/request'
 
 // 查询列表registerBook
 export function listRegisterBook(query) {
@@ -45,9 +47,11 @@ export function delRegisterBook(id) {
 
 // 勾选下载
 export function selectExport(data) {
-  return request({
-    url: '/core/registerBook/batch/export',
-    method: 'post',
-    data: data
-  })
+  return exportFile(
+     '/core/registerBook/batch/export',
+     data,
+     'post',
+    null,
+    null,
+  )
 }

+ 81 - 0
src/utils/request.js

@@ -126,7 +126,88 @@ let error = error => {
 
 // 响应拦截器
 service.interceptors.response.use(success,error)
+export function exportFile(
+  url,
+  request,
+  method,
+  onDownloadProgressCallBack,
+  exceptionCallBack
+) {
+  const headers = {
+    //"content-type": "application/vnd.ms-excel",
+  };
 
+  service
+    .request({
+      url,
+      method,
+      data: request,
+      responseType: "blob",
+      headers,
+      onDownloadProgress: onDownloadProgressCallBack,
+    })
+    .then((response) => {
+      if (loading) loading.close();
+      const data = response.data;
+
+   /*   if (!data) {
+        Message.warning("文件下载失败");
+        exceptionCallBack("文件下载失败");
+        return;
+      } else if (data.type === "application/json") {
+        data.text().then((t) => {
+          let r = JSON.parse(t);
+          if (r.result === "000001") {
+            if(exceptionCallBack)
+            {
+              exceptionCallBack(r.error);
+            }else{
+              Message.warning(r.error);
+            }
+          }
+        });
+        return;
+      }*/
+      debugger
+    /*  let cd = response.headers["content-disposition"];
+      let fileName = "未知";
+      if (cd) {
+        fileName = decodeURIComponent(
+          response.headers["content-disposition"].split("=")[1]
+        );
+      }*/
+      let fileName="1231231231.zip";
+      if (typeof window.navigator.msSaveBlob !== "undefined") {
+        window.navigator.msSaveBlob(
+          response,
+          fileName
+        );
+      } else {
+        const url = window.URL.createObjectURL(
+          response,
+        );
+        const link = document.createElement("a");
+        link.style.display = "none";
+        link.href = url;
+        link.setAttribute("download", fileName);
+        document.body.appendChild(link);
+        link.click();
+        document.body.removeChild(link); // 下载完成移除元素
+        window.URL.revokeObjectURL(url); // 释放掉blob对象
+        if(fileName=="未知") {
+          exceptionCallBack("后端接口返回异常,文件下载失败");
+        }
+      }
+    })
+    .catch(function(err) {
+      if (loading) loading.close();
+      console.log("exportFile catch",err);
+      if(exceptionCallBack)
+      {
+        exceptionCallBack(err);
+      }
+    });
+}
 // 通用下载方法
 export function download(url, params, filename, config) {
   downloadLoadingInstance = Loading.service({ text: "正在下载数据,请稍候", spinner: "el-icon-loading", background: "rgba(0, 0, 0, 0.7)", })

+ 10 - 1
src/views/registerBook/index.vue

@@ -169,6 +169,7 @@ import tableList from "@/mixins/tableList";
 import DownListDialog from "./dialog.list";
 import OrgTree from "@/components/orgTree";
 import {guid} from "@/utils";
+import dayjs from "dayjs";
 
 export default {
   name: "RegisterBook",
@@ -300,7 +301,15 @@ export default {
       }
       let pdfIdList=this.ids;
       this.queryParams.exportType = 1;
-      selectExport({...this.queryParams, pdfIdList});
+      let fileName=`登记簿-${dayjs(new Date()).format("YYYYMMDD")}.zip`;
+      console.log("fileName",fileName)
+      console.log("this.queryParams",this.queryParams)
+      await selectExport({...this.queryParams, pdfIdList});
+     /* this.download(
+        "/core/registerBook/batch/export",
+        {...this.queryParams, pdfIdList},
+        `${this.selectedOrgName}-'登记簿'-${dayjs(new Date()).format("YYYYMMDD")}.zip`
+      );*/
     },
     getDownList() {
       this.$refs.downListDialog.show(this.search);