当时以为 是解决了。后来打包到IOS上时也是 出现。原因是
- let ws = plus.webview.create("./camera.html", "camera");
- ws.show();
- ws.addEventListener(
- "loaded",
- function() {
- //页面加载完成后才显示
- setTimeout(function() {
- ws.show();
- }, );
- },
- false
- );
- ws.addEventListener(
- "close",
- function() {
- ws = null;
- },
- false
- );
camera.html页面上
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>camera</title>
- <style>
- html,
- body,
- div,
- span,
- img {
- margin: ;
- padding: ;
- }
- body {
- background: #;
- }
- .tips {
- margin-top: %;
- color: #fff;
- text-align: center
- }
- .action {
- position: fixed;
- z-index: ;
- width: %;
- left: ;
- bottom: ;
- }
- .action .items {
- display: flex;
- justify-content: space-around;
- background: rgba(, , , 0.35);
- width: %;
- padding: 4px;
- margin: 4px auto;
- }
- .action .items .item {
- flex-basis: 50px;
- text-align: center;
- }
- .action .items img {
- width: 27px;
- }
- </style>
- </head>
- <body>
- <div id="camera">
- <div id="scan"></div>
- <div class="tips">加载中...</div>
- <div class="action">
- <div class="items">
- <div class="item" onclick="openLight"><img src="./src/assets/img/png-60@3x.png"></div>
- <div class="item" onclick="getPicture"><img src="./src/assets/img/png-59@3x.png"></div>
- <!-- <div
- class="item"
- @click="showInput"
- ><img src="../assets/img/png-68@3x.png">
- </div> -->
- <div class="item" onclick="cancelScan"><img src="./src/assets/img/png-61@3x.png"></div>
- <!-- <d class="item"><img src="../../assets/img/png-25@3x.png"></d -->
- </div>
- </div>
- </div>
- </body>
- <script>
- var isLight = false, scan = null;
- // 打开闪光灯
- function openLight() {
- isLight = !isLight;
- scan.setFlash(isLight);
- }
- //创建扫描控件
- function startRecognize() {
- if (!window.plus) return;
- scan = null;
- scan = new plus.barcode.Barcode(
- "scan",
- [plus.barcode.QR, plus.barcode.EAN8, plus.barcode.EAN13],
- {
- frameColor: "#1294cb",
- scanbarColor: "#1294cb",
- top: "100px",
- left: "0px",
- width: "100%",
- height: "500px",
- position: "fixed"
- }
- );
- // 条码识别成功
- scan.onmarked = onmarked;
- function onmarked(type, result, file) {
- result = result.replace(/\n/g, "");
- localStorage.setItem("cameraData", result);
- let ws = plus.webview.getWebviewById("camera");
- ws.close()
- }
- }
- // //开始扫描
- function startScan() {
- if (!window.plus) return;
- startRecognize(); //创建控件
- setTimeout(() => {
- scan.start();
- }, );
- }
- // 取消扫描
- function cancelScan() {
- if (!window.plus) return;
- plus.navigator.setStatusBarStyle("dark");
- if (scan) {
- scan.cancel(); //关闭扫描
- scan.close(); //关闭条码识别控件
- }
- let ws = plus.webview.getWebviewById("camera");
- ws.close()
- }
- // 从相册选取二维码相片
- function getPicture() {
- plus.gallery.pick(src => {
- // scan.cancel(); //关闭扫描
- plus.barcode.scan(
- src,
- (type, result) => {
- scan.cancel(); //关闭扫描
- scan.close();
- localStorage.setItem("cameraData", result);
- plus.navigator.setStatusBarStyle("dark");
- let ws = plus.webview.getWebviewById("camera");
- ws.close()
- }
- );
- });
- }
- window.onload = function () {
- setTimeout(() => {
- plus.navigator.setStatusBarStyle("dark");
- startScan()
- }, );
- }
- </script>
- </html>
这样算解决了。折腾了N久
以上就是vue项目使用html5+ barcode扫码在苹果遇到的问题以及自己的解决方法的详细内容,更多关于vue项目使用html5+ barcode扫码在苹果遇到的问题以及自己的解决方法的资料请关注九品源码其它相关文章!