弹窗预览pdf,下载文档

<el-table-column label="操作">
	<template slot-scope="scope">
		<el-button type="text" size="mini" @click="handleSee(scope.$index, scope.row)">预览</el-button>
		<el-button size="mini" type="text" @click="downLoad(scope.$index, scope.row)">下载</el-button>
	</template>
</el-table-column>

 <el-dialog title="预览" :visible.sync="dialogVisible" width="90%" class="dialog">
      <iframe :src="iframeUrl" style="width: 100%; height: 83vh; overflow-y: auto; overflow-x: auto"></iframe>
 </el-dialog>
 
 data:{
    iframeUrl: "", //iframe预览显示
    dialogVisible: false, //弹出层是否显示
}
 // 预览
handleSee(index, row) {
	this.dialogVisible = true;
	yulan(row.id).then((res) => {
		if (this.dialogVisible == true) {
			var binaryData = [];
			binaryData.push(res);
			this.iframeUrl = window.URL.createObjectURL(
				new Blob(binaryData, { type: "application/pdf" })
			 );
		}
	});
},
// 下载
downLoad(index, row) {
	console.log(row);
	dodnLoadDoc(row.id).then((res) => {
          const url = URL.createObjectURL(res);
          const link = document.createElement("a");
          document.body.appendChild(link);
          link.download = row.reportName;
          link.href = url;
          link.click();
          document.body.removeChild(link);
          URL.revokeObjectURL(url);
        })
        .catch((error) => {
          this.$message({ message: error.message, type: "error" });
        });
    },
// 预览接口:
export function yulan(query) {
  return request({
    url: `XXX/${query}`,
    method: 'get',
    // params: query
    responseType: "blob",
  })
}
// 下载接口
export function dodnLoadDoc(query) {
  return request({
    url: `XXX/${query}`,
    method: 'get',
    // params: query
    responseType: "blob",
  })
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值