stream 展示数据格式为流文件的PDF和图片

发布时间 2023-12-21 15:14:52作者: LaLaLa_heng

判断数据格式为PDF或非

        getViewImg(row.row.id).then((res) => {
          if(row.row.fileExtension == 'pdf') {
            let newBlob = new window.Blob([res.data], { type: 'application/pdf;charset-UTRF-8' })
            const downloadUrl = window.URL.createObjectURL(newBlob);
            this.viewVisible = true;
            this.pdfsrc = downloadUrl
          } else {
            const downloadUrl = window.URL.createObjectURL(res.data);
            this.dialogImageUrl = downloadUrl;
            this.dialogVisible = true
          }
          console.log(res)
        })

展示

        <!-- 文件上传预览 -->
        <el-dialog :visible.sync="dialogVisible" top="70px" append-to-body>
          <el-image
            :src="dialogImageUrl"
            :preview-src-list="dialogImageUrlList">
          </el-image>
        </el-dialog>
        <el-dialog append-to-body :visible.sync="viewVisible" width="80%" height="80%" top="20px" :before-close='closeDialog'>
          <div class="pdf" v-show="fileType === 'pdf'">
            <!--<pdf :src="pdfsrc" ></pdf>-->
            <iframe :src="pdfsrc" style="width: 100%;height: 666px" frameborder="0"></iframe>
          </div>
        </el-dialog>