微信小程序在线预览PDF文件

编程入门 行业动态 更新时间:2024-10-23 07:14:42

微信小程序<a href=https://www.elefans.com/category/jswz/34/1770935.html style=在线预览PDF文件"/>

微信小程序在线预览PDF文件

需求:微信小程序在线预览PDF合同文件,加载完成后强制阅读10秒才可点击同意按钮

H5代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>微信小程序在线预览PDF</title><link rel="stylesheet" href="./css/pdfh5.css"><link rel="stylesheet" href="./css/style.css"><style>#pdf {width: 100%;height: 100vh;}.btn {display: flex;justify-content: center;align-items: center;position: absolute;left: 32px;right: 32px;bottom: 10px;height: 50px;background-image: linear-gradient(270deg, #FF5D31 0%, #FFA853 100%);border-radius: 44px;font-weight: 500;font-size: 16px;color: #fff;}</style>
</head><body><div id="app"><div id="pdf"></div><div class="btn" style="opacity: .8;" v-if="show">{{message}}</div><div class="btn" v-else @click="submit">同意签署</div></div><script src="./js/pdf.js"></script><script src="./js/pdf.worker.js"></script><script src="./js/jquery-3.6.0.min.js"></script><script src="./js/pdfh5.js"></script><script src=".3.2.js"></script><script src="@2"></script><script>var app = new Vue({el: '#app',data: {show: true,num: 10,timer: null},computed: {message() {if (this.num === 10) {return '合同加载中...'} else {return '阅读倒计时' + this.num + '秒'}}},methods: {submit() {wx.miniProgram.postMessage({ data: 'done' })},},mounted() {let searchURL = window.location.search;searchURL = searchURL.substring(1, searchURL.length);const pdfurl = searchURL.split("&")[0].split("=")[1];const pdfh5 = new Pdfh5('#pdf', {pdfurl,}, {lazy: true});pdfh5.on("complete", (status) => {if (status === 'error') returnthis.timer = setInterval(() => {if (this.num === 0) {this.show = falseclearInterval(this.timer)} else {this.num -= 1}}, 1000)})},unmounted() {this.timer && clearInterval(this.timer)},})</script>
</body></html>

微信小程序

wxml
<web-view src="{{src}}" bindmessage="bindmessage" />js
Page({data: {src: '',},onLoad() {this.setData({src: `${将H5页面部署到服务器的地址}?file=${pdf文件路径}`})},bindmessage(e) {if (e.detail.data[0] === 'done') {// todo 处理同意后的逻辑}},
})

更多推荐

微信小程序在线预览PDF文件

本文发布于:2023-12-03 11:08:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1654683.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在线   文件   程序   微信小   PDF

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!