Advertisement
sayhicoelho

QR Code Reader

Oct 18th, 2018
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 3.40 KB | None | 0 0
  1. <template>
  2.   <v-card>
  3.     <v-alert :value="!!camera.error" type="error" transition="slide-y-transition">
  4.       {{ camera.error }}
  5.     </v-alert>
  6.     <v-progress-circular v-if="camera.loading" :size="30" :width="3" color="primary" indeterminate/>
  7.     <v-responsive class="qr-scanner-container" height="280px" v-if="!camera.loading">
  8.       <div v-if="camera.active">
  9.         <qrcode-reader :paused="camera.paused" @decode="onDecode" @init="onInit"></qrcode-reader>
  10.       </div>
  11.       <div class="qr-scanner">
  12.         <v-btn color="blue darken-2" class="white--text" @click="toggleCamera">
  13.           <v-icon dark v-if="!camera.active">fingerprint</v-icon>
  14.           <v-icon dark v-else>stop</v-icon>
  15.         </v-btn>
  16.         <v-btn color="blue darken-2" class="white--text" @click="togglePause" v-if="camera.active">
  17.           <v-icon dark v-if="!camera.paused">replay</v-icon>
  18.           <v-icon dark v-else>pause</v-icon>
  19.         </v-btn>
  20.       </div>
  21.     </v-responsive>
  22.   </v-card>
  23. </template>
  24.  
  25. <script>
  26. import { mapGetters } from 'vuex'
  27. import QrcodeReader from 'vue-qrcode-reader'
  28.  
  29. export default {
  30.   name: 'point-records',
  31.   components: { QrcodeReader },
  32.   data () {
  33.     return {
  34.       camera: {
  35.         active: false,
  36.         paused: false,
  37.         loading: false,
  38.         error: null
  39.       }
  40.     }
  41.   }
  42.   methods: {
  43.     toggleCamera () {
  44.       this.camera.active = !this.camera.active
  45.     },
  46.     togglePause () {
  47.       this.camera.paused = !this.camera.paused
  48.     },
  49.     onDecode (content) {
  50.       this.camera.paused = true
  51.       this.form.registration = content
  52.     },
  53.     async onInit (promise) {
  54.       // show loading indicator
  55.       this.camera.loading = true
  56.  
  57.       try {
  58.         await promise
  59.  
  60.         // successfully initialized
  61.       } catch (error) {
  62.         if (error.name === 'NotAllowedError') {
  63.           // user denied camera access permisson
  64.           this.camera.error = 'Você precisa permitir o acesso à câmera para efetuar o registro de pontos.'
  65.         } else if (error.name === 'NotFoundError') {
  66.           // no suitable camera device installed
  67.           this.camera.error = 'Sua câmera não foi detectada. Por favor, certifique se sua câmera está funcionando corretamente e tente novamente.'
  68.         } else if (error.name === 'NotSupportedError') {
  69.           // page is not served over HTTPS (or localhost)
  70.           this.camera.error = 'Para que consigamos acessar sua câmera, é preciso estar conectado em uma conexão segura (HTTPS).'
  71.         } else if (error.name === 'NotReadableError') {
  72.           // maybe camera is already in use
  73.           this.camera.error = 'Não conseguimos conectar à sua câmera. Certifique se ela não está em uso por outro programa/aplicativo.'
  74.         } else if (error.name === 'OverconstrainedError') {
  75.           // passed constraints don't match any camera.
  76.           // Did you requested the front camera although there is none?
  77.           this.camera.error = 'Sua câmera frontal não está presente. Por favor, mude para a câmera traseira e tente novamente.'
  78.         } else {
  79.           // browser might be lacking features (WebRTC, ...)
  80.           this.camera.error = 'Parece que seu navegador não suporta a tecnologia WebRTC. Por favor, tente atualizá-lo ou baixe um navegador mais recente.'
  81.         }
  82.       } finally {
  83.         // hide loading indicator
  84.         this.camera.loading = false
  85.       }
  86.     }
  87.   }
  88. }
  89. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement