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