-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add new better qrcode scanner feat: add new better qrcode scanner feat: add new better qrcode scanner feat: version 2.0 - add new better qrcode scanner - refactor the styling feat: version 2.0 - add new better qrcode scanner - refactor the styling
- Loading branch information
Showing
9 changed files
with
120 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,111 @@ | ||
<template> | ||
<ion-content> | ||
<StreamBarcodeReader | ||
@decode="(a, b, c) => onDecode(a, b, c)" | ||
@loaded="() => onLoaded()" | ||
></StreamBarcodeReader> | ||
<ion-item :color="text ? 'success' : 'danger'"> | ||
<span class="ion-margin-end">Input value:</span> | ||
<span>{{ text || 'Nothing' }}</span></ion-item | ||
<ion-modal | ||
ref="modal" | ||
:breakpoints="breakpoints" | ||
:initial-breakpoint="initialBreakpoint" | ||
:is-open="true" | ||
:trigger="trigger" | ||
> | ||
<HeaderModal title="Scanner" /> | ||
<QrcodeStream | ||
:paused="paused" | ||
@detect="onDetect" | ||
@error="onError" | ||
@camera-on="onCameraOn" | ||
@camera-off="onCameraOff" | ||
> | ||
<ion-fab class="ion-margin-top" horizontal="end"> | ||
<ion-fab-button @click="toggleFlashLight"> | ||
<ion-icon :icon="torch ? flash : flashOutline"></ion-icon> | ||
</ion-fab-button> | ||
</ion-fab> | ||
</ion-content> | ||
<div v-show="showScanConfirmation" class="scan-confirmation"> | ||
<ion-icon | ||
:icon="checkmarkCircleOutline" | ||
class="large-icon" | ||
color="success" | ||
></ion-icon> | ||
</div> | ||
</QrcodeStream> | ||
</ion-modal> | ||
</template> | ||
|
||
<script lang="ts" setup> | ||
import { ref } from 'vue' | ||
import { IonContent, IonFab, IonFabButton, IonIcon } from '@ionic/vue' | ||
import { StreamBarcodeReader } from 'vue-barcode-reader' | ||
import { flash, flashOutline } from 'ionicons/icons' | ||
import { QrcodeStream } from 'vue-qrcode-reader' | ||
import { IonIcon, IonModal, toastController } from '@ionic/vue' | ||
import { checkmarkCircleOutline } from 'ionicons/icons' | ||
import HeaderModal from '@/components/elements/HeaderModal.vue' | ||
const text = ref('') | ||
let id: any = null | ||
defineProps<{ | ||
breakpoints: Array<number> | ||
initialBreakpoint: number | ||
eventId?: number | ||
securityCode?: string | ||
ticketId?: number | ||
title: string | ||
trigger: string | ||
}>() | ||
const onDecode = (a: any, b: any, c: any) => { | ||
console.log(a, b, c) | ||
text.value = a | ||
if (id) clearTimeout(id) | ||
id = setTimeout(() => { | ||
if (text.value === a) { | ||
text.value = '' | ||
} | ||
}, 5000) | ||
const paused = ref(false) | ||
const result = ref('') | ||
const showScanConfirmation = ref(false) | ||
const onCameraOn = () => { | ||
showScanConfirmation.value = false | ||
} | ||
const onCameraOff = () => { | ||
showScanConfirmation.value = true | ||
} | ||
const onDetect = async (detectedCodes: any[]) => { | ||
result.value = JSON.stringify(detectedCodes.map((code) => code.rawValue)) | ||
paused.value = true | ||
await timeout(1000) | ||
paused.value = false | ||
await presentToast(result.value) | ||
} | ||
const timeout = (ms: number) => { | ||
return new Promise((resolve) => setTimeout(resolve, ms)) | ||
} | ||
const onLoaded = () => { | ||
console.log('load') | ||
const presentToast = async (message: string) => { | ||
const toast = await toastController.create({ | ||
message: message, | ||
duration: 2500, | ||
position: 'top', | ||
color: 'success' | ||
}) | ||
await toast.present() | ||
} | ||
const torch = ref(false) | ||
const presentErrorToast = async (message: string) => { | ||
const toast = await toastController.create({ | ||
message: message, | ||
duration: 2500, | ||
position: 'top', | ||
color: 'danger' | ||
}) | ||
await toast.present() | ||
} | ||
const toggleFlashLight = () => { | ||
torch.value = !torch.value | ||
const onError = async (error: Error) => { | ||
console.error(error) | ||
await presentErrorToast(error.message) | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.scan-confirmation { | ||
position: absolute; | ||
width: 100%; | ||
height: 100%; | ||
background-color: rgba(255, 255, 255, 0.8); | ||
display: flex; | ||
flex-flow: row nowrap; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
.large-icon { | ||
font-size: 10rem; | ||
color: var(--ion-color-success); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters