<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: "",
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',
responseType: "blob",
})
}
export function dodnLoadDoc(query) {
return request({
url: `XXX/${query}`,
method: 'get',
responseType: "blob",
})
}