-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTicketQrCode.vue
More file actions
89 lines (78 loc) · 1.7 KB
/
TicketQrCode.vue
File metadata and controls
89 lines (78 loc) · 1.7 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
<script setup>
import {onMounted, ref, watch} from "vue";
import QRCodeStyling from 'styled-qr-code';
const props = defineProps({
data: {
type: String,
required: false
},
image: {
type: String,
required: false
}
});
const qr_code = ref(null);
const qr_options = {
width: 512,
height: 512,
type: 'canvas',
margin: 4,
qrOptions: {
typeNumber: 0,
mode: 'Byte',
errorCorrectionlevel: 'L'
},
imageOptions: {
hideBackgroundDots: true,
imageSize: 1,
margin: 2,
// crossOrigin: false,
crossOrigin: 'anonymous'
},
dotsOptions: {
// type: 'rounded',
color: '#000000',
},
backgroundOptions: {
color: "#ffffff"
},
cornersSquareOptions: {
type: "extra-rounded",
color: "#000000"
},
cornersDotOptions: {
type: "dot",
color: "#000000"
},
};
const qrCode = new QRCodeStyling(qr_options);
const doDownload = () => {
qrCode.download({
name: 'my_ticket',
extension: 'png',
}, 1);
}
onMounted(async () => {
qrCode.append(qr_code.value)
});
watch(() => props, async (newValue) => {
// const timestamp = new Date().getTime();
// const img_path = `${newValue.image}?timestamp=${timestamp}`;
const data_uri = newValue.data;
qrCode.update({
...qr_options,
data: data_uri,
// image: img_path
});
qrCode.append(qr_code.value);
}, {deep: true, immediate: true});
</script>
<template>
<div ref="qr_code"/>
<v-btn color="primary" @click="doDownload">Download</v-btn>
</template>
<style>
canvas {
max-width: 100%
}
</style>