小程序Camera组件扫条形码,在IOS设备上无反应,偶发事件,在安卓上不会?
发布于 6 年前 作者 qiang68 7010 次浏览 来自 官方Issues

微信版本号:7.0.12

import Taro, { Component } from '[@tarojs](/user/tarojs)/taro';

import {

  Camera,

  View,

  Button

from '[@tarojs](/user/tarojs)/components';


import './scanCode.less';


export default class ScanCode extends Component {

  state = {

    showCameratrue

  };


  //用户拒绝使用摄像头时,展示提示信息

  handleScanError = e => {

    const { type } = e;

    if (type === 'error') {

      this.setState({ showCamerafalse });

    }

  };


  //重新弹出摄像头授权页面

  handleReAuthCamera = () => {

    const that = this;

    Taro.openSetting({

      successres => {

        res.authSetting = {

          'scope.camera'true

        };

      }

    }).then(() => that.setState({ showCameratrue }));

  };


  handleScanCode = e => {

    const {

      detail: { result }

    } = e;


    console.log('eee===>'e);

  };


  render() {

    const { showCamera } = this.state;

    return (

      <View className="scan-view">

        <View className="scan-border">

          {showCamera ? (

            <Camera

              className="scan-camera"

              mode="scanCode"

              onError={this.handleScanError}

              onScanCode={this.handleScanCode}

              frameSize="small"

              resolution="high"

            ></Camera>

          ) : (

            <View className="scan-reauth">

              <Button type="primary" onClick={this.handleReAuthCamera} />

            </View>

          )}

        </View>

      </View>

    );

  }

}


1 回复

你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

回到顶部