Compare commits
2 Commits
31ff426acf
...
25ab061255
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
25ab061255 | ||
|
|
439eaf9fdf |
@@ -1,102 +1,63 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div style="margin: 0 auto">
|
||||||
<div ref="content" class="content">
|
<el-button
|
||||||
<pdf :src="url" class="PDF"></pdf>
|
type="primary"
|
||||||
|
@click="testdownload4()"
|
||||||
|
style="display: block; margin: 0 auto"
|
||||||
|
:loading="isloading"
|
||||||
|
>下载到手机</el-button
|
||||||
|
>
|
||||||
|
<div v-for="(item, index) in apidata.pics" :key="index">
|
||||||
|
<van-image
|
||||||
|
:width="pic_width"
|
||||||
|
:height="pic_height"
|
||||||
|
:src="item"
|
||||||
|
class="baseImg"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="bottom">
|
|
||||||
<a href="" download="">
|
|
||||||
<el-button type="primary">保存到相册</el-button>
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
<iframe :src="url" frameborder="0"></iframe>
|
|
||||||
<!-- <el-button type="primary" @click="this.savePdf()">测试2</el-button>
|
|
||||||
<el-button type="primary" @click="this.handlePrint()">测试3</el-button>
|
|
||||||
<el-button type="primary" @click="testdownload4()">测试4</el-button> -->
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script src="https://cdn.bootcss.com/html2canvas/0.5.0-beta4/html2canvas.js"></script>
|
|
||||||
<script>
|
<script>
|
||||||
import pdf from "vue-pdf";
|
// import pdf from "vue-pdf";
|
||||||
import $ from "jquery";
|
|
||||||
import html2canvas from "html2canvas";
|
|
||||||
// import axios from "axios";
|
|
||||||
import request from "@/common/util";
|
|
||||||
import { mgop } from "@aligov/jssdk-mgop";
|
import { mgop } from "@aligov/jssdk-mgop";
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {},
|
||||||
pdf
|
|
||||||
},
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
url:
|
url: "",
|
||||||
"https://zsxt.nbzs.org.cn/Files/UploadFiles/e85a13ef-431c-46a5-85cd-9dd1b4f50fc6/80616f98-da17-49bc-92d0-b87199963787.pdf"
|
apidata: {},
|
||||||
|
pic_width: "auto",
|
||||||
|
pic_height: "auto",
|
||||||
|
isloading: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
this.onInit();
|
this.onInit();
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {},
|
||||||
// 截图
|
|
||||||
// html2canvas(this.$refs.PDF).then(canvas => {
|
|
||||||
// canvas.id = "mycanvas";
|
|
||||||
// const base64 = canvas.toDataURL("image/png");
|
|
||||||
// jquery("a").prop("href", base64);
|
|
||||||
// });
|
|
||||||
},
|
|
||||||
methods: {
|
methods: {
|
||||||
onInit() {
|
onInit() {
|
||||||
// this.onLoadData();
|
|
||||||
request({
|
|
||||||
url: "http://10.19.94.9:7099/api/agreement/info",
|
|
||||||
method: "post",
|
|
||||||
data: {
|
|
||||||
ticket: window.sessionStorage.getItem("ticket"),
|
|
||||||
id: "C655515B-FD91-48F2-BD79-EAABAFB7077C"
|
|
||||||
},
|
|
||||||
headers: { "Content-Type": "application/json; charset=UTF-8" },
|
|
||||||
responseType: "blob" //一定要设置响应类型,否则页面会是空白pdf
|
|
||||||
}).then(result => {
|
|
||||||
console.log("结果", result);
|
|
||||||
const binaryData = [];
|
|
||||||
binaryData.push(result.data);
|
|
||||||
//获取blob链接
|
|
||||||
const gan = window.URL.createObjectURL(
|
|
||||||
new Blob(binaryData, { type: "application/pdf" })
|
|
||||||
);
|
|
||||||
this.url = this.getObjectURL(result.data);
|
|
||||||
console.log("aaa", this.url);
|
|
||||||
$("a").prop("href", this.url);
|
|
||||||
// if (pdfUrl) {
|
|
||||||
// this.handlePrint(pdfUrl);
|
|
||||||
// }
|
|
||||||
});
|
|
||||||
mgop({
|
mgop({
|
||||||
api: "mgop.kykj.houseexpropriat.getagreementinfo",
|
api: "mgop.kykj.houseexpropriat.getagreementinfop",
|
||||||
host: "https://mapi.zjzwfw.gov.cn/",
|
host: "https://mapi.zjzwfw.gov.cn/",
|
||||||
dataType: "JSON",
|
dataType: "JSON",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
data: {
|
data: {
|
||||||
ticket: window.sessionStorage.getItem("ticket"),
|
ticket:
|
||||||
id: "C655515B-FD91-48F2-BD79-EAABAFB7077C"
|
this.$route.params.ticket ||
|
||||||
|
window.sessionStorage.getItem("ticket"),
|
||||||
|
id: "C655515B-FD91-48F2-BD79-EAABAFB7077C",
|
||||||
},
|
},
|
||||||
appKey: "es4b8zmz+2001833218+dehllx",
|
appKey: "es4b8zmz+2001833218+dehllx",
|
||||||
onSuccess: result => {
|
onSuccess: result => {
|
||||||
console.log("pdf.vue页面请求pdf文件:", result);
|
console.log("pdf.vue页面请求pdf文件:", result);
|
||||||
if (result.data && result.data.success == true) {
|
if (result.data && result.data.success == true) {
|
||||||
console.log("result.data.data:", result.data.data);
|
console.log("result.data.data:", result.data.data);
|
||||||
// this.url = result.data.data;
|
this.apidata = result.data.data;
|
||||||
const binaryData = [];
|
this.pic_width = "94%";
|
||||||
binaryData.push(result.data.data);
|
this.pic_height = "100%";
|
||||||
//获取blob链接
|
this.isloading = false;
|
||||||
const gan = window.URL.createObjectURL(
|
|
||||||
new Blob(binaryData, { type: "application/pdf" })
|
|
||||||
);
|
|
||||||
this.url = this.getObjectURL(gan);
|
|
||||||
console.log("aaa", this.url);
|
|
||||||
// if (pdfUrl) {
|
|
||||||
// this.handlePrint(pdfUrl);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onFail: err => {
|
onFail: err => {
|
||||||
@@ -104,34 +65,11 @@ export default {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
saveImages() {
|
||||||
handlePrint() {
|
|
||||||
if (document.getElementById("print-iframe")) {
|
|
||||||
document.body.removeChild(document.getElementById("print-iframe"));
|
|
||||||
}
|
|
||||||
//判断iframe是否存在,不存在则创建iframe
|
|
||||||
let iframe = document.getElementById("print-iframe");
|
|
||||||
if (!iframe) {
|
|
||||||
iframe = document.createElement("IFRAME");
|
|
||||||
let doc = null;
|
|
||||||
iframe.setAttribute("src", this.url);
|
|
||||||
iframe.setAttribute("id", "print-iframe");
|
|
||||||
document.body.appendChild(iframe);
|
|
||||||
doc = iframe.contentWindow.document;
|
|
||||||
doc.close();
|
|
||||||
iframe.contentWindow.focus();
|
|
||||||
}
|
|
||||||
iframe.contentWindow.print();
|
|
||||||
},
|
|
||||||
onLoadData() {
|
|
||||||
// console.log(this.$route.params);
|
|
||||||
// this.url = this.$route.params.url;
|
|
||||||
},
|
|
||||||
savePdf() {
|
|
||||||
ZWJSBridge.onReady(() => {
|
ZWJSBridge.onReady(() => {
|
||||||
console.log("初始化完成后,执行bridge方法-savePdf");
|
console.log("初始化完成后,执行bridge方法-saveImages");
|
||||||
ZWJSBridge.saveImage({
|
ZWJSBridge.saveImage({
|
||||||
url: this.url
|
url: this.apidata.pdf,
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
console.log("saveImage()成功:" + JSON.stringify(result));
|
console.log("saveImage()成功:" + JSON.stringify(result));
|
||||||
@@ -146,10 +84,10 @@ export default {
|
|||||||
ZWJSBridge.onReady(() => {
|
ZWJSBridge.onReady(() => {
|
||||||
console.log("初始化完成后,执行bridge方法-testdownload4");
|
console.log("初始化完成后,执行bridge方法-testdownload4");
|
||||||
ZWJSBridge.openLink({
|
ZWJSBridge.openLink({
|
||||||
url: this.url
|
url: this.apidata.pdf,
|
||||||
})
|
})
|
||||||
.then(result => {
|
.then((result) => {
|
||||||
console.log("testdownload4():" + result);
|
console.log("测试新开窗口():" + result);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
@@ -171,4 +109,8 @@ export default {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
.baseImg {
|
||||||
|
display: block;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user