WXL
2024-02-20 c0b29ee03f4f6c984f35618bfa669ba3f2ab6517
src/views/project/fundstatistics/index.vue
@@ -160,6 +160,8 @@
import { listDonatebaseinfo } from "@/api/project/donatebaseinfo";
import { getDonationCost, exportFundCost } from "@/api/project/financesubject";
import FundSummary from "@/views/project/components/fundsummary";
import { getToken } from "@/utils/auth";
export default {
  //import引入的组件需要注入到对象中才能使用
  components: {
@@ -198,6 +200,9 @@
        donorno: null,
        name: null,
        id: null,
      },
      headers: {
        Authorization: "Bearer " + getToken()
      },
    };
  },
@@ -244,22 +249,35 @@
    //导出汇总表
    exportSummary(id) {
      exportFundCost(id).then((res) => {
        if (res.downloadUrl) {
          var fileUrl = res;
          //获取当前网址
          var urlBase = process.env.VUE_APP_BASE_API;
          var curWWWPath = window.document.location.href;
          var pos = curWWWPath.indexOf(window.document.location.pathname);
          // 创建a标签
          var aEle = document.createElement("a");
          aEle.href =
            curWWWPath.substring(0, pos) + urlBase + fileUrl["downloadUrl"];
          aEle.click();
          this.$alert("下载成功", "提示", {
            confirmButtonText: "确定",
            type: "success",
        var fileUrl = res;
        //获取当前网址
        var urlBase = process.env.VUE_APP_BASE_API;
        var curWWWPath = window.document.location.href;
        var pos = curWWWPath.indexOf(window.document.location.pathname);
        // 创建a标签
        var aEle = document.createElement("a");
        aEle.href =
          curWWWPath.substring(0, pos) + urlBase + fileUrl["downloadUrl"];
        console.log(aEle.href);
        // 添加Authorization头部
        fetch(aEle.href, {
          headers: this.headers
        })
          .then(response => {
            // 将文件下载链接作为blob对象进行下载
            return response.blob();
          })
          .then(blob => {
            const url = window.URL.createObjectURL(new Blob([blob]));
            console.log(url);
            const link = document.createElement("a");
            link.href = url;
            const name=fileUrl["downloadName"]
            link.setAttribute("download", name); // 替换file.pdf为实际的文件名
            document.body.appendChild(link);
            link.click();
            link.parentNode.removeChild(link);
          });
        }
      });
    },
  },