9***@qq.com
9***@qq.com
  • 发布:2021-03-11 10:08
  • 更新:2021-03-11 15:08
  • 阅读:918

barcode扫码框在ios下可以看到闪光,但是屏幕是白的,看不到扫的条码,也无法识别到二维码

分类:HBuilderX

barcode扫码框在ios下可以看到闪光,但是屏幕是白的,看不到扫的条码,也无法识别到二维码,哪位大佬帮忙看看

2021-03-11 10:08 负责人:无 分享
已邀请:
天生DR

天生DR - Q:342134068 V:Dronaldo17

提供可以稳定复现的示例demo 方便查看

  • 9***@qq.com (作者)

    发到附件里了,麻烦帮忙看一下

    2021-03-11 11:50

  • 天生DR

    回复 9***@qq.com: 需要账号登录?

    2021-03-11 12:59

  • 9***@qq.com (作者)

    回复 天生DR: 账号17748635909 密码222222

    2021-03-11 14:22

  • 天生DR

    回复 9***@qq.com: 你是怎么调用的 示例工程里 是压缩过得js代码吧 我看不了

    2021-03-11 14:55

  • 9***@qq.com (作者)

    回复 天生DR: new plus.barcode.Barcode("bcid")通过这个api调用的

    2021-03-11 14:59

  • 天生DR

    回复 9***@qq.com:你抛去你的那些权限判断逻辑 直接调这个API 可以吗 估计是你那些逻辑和或者延迟引起的 你先最简单化 调用 再去判断逻辑吧 我这边没办法跑起来直接debug 只能说 API 是没问题的

    2021-03-11 15:54

  • 9***@qq.com (作者)

    回复 天生DR: 我把这个barcode append到webview上貌似就可以了

    2021-03-11 16:22

  • 天生DR

    回复 9***@qq.com: OK

    2021-03-11 16:32

9***@qq.com

9***@qq.com (作者)

如附件

9***@qq.com

9***@qq.com (作者)

<template>
<div class="scan">
<div class="goBack">
<div class="left" @click="exitScan">
<van-icon name="arrow-left" color="#fff" />返回
</div>

  <div class="right" @click="setFlash">{{ flashMsg }}</div>  
</div>  
<div id="bcid">  
  <div style="height: 40%"></div>  
  <p class="tip">...载入中...</p>  
</div>  

</div>
</template>

<script type='text/ecmascript-6'>
import Vue from "vue";
import { Toast, Icon } from "vant";

let scan = null;

Vue.use(Toast);
Vue.use(Icon);

export default {
name: "Scan",
data() {
return {
codeUrl: "",
flashMsg: "开启闪光灯",
flashStatus: "false",
enableFlash: false,
};
},
created: function () {
console.log("flashStatus", this.$route.query.flashStatus);
this.enableFlash = this.$route.query.flashStatus;
Toast.loading({
message: "加载中...",
forbidClick: true,
});
// console.log('Created')
const that = this;

var u = navigator.userAgent;  
if (u.indexOf("Android") > -1 || u.indexOf("Adr") > -1) {  
  console.log('安卓系统进入')  
  plus.android.requestPermissions(  
  ["android.permission.CAMERA"],  
  function (e) {  
    if (e.deniedAlways.length > 0) {  
      // 权限被永久拒绝  
      // 弹出提示框解释为何需要定位权限,引导用户打开设置页面开启  
      // alert('永久');  
      document.addEventListener("plusready", onPlusReady, false);  
      // 扩展API加载完毕,现在可以正常调用扩展API  
      function onPlusReady() {  
        // 创建扫码控件来调获取手机的相机权限  
        barcode = plus.barcode.create("barcode", [plus.barcode.QR], {  
          top: "-9999", // 改为-9999px隐藏该页面  
          left: "0",  
          width: "100%",  
          height: "500px",  
          position: "static",  
        });  
        // plus.webview.currentWebview().append(barcode);;  
        // barcode.start();开始扫码识别(我们把这句代码注释了,因为我们不需要扫描任何东西)  
      }  
      // 上面打开权限后,这里直接重启APP  
      plus.runtime.restart();  
    }  
    if (e.deniedPresent.length > 0) {  
      // 权限被临时拒绝  
      // 弹出提示框解释为何需要定位权限,可再次调用plus.android.requestPermissions申请权限  
      // alert('临时 ');  
    }  
    if (e.granted.length > 0) {  
      // 权限被允许  
      // 调用依赖获取定位权限的代码  
      // alert('允许!!! ');  
      that.startRecognize();  
    }  
  },  
  function (e) {  
    alert("Request Permissions error:" + JSON.stringify(e));  
  }  
);  
} else {  
  console.log('IOS系统进入')  
  // document.addEventListener("plusready", onPlusReady, false);  
  //     // 扩展API加载完毕,现在可以正常调用扩展API  
  //     function onPlusReady() {  
  //       // 创建扫码控件来调获取手机的相机权限  
  //       barcode = plus.barcode.create("barcode", [plus.barcode.QR]);  
  //     }  
  let s = plus.navigator.checkPermission("camera");  
  console.log(s)  
  if (s !== "notdeny") {  
    plus.nativeUI.alert("相机权限未获取,请往设置应用程序里面开启权限!");  
  }  
  that.startRecognize();  
}  

},
mounted: function () {
if (window.history && window.history.pushState) {
history.pushState(null, null, document.URL);
window.addEventListener("popstate", this.goBack, false);
}
},
destroyed() {
window.removeEventListener("popstate", this.goBack, false);
},
methods: {
// 创建扫描控件
startRecognize() {
console.log("startRecognize");
const that = this;
if (!window.plus) return;
scan = new plus.barcode.Barcode("bcid");
scan.onmarked = onmarked;

  function onmarked(type, result, file) {  
    switch (type) {  
      case plus.barcode.QR:  
        type = "QR";  
        break;  
      case plus.barcode.EAN13:  
        type = "EAN13";  
        break;  
      case plus.barcode.EAN8:  
        type = "EAN8";  
        break;  
      default:  
        type = "其它" + type;  
        break;  
    }  
    result = result.replace(/\n/g, "");  
    that.codeUrl = result;  
    // alert(result)  
    console.log("扫描结果" + result);  
    // window.location.href = result  
    that.closeScan();  
    let terminalld = result  
      .substring(result.indexOf("terminalId="))  
      .replace("terminalId=", "");  
    console.log("scan result " + terminalld);  
    that.$router.replace({  
      path: "charge-options",  
      query: { TerminalId: terminalld },  
    });  
  }  
  setTimeout(() => {  
    that.startScan();  
  }, 200);  
},  
// 开始扫描  
startScan() {  
  console.log("startScan");  
  if (!window.plus) return;  
  scan.start();  
  if (this.enableFlash == "true") {  
    scan.setFlash(true);  
  }  
},  
// 开启闪光灯  
setFlash() {  
  console.log("setFlash");  

  this.flashStatus = !this.flashStatus;  
  if (this.flashStatus) {  
    this.flashMsg = "关闭闪光灯";  
  } else {  
    this.flashMsg = "开启闪光灯";  
  }  
  if (!window.plus) return;  
  scan.setFlash(this.flashStatus);  
},  
// 关闭扫描  
cancelScan() {  
  console.log("cancelScan");  
  if (!window.plus) return;  
  scan.cancel();  
},  
// 关闭条码识别控件  
closeScan() {  
  console.log("closeScan");  
  if (!window.plus) return;  
  scan.close();  
},  
goBack() {  
  this.closeScan();  
  // replace替换原路由,作用是避免回退死循环  
  this.$router.back();  
},  
exitScan: function () {  
  this.closeScan();  
  this.$router.replace("home");  
},  

},
};
</script>
<style lang="less">
.goBack {
height: 40px;
line-height: 40px;
background-color: #536e00;
color: #fff;
position: relative;
font-size: 14px;
padding: 0 10px 0 20px;
.left {
float: left;
}
.right {
float: right;
}
.van-icon {
position: absolute;
top: 9px;
left: 0;
font-size: 20px;
margin-right: 5px;
}
}
.scan {
height: 100%;

bcid {

width: 100%;  
// position: absolute;  
// left: 0;  
// right: 0;  
// top: 40px;  
// bottom: 0;  
height: calc(100vh - 40px);  
text-align: center;  
color: #fff;  
background: #fff;  
opacity: 0.8;  

}
footer {
position: absolute;
left: 0;
bottom: 1rem;
height: 2rem;
line-height: 2rem;
z-index: 2;
}
}
</style>

9***@qq.com

9***@qq.com (作者)

扫码页面

该问题目前已经被锁定, 无法添加新回复