aboutsummaryrefslogtreecommitdiff
path: root/src/tools/qr-code-generator/qr-code-generator.vue
blob: 8f2161d3ea6d2a758e8bad430eea8c4d1893b414 (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
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
<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
            secondary
            @click="download"
          >
            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>