qinxianzhangyao
2024-05-27 015aeab7a6a99afd0b24ee6ea7b5e4a9c950c3b5
src/views/reservation/grouprecords/index.vue
@@ -281,7 +281,6 @@
      </el-dialog>
    </div>
    <el-dialog
      title="PDF 预览"
      :visible.sync="dialogVisible"
@@ -303,7 +302,8 @@
import {
  addComp,
  plRevokeTjOrderByTjNum,
  getListByCompId, makeTjPDF,
  getListByCompId,
  makeTjPDF,
} from "@/api/system/comp";
import { getCompany, queryCompany } from "@/api/team/tuanti";
@@ -466,7 +466,7 @@
      single: true,
      // 非多个禁用
      multiple: true,
      ids:[],
      ids: [],
      // 总条数
      total: 0,
      // 弹出层标题
@@ -591,32 +591,61 @@
      this.objs.reservationTime = val;
    },
     /** 确认按钮 */
     submitForm() {
      makeTjPDF().then((response) => {
        if (response.size === 0) {
          const loading = this.$loading({
            lock: true,
            text: "Loading",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)",
          });
          setTimeout(() => {
            loading.close();
          }, 3000);
          this.$message({
            message: "报告正在生成,请两分钟后预览!",
            type: "warning",
          });
        } else {
          this.dialogVisible = true;
          const newBlob = [];
          newBlob.push(response);
          const blob = new Blob(newBlob, { type: "application/pdf" });
          this.url = window.webkitURL.createObjectURL(blob); //将后端返回的blob文件读取出url
    base64ToBlob({ b64data = "", contentType = "", sliceSize = 512 } = {}) {
      return new Promise((resolve, reject) => {
        // 使用 atob() 方法将数据解码
        let byteCharacters = atob(b64data);
        let byteArrays = [];
        for (
          let offset = 0;
          offset < byteCharacters.length;
          offset += sliceSize
        ) {
          let slice = byteCharacters.slice(offset, offset + sliceSize);
          let byteNumbers = [];
          for (let i = 0; i < slice.length; i++) {
            byteNumbers.push(slice.charCodeAt(i));
          }
          // 8 位无符号整数值的类型化数组。内容将初始化为 0。
          // 如果无法分配请求数目的字节,则将引发异常。
          byteArrays.push(new Uint8Array(byteNumbers));
        }
        let result = new Blob(byteArrays, {
          type: contentType,
        });
        result = Object.assign(result, {
          // jartto: 这里一定要处理一下 URL.createObjectURL
          preview: URL.createObjectURL(result),
          // name: `图片示例.png`,
        });
        resolve(result);
      });
    },
    /** 确认按钮 */
    submitForm() {
      if (this.ids.length != 0) {
        makeTjPDF(this.ids).then((response) => {
        let base64 = response.file;
        this.base64ToBlob({
          b64data: base64,
          contentType: "application/pdf",
        }).then((res) => {
          this.dialogVisible = true;
          // 转后后的blob对象
          console.log("blob", res.preview);
         try {
          this.url =res.preview;
         } catch (error) {
          this.url = window.webkitURL.createObjectURL(res.preview);
         }
        })
      });
      } else {
        this.$modal.msgError("请选择撤销人员");
      }
    },
  },
};
</script>