mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-24 23:00:19 +03:00
* feat: add script to extract strings * feat: extract many strings (html, attr, label) * feat(extract string): extract html only for .vue and single file mode * fix: __i18n_ally_root__ * feat: nestify en.yml + extract tab attributes * feat: add script to extract strings * feat: extract many strings (html, attr, label) * feat(extract string): extract html only for .vue and single file mode * fix: __i18n_ally_root__ * feat: nestify en.yml + extract tab attributes * fix: lint * feat: add vue-i18n-extract to check missing keys * fix: unit tests * fix: update vue i18n plugin
70 lines
1.8 KiB
Vue
70 lines
1.8 KiB
Vue
<script setup lang="ts">
|
|
import { useI18n } from 'vue-i18n';
|
|
import { BarcodeFormat, BrowserMultiFormatReader } from '@zxing/library';
|
|
import TextareaCopyable from '@/components/TextareaCopyable.vue';
|
|
|
|
const { t } = useI18n();
|
|
|
|
const imageBase64 = ref('');
|
|
const barCode = computedAsync(async () => {
|
|
if (imageBase64.value === '') {
|
|
return { text: '', format: '', error: '' };
|
|
}
|
|
try {
|
|
const barcodeReader = new BrowserMultiFormatReader();
|
|
const result = (await barcodeReader.decodeFromImageUrl(imageBase64.value));
|
|
return { text: result.getText(), format: BarcodeFormat[result.getBarcodeFormat()], error: '' };
|
|
}
|
|
catch (e: any) {
|
|
return { error: e.toString(), text: '', format: '' };
|
|
}
|
|
});
|
|
|
|
function blobToBase64(blob: Blob) {
|
|
if (blob === null) {
|
|
return Promise.resolve('');
|
|
}
|
|
return new Promise<string>((resolve, _reject) => {
|
|
const reader = new FileReader();
|
|
reader.onloadend = () => resolve(reader.result as string);
|
|
reader.readAsDataURL(blob);
|
|
});
|
|
}
|
|
|
|
async function onUpload(file: File) {
|
|
if (file) {
|
|
imageBase64.value = await blobToBase64(file);
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<c-file-upload
|
|
:title="t('tools.barcode-reader.texts.title-drag-and-drop-a-barcode-here-or-click-to-select-a-file')"
|
|
:paste-image="true"
|
|
mb-3
|
|
@file-upload="onUpload"
|
|
/>
|
|
|
|
<div v-if="barCode?.text">
|
|
<n-divider />
|
|
|
|
<h3>{{ t('tools.barcode-reader.texts.tag-decoded') }}<span v-if="barCode?.format">({{ barCode?.format }})</span></h3>
|
|
<TextareaCopyable
|
|
:value="barCode?.text"
|
|
:word-wrap="true"
|
|
/>
|
|
</div>
|
|
<c-alert v-if="barCode?.error">
|
|
{{ barCode?.error }}
|
|
</c-alert>
|
|
</div>
|
|
</template>
|
|
|
|
<style lang="less" scoped>
|
|
::v-deep(.n-upload-trigger) {
|
|
width: 100%;
|
|
}
|
|
</style>
|