gaoluyang
11 小时以前 e449a5408265e4bd1f6c66f5be28a42efac444ee
src/pages/qualityManagement/finalInspection/fileList.vue
@@ -3,6 +3,15 @@
    <!-- 页面头部 -->
    <PageHeader title="附件管理"
                @back="goBack" />
    <!-- 需求九.4:下载 PDF 合格证 -->
    <view class="pdf-bar">
      <u-button type="primary"
                size="small"
                :loading="downloadingPdf"
                @click="downloadPdf">
        下载合格证PDF
      </u-button>
    </view>
    <!-- 附件列表 -->
    <view class="file-list-container">
      <view v-if="fileList.length > 0"
@@ -78,10 +87,28 @@
    qualityInspectFileListPage,
    qualityInspectFileDel,
  } from "@/api/qualityManagement/materialInspection";
  import { downloadQualityInspectPdf } from "@/api/qualityManagement/qualityInspectFile.js";
  import { openFile } from "@/utils/file";
  import { blobValidate } from "@/utils/ruoyi";
  // 附件列表
  const fileList = ref([]);
  // 合格证PDF 下载中
  const downloadingPdf = ref(false);
  // 下载 PDF 合格证(与附件同一份 inspectId)
  const downloadPdf = () => {
    if (!rulesRegulationsManagementId.value) {
      showToast("参数错误");
      return;
    }
    downloadingPdf.value = true;
    downloadQualityInspectPdf(rulesRegulationsManagementId.value)
      .catch(() => {})
      .finally(() => {
        downloadingPdf.value = false;
      });
  };
  // 返回上一页
  const goBack = () => {
@@ -259,81 +286,11 @@
      });
    });
  };
  // 下载文件
  // 下载并预览。
  // 原来走的是 /common/download?...&delete=true —— 会把服务端附件删掉,
  // 且回调里引用了未定义的 resolve/reject。改为直接按 url 打开。
  const downloadFile = file => {
    var url =
      config.baseUrl +
      "/common/download?fileName=" +
      encodeURIComponent(file.url) +
      "&delete=true";
    console.log(url, "url");
    uni
      .downloadFile({
        url: url,
        responseType: "blob",
        header: { Authorization: "Bearer " + getToken() },
      })
      .then(res => {
        let osType = uni.getStorageSync("deviceInfo").osName;
        let filePath = res.tempFilePath;
        if (osType === "ios") {
          uni.openDocument({
            filePath: filePath,
            showMenu: true,
            success: res => {
              resolve(res);
            },
            fail: err => {
              console.log("uni.openDocument--fail");
              reject(err);
            },
          });
        } else {
          uni.saveFile({
            tempFilePath: filePath,
            success: fileRes => {
              uni.showToast({
                icon: "none",
                mask: true,
                title:
                  "文件已保存:Android/data/uni.UNI720216F/apps/__UNI__720216F/" +
                  fileRes.savedFilePath, //保存路径
                duration: 3000,
              });
              setTimeout(() => {
                //打开文档查看
                uni.openDocument({
                  filePath: fileRes.savedFilePath,
                  success: function (res) {
                    resolve(fileRes);
                  },
                });
              }, 3000);
            },
            fail: err => {
              console.log("uni.save--fail");
              reject(err);
            },
          });
        }
        // const isBlob = blobValidate(res.data);
        // if (isBlob) {
        //   const blob = new Blob([res.data], { type: "text/plain" });
        //   const url = URL.createObjectURL(blob);
        //   const downloadLink = document.getElementById("downloadLink");
        //   downloadLink.href = url;
        //   downloadLink.download = file.name;
        //   downloadLink.click();
        //   showToast("下载成功");
        // } else {
        //   showToast("下载失败");
        // }
      })
      .catch(err => {
        console.error("下载失败:", err);
        showToast("下载失败");
      });
    openFile(file?.url);
  };
  // 确认删除
@@ -431,6 +388,10 @@
    padding: 20rpx;
  }
  .pdf-bar {
    padding: 16rpx 20rpx 0;
  }
  .file-list {
    background: #ffffff;
    border-radius: 8rpx;