Merge branch 'preview'
This commit is contained in:
commit
31731c5bed
1 changed files with 49 additions and 4 deletions
|
|
@ -1,5 +1,8 @@
|
||||||
<script setup>
|
<script setup>
|
||||||
|
import { Button } from '#components'
|
||||||
|
import { Download } from 'lucide-vue-next'
|
||||||
import QRCodeStyling from 'qr-code-styling'
|
import QRCodeStyling from 'qr-code-styling'
|
||||||
|
import { ref, watch } from 'vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
data: {
|
data: {
|
||||||
|
|
@ -11,6 +14,7 @@ const props = defineProps({
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
const color = ref('#000000')
|
||||||
const options = {
|
const options = {
|
||||||
width: 256,
|
width: 256,
|
||||||
height: 256,
|
height: 256,
|
||||||
|
|
@ -68,14 +72,55 @@ const options = {
|
||||||
const qrCode = new QRCodeStyling(options)
|
const qrCode = new QRCodeStyling(options)
|
||||||
const qrCodeEl = ref(null)
|
const qrCodeEl = ref(null)
|
||||||
|
|
||||||
|
function updateColor(newColor) {
|
||||||
|
qrCode.update({
|
||||||
|
dotsOptions: { type: 'dots', color: newColor, gradient: null },
|
||||||
|
cornersSquareOptions: { type: 'extra-rounded', color: newColor },
|
||||||
|
cornersDotOptions: { type: 'dot', color: newColor },
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(color, (newColor) => {
|
||||||
|
updateColor(newColor)
|
||||||
|
})
|
||||||
|
|
||||||
|
function downloadQRCode() {
|
||||||
|
const slug = props.data.split('/').pop()
|
||||||
|
qrCode.download({
|
||||||
|
extension: 'png',
|
||||||
|
name: `qr_${slug}`,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
qrCode.append(qrCodeEl.value)
|
qrCode.append(qrCodeEl.value)
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div
|
<div class="flex flex-col items-center gap-4">
|
||||||
ref="qrCodeEl"
|
<div
|
||||||
:data-text="data"
|
ref="qrCodeEl"
|
||||||
/>
|
:data-text="data"
|
||||||
|
/>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<div class="relative flex items-center">
|
||||||
|
<div
|
||||||
|
class="w-8 h-8 rounded-full border cursor-pointer overflow-hidden"
|
||||||
|
:style="{ backgroundColor: color }"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
v-model="color"
|
||||||
|
type="color"
|
||||||
|
class="absolute inset-0 w-full h-full opacity-0 cursor-pointer"
|
||||||
|
title="Change QR code color"
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Button variant="outline" @click="downloadQRCode">
|
||||||
|
<Download class="w-4 h-4 mr-2" />
|
||||||
|
Download QR Code
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue