HBuilderX wap2app 5+app扫码功能页面的实现 调摄像头扫二维码

news/2024/10/30 23:16:23/

DCloud HBuilderX wap2app 5+app扫码功能页面的实现,html页面,跳到这个页面即可扫码,扫了以后再带参数返回想要返回的页面。

<!DOCTYPE html>
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=no,width=device-width,initial-scale=1.0" /><title>扫二维码</title><link rel="stylesheet" href="assets/index.css"><style>.bg {background-color: #eee}.fr {float: right;}.gray {color: #888;}.mxje {font-size: 14px;color: #ff4960;line-height: 35px;float: right;}.van-nav-bar {background-image: linear-gradient(to right, #2d76ff, #2abaff);}.van-nav-bar__title,.van-nav-bar .van-icon {color: #fff;}.van-cell .van-button {float: right}.block {overflow: auto;zoom: 1;text-align: center}.tico {margin: 0 2px 0 0;top: 2px;}.errmsg {color: #ee0a24}</style><script src="assets/vue.min.js"></script><script src="assets/vant.min.js"></script><script src="assets/axios.min.js"></script><script src="assets/main.js"></script></head><body><div id="app">
<script>/*document.addEventListener('plusready', function() {var barcode = null;// 扫码成功回调function onmarked(type, result) {var text = '未知: ';switch (type) {case plus.barcode.QR:text = 'QR: ';break;case plus.barcode.EAN13:text = 'EAN13: ';break;case plus.barcode.EAN8:text = 'EAN8: ';break;}alert(text + result);}// 创建Barcode扫码控件function createBarcode() {if (!barcode) {// plus.navigator.setFullscreen(true); //全屏barcode = plus.barcode.create('barcode', [plus.barcode.QR], {top: '0px',left: '0px',width: '100%',height: '100%',position: 'static'});barcode.onmarked = onmarked;plus.webview.currentWebview().append(barcode);}barcode.start();}createBarcode();});*/var barcode = null;var app = new Vue({el: '#app',data: {name: '自定义', //要在扫码界面自定义的内容flash: false, //是否打开摄像头type: '',},mounted() {document.addEventListener('plusready', ()=>{this.onLoad();// console.log('44');});},methods: {onLoad() {var n = "扫描二维码";this.type = "scan-listener";if (n) {this.name = n;}// var pages = getCurrentPages();// var page = pages[pages.length - 1];// #ifdef APP-PLUS// plus.navigator.setFullscreen(true); //全屏var currentWebview = plus.webview.currentWebview();this.createBarcode(currentWebview); //创建二维码窗口this.createView(currentWebview); //创建操作按钮及tips界面// #endif},// 扫码成功回调onmarked(type, result) {var text = '未知: ';switch (type) {case plus.barcode.QR:text = 'QR: ';break;case plus.barcode.EAN13:text = 'EAN13: ';break;case plus.barcode.EAN8:text = 'EAN8: ';break;case plus.barcode.CODE39:text = 'CODE39: ';break;}// plus.navigator.setFullscreen(false);//这是登录时扫码获取税号if(getQueryString('ref')=='login'){this.getContent(result);}else if(getQueryString('ref')=='write_off'){ //核销扫码this.getWriteOffCode(result);}else if(getQueryString('ref')=='voice_box'){ //绑定扫码var strs=result.split(",");window.location.href="voice_box.html?sn="+strs[0];}barcode.close();},// 创建二维码窗口createBarcode(currentWebview) {barcode = plus.barcode.create('barcode', [plus.barcode.QR], {top: '0',left: '0',width: '100%',height: '100%',scanbarColor: '#1DA7FF',position: 'static',frameColor: '#1DA7FF'});barcode.onmarked = this.onmarked;barcode.setFlash(this.flash);currentWebview.append(barcode);barcode.start();},getContent(url){vant.Toast.loading({duration: 0,message: '加载中...',forbidClick: true,loadingType: 'spinner',});let self=this;axios({method:'post',url:'/api/getData',data:{'url':url,}}).then(function(res){vant.Toast.clear();vant.Toast({message:res.data.msg,closeOnClick:true});if (res.data.code==1) {window.location.href="login.html?no="+res.data.data;/*if (!plus.webview.getWebviewById('login')){plus.webview.create("login.html?taxno="+res.data.data,"login");}setTimeout(()=> {plus.webview.show("login");},500);*/}else{vant.Toast({message:res.data.msg,closeOnClick:true});}});},getWriteOffCode(sn){window.location.href="write_off.html?sn="+sn;},// 创建操作按钮及tipscreateView(currentWebview) {// 创建返回原生按钮var backVew = new plus.nativeObj.View('backVew', {top: '13px',left: '0px',height: '40px',width: '100%'},[{tag: 'img',id: 'backBar',src: 'assets/img/left.png',position: {top: '15px',left: '3px',width: '25px',height: '25px'}}]);// 创建打开手电筒的按钮var scanBarVew = new plus.nativeObj.View('scanBarVew', {top: '55%',left: '40%',height: '10%',width: '20%'},[{tag: 'img',id: 'scanBar',src: 'assets/img/sdt.png',position: {width: '28%',left: '36%',height: '30%'}},{tag: 'font',id: 'font',text: '轻触照亮',textStyles: {size: '10px',color: '#ffffff'},position: {width: '80%',left: '10%'}}]);// 创建展示类内容组件var content = new plus.nativeObj.View('content', {top: '13px',left: '0px',height: '100%',width: '100%'},[/*{tag: 'font',id: 'scanTitle',text: '扫码',textStyles: {size: '18px',color: '#ffffff'},position: {top: '13px',left: '0px',width: '100%',height: '40px'}},*/{tag: 'font',id: 'scanTips',text: this.name,textStyles: {size: '14px',color: '#ffffff',whiteSpace: 'normal'},position: {top: '90px',left: '10%',width: '80%',height: 'wrap_content'}}]);backVew.interceptTouchEvent(true);scanBarVew.interceptTouchEvent(true);currentWebview.append(content);currentWebview.append(scanBarVew);/*currentWebview.append(backVew);backVew.addEventListener("click", function(e) { //返回按钮plus.webview.close('scanPage');barcode.close();plus.navigator.setFullscreen(false);}, false);*/var temp = this;scanBarVew.addEventListener("click", function(e) { //点亮手电筒temp.flash = !temp.flash;if (temp.flash) {scanBarVew.draw([{tag: 'img',id: 'scanBar',src: 'assets/img/sdt.png',position: {width: '28%',left: '36%',height: '30%'}},{tag: 'font',id: 'font',text: '轻触照亮',textStyles: {size: '10px',color: '#ffffff'},position: {width: '80%',left: '10%'}}]);} else {scanBarVew.draw([{tag: 'img',id: 'scanBar',src: 'assets/img/sdt.png',position: {width: '28%',left: '36%',height: '30%'}},{tag: 'font',id: 'font',text: '轻触照亮',textStyles: {size: '10px',color: '#ffffff'},position: {width: '80%',left: '10%'}}])}if (barcode) {barcode.setFlash(temp.flash);}}, false)}},onBackPress() {// #ifdef APP-PLUS// 返回时退出全屏barcode.close();plus.navigator.setFullscreen(false);// #endif},onUnload() {plus.navigator.setFullscreen(false);}});
</script></div></body>
</html>

我的微信:


http://www.ppmy.cn/news/460677.html

相关文章

【翻译】Evaluation of a computer‑aided method for measuring the Cobb angle on chest X‑rays

Evaluation of a computer‑aided method for measuring the Cobb angle on chest X‑rays 计算机辅助测量胸部X光片Cobb角方法的评价 论文链接、European Spine Journal、EUR SPINE J、三区(1432-0932) 单词积累&#xff1a; a retrospective analysis 回顾性分析、radiol…

2023年的深度学习入门指南(11) - Triton

2023年的深度学习入门指南(11) - Triton 上一篇我们学习了如何用CUDA进行编程。 下面我们将介绍几种深度学习GPU编程的优化方法。 第一种我们称之为多面体编译器。我们知道&#xff0c;在传统的IR&#xff0c;比如LLVM-IR中&#xff0c;使用条件分支来编码控制流信息。这种相…

hdu 4960 Another OCD Patient dp

题目链接:hdu 4960 题意:一排橡皮泥排成一排,要求最后捏成对称的,捏过的不能再捏. 思路:书读的少啊!!!看到题就想暴力,发现不行才想dp,状态转移方程dp[j]min(dp[j],dp[i]a[cnt]),初始化dp值为从开始捏到I. 代码: #include <cstdio>#include <cstring>#include &…

HDU 4960(Another OCD Patient-区间dp)

Another OCD Patient Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1320 Accepted Submission(s): 459 Problem Description 已知一个数列&#xff0c;现在把它分成k段&#xff0c;要求每段的和组成的新数列…

HDU 4960 (区间DP)

题目链接&#xff1a;点击这里 题意&#xff1a;把一个数列合并成回文序列&#xff0c;每一个数字只能和并一次&#xff0c;只能连续的子串进行合并&#xff0c;合并后的数字是他们的和&#xff0c;花费是他们中数字个数的函数。给出原始串和花费函数求最小的花费。 O(n) 扫一…

git版本管理入门(本地/远程仓库,常用命令)

目录 git简介 安装git 配置SSH key Linux环境下需要命令生成ssh key 本地git管理 多人协作流程 追加 重新提交 git命令 git commit本地和git push远程 git stash和git stash pop暂存 git status查看修改哪些了文件​ git diff 查看修改前后的差异 git log查看提交…

HDU 4960 Another OCD Patient

解题报告&#xff1a; 维护前缀和以及后缀和&#xff0c;相等则记录为断点 dp[ i ]表示断点 i 中间全部合并&#xff0c;两侧最优合并的最小代价 #include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <cli…

【DP】 HDOJ 4960 Another OCD Patient

从两端往中间合并。。。合并过程中的数必然向数小的一方先合并。。。然后我们就可以这样先预处理出关节点。。。然后再关节点上一维DP即可。。。。 #include <iostream> #include <queue> #include <stack> #include <map> #include <set&g…