aboutsummaryrefslogtreecommitdiff
path: root/src/tools/qr-code-generator/qr-code-generator.vue
blob: e23f00aac0e8c7d7cdbf21263deb10e0dbb48e7d (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
<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>