mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-22 22:02:38 +03:00
fix(QRCode Decoder): limit to image/* and leave empty if no qr code to decode
Fix #136
This commit is contained in:
1 parent
11e2ac8130
commit
75670a71ab
1 file changed
+13
-4
@@ -10,7 +10,11 @@ const { t } = useI18n();
|
|||||||
const fileInput = ref() as Ref<File>;
|
const fileInput = ref() as Ref<File>;
|
||||||
const qrCode = computedAsync(async () => {
|
const qrCode = computedAsync(async () => {
|
||||||
try {
|
try {
|
||||||
return (await qrcodeParser(fileInput.value));
|
const file = fileInput.value;
|
||||||
|
if (!file) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return (await qrcodeParser(file));
|
||||||
}
|
}
|
||||||
catch (e: any) {
|
catch (e: any) {
|
||||||
return e.toString();
|
return e.toString();
|
||||||
@@ -18,7 +22,11 @@ const qrCode = computedAsync(async () => {
|
|||||||
});
|
});
|
||||||
const qrCodeParsed = computed(() => {
|
const qrCodeParsed = computed(() => {
|
||||||
try {
|
try {
|
||||||
const parsed = parseQRData(qrCode.value);
|
const qrCodeValue = qrCode.value;
|
||||||
|
if (!qrCodeValue) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
const parsed = parseQRData(qrCodeValue);
|
||||||
return `Type: ${parsed.type}\nValue:${JSON.stringify(parsed.value, null, 2)}`;
|
return `Type: ${parsed.type}\nValue:${JSON.stringify(parsed.value, null, 2)}`;
|
||||||
}
|
}
|
||||||
catch (e: any) {
|
catch (e: any) {
|
||||||
@@ -38,19 +46,20 @@ async function onUpload(file: File) {
|
|||||||
<c-file-upload
|
<c-file-upload
|
||||||
:title="t('tools.qr-code-decoder.texts.title-drag-and-drop-a-qr-code-here-or-click-to-select-a-file')"
|
:title="t('tools.qr-code-decoder.texts.title-drag-and-drop-a-qr-code-here-or-click-to-select-a-file')"
|
||||||
:paste-image="true"
|
:paste-image="true"
|
||||||
|
accept="image/*"
|
||||||
@file-upload="onUpload"
|
@file-upload="onUpload"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<n-divider />
|
<n-divider />
|
||||||
|
|
||||||
<div>
|
<div v-if="qrCode">
|
||||||
<h3>{{ t('tools.qr-code-decoder.texts.tag-decoded') }}</h3>
|
<h3>{{ t('tools.qr-code-decoder.texts.tag-decoded') }}</h3>
|
||||||
<TextareaCopyable
|
<TextareaCopyable
|
||||||
:value="qrCode"
|
:value="qrCode"
|
||||||
:word-wrap="true"
|
:word-wrap="true"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div v-if="qrCodeParsed">
|
||||||
<h3>{{ t('tools.qr-code-decoder.texts.tag-parsed') }}</h3>
|
<h3>{{ t('tools.qr-code-decoder.texts.tag-parsed') }}</h3>
|
||||||
<TextareaCopyable
|
<TextareaCopyable
|
||||||
:value="qrCodeParsed"
|
:value="qrCodeParsed"
|
||||||
|
|||||||
Reference in new issue
Block a user