blob: f6ea7c8e1ce992219cb402eed8cb173c7b7090d3 (
plain) (
blame)
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
|
<script setup lang="ts">
import { ref } from 'vue';
import type { QRCodeErrorCorrectionLevel } from 'qrcode';
import { useQRCode } from './useQRCode';
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
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>
<template>
<c-card>
<n-grid x-gap="12" y-gap="12" cols="1 600:3">
<n-gi span="2">
<n-form label-width="130" label-placement="left">
<n-form-item label="Text:">
<n-input
v-model:value="text"
type="textarea"
:autosize="{ minRows: 1 }"
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>
<div flex flex-col items-center gap-3>
<n-image :src="qrcode" width="200" />
<c-button @click="download">
Download qr-code
</c-button>
</div>
</n-gi>
</n-grid>
</c-card>
</template>
|