feat(tool): qr-code generator

This commit is contained in:
Corentin Thomasset 2022-04-14 18:18:15 +02:00
parent 203b6a9d73
commit 5582d75927
No known key found for this signature in database
GPG key ID: 3103EB5E79496F9C
8 changed files with 527 additions and 21 deletions

View file

@ -0,0 +1,60 @@
<template>
<n-card>
<n-grid cols="3" x-gap="12">
<n-gi span="2">
<n-form label-width="130" label-placement="left">
<n-form-item label="Text:">
<n-input v-model:value="text" placeholder="Your link or text..." />
</n-form-item>
<n-form-item label="Foreground color:">
<n-color-picker v-model:value="foreground" :modes="['hex']" />
</n-form-item>
<n-form-item label="Background color:">
<n-color-picker v-model:value="background" :modes="['hex']" />
</n-form-item>
<n-form-item label="Error resistance:">
<n-select v-model:value="errorCorrectionLevel"
:options="errorCorrectionLevels.map((value) => ({ label: value, value }))" />
</n-form-item>
</n-form>
</n-gi>
<n-gi>
<n-space justify="center" align="center" vertical>
<n-image :src="qrcode" width="200" />
<n-button @click="download" secondary>Download qr-code</n-button>
</n-space>
</n-gi>
</n-grid>
</n-card>
</template>
<script setup lang="ts">
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
import { useQRCode } from './useQRCode'
import { ref } from 'vue';
import type { QRCodeErrorCorrectionLevel } from 'qrcode';
const foreground = ref('#000000ff')
const background = ref('#ffffffff')
const errorCorrectionLevel = ref<QRCodeErrorCorrectionLevel>('medium')
const errorCorrectionLevels = ['low', 'medium', 'quartile', 'high']
const text = ref('https://it-tools.tech')
const { qrcode } = useQRCode({
text,
color: {
background,
foreground
},
errorCorrectionLevel,
options: { width: 1024 }
})
const { download } = useDownloadFileFromBase64({ source: qrcode, filename: 'qr-code.png' })
</script>
<style lang="less" scoped>
</style>