王震
2023-12-04 bea4b9e9da44517844bff2e8952b85206ce839ca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<template>
    <div class="qrcode">
      <div class="code">
        <!-- decode是扫描结果的函数,torch用于是否需要打开手电筒,init用于检查该设备是否能够调用摄像头的权限,camera可用于打开前面或者后面摄像头  -->
        <qrcode-drop-zone @decode="onDecode">
          <qrcode-stream @decode="onDecode" :torch="torchActive" @init="onInit" :camera="camera" />
        </qrcode-drop-zone>
        <div class="code-button">
          <button @click="switchCamera">相机反转</button>
          <button @click="ClickFlash">打开手电筒</button>
          <button @click="turnCameraOff">关闭相机</button>
        </div>
      </div>
    </div>
  </template>
  
  <script>
  // 引用vue-qrcode-reader插件
  import { QrcodeStream, QrcodeDropZone, QrcodeCapture } from 'vue-qrcode-reader'
  
  export default {
    name: 'Approve',
    props: {
      camera: {
        type: String,
        default: 'rear',
      },
      torchActive: {
        type: Boolean,
        default: false,
      },
      qrcode: {
        type: Boolean,
        default: false,
      },
      noStreamApiSupport: {
        type: Boolean,
        default: false,
      },
    },
    data() {
      return {}
    },
    created() {
      console.log(222222222222224564646);
    },
  
    components: {
      // 注册组件
      QrcodeStream,
      QrcodeDropZone,
      QrcodeCapture,
    },
    methods: {
      // 扫码结果回调
      onDecode(result) {
        this.$emit('onDecode', result)
      },
      // 相机反转
      switchCamera() {
        this.$emit('switchCamera')
      },
      // 关闭相机??????
      turnCameraOff() {
        this.$emit('turnCameraOff')
      },
      // 打开手电筒
      ClickFlash() {
        this.$emit('ClickFlash')
      },
      // 检查是否调用摄像头
      onInit(promise) {
        this.$emit('onInit', promise)
      },
    },
  }
  </script>