mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
QR code generator UI improvements (#165)
* - Added dedicated copy button - Added download icon to download button - Moved output format dropdown from the bottom of the page to under the error resistance dropdown for easier access - Increased the width of the QR code image displayed on the page to match the copy and download buttons - Disabled the multiline attribute in the url text field as newlines weren't being encoded into the QR code * - Fixed a bug where the output format selection wouldn't update the image file extension when downloading the QR code image * Fixed an issue with using the copy button for image formats other than png --------- Co-authored-by: sharevb <sharevb@gmail.com>
This commit is contained in:
1 parent
6cbfa60e89
commit
0462c17fc1
2 files changed
+96
-24
No files matched your search
Vendored
+17
-7
@@ -198,16 +198,22 @@ declare module '@vue/runtime-core' {
|
||||
IcoConverter: typeof import('./src/tools/ico-converter/ico-converter.vue')['default']
|
||||
'IconMdi:brushVariant': typeof import('~icons/mdi/brush-variant')['default']
|
||||
'IconMdi:kettleSteamOutline': typeof import('~icons/mdi/kettle-steam-outline')['default']
|
||||
IconMdiArrowRightBottom: typeof import('~icons/mdi/arrow-right-bottom')['default']
|
||||
IconMdiCheck: typeof import('~icons/mdi/check')['default']
|
||||
IconMdiChevronDown: typeof import('~icons/mdi/chevron-down')['default']
|
||||
IconMdiChevronRight: typeof import('~icons/mdi/chevron-right')['default']
|
||||
IconMdiClose: typeof import('~icons/mdi/close')['default']
|
||||
IconMdiContentCopy: typeof import('~icons/mdi/content-copy')['default']
|
||||
IconMdiCopy: typeof import('~icons/mdi/copy')['default']
|
||||
IconMdiDownload: typeof import('~icons/mdi/download')['default']
|
||||
IconMdiEye: typeof import('~icons/mdi/eye')['default']
|
||||
IconMdiEyeOff: typeof import('~icons/mdi/eye-off')['default']
|
||||
IconMdiHeart: typeof import('~icons/mdi/heart')['default']
|
||||
IconMdiSearch: typeof import('~icons/mdi/search')['default']
|
||||
IconMdiTranslate: typeof import('~icons/mdi/translate')['default']
|
||||
IconMdiTriangleDown: typeof import('~icons/mdi/triangle-down')['default']
|
||||
IconTablerCopy: typeof import('~icons/tabler/copy')['default']
|
||||
IconTablerDownload: typeof import('~icons/tabler/download')['default']
|
||||
IesLightingGuidelines: typeof import('./src/tools/ies-lighting-guidelines/ies-lighting-guidelines.vue')['default']
|
||||
IlluminanceConverter: typeof import('./src/tools/illuminance-converter/illuminance-converter.vue')['default']
|
||||
ImageConverter: typeof import('./src/tools/image-converter/image-converter.vue')['default']
|
||||
@@ -309,37 +315,41 @@ declare module '@vue/runtime-core' {
|
||||
MorseConverter: typeof import('./src/tools/morse-converter/morse-converter.vue')['default']
|
||||
MultiLinkDownloader: typeof import('./src/tools/multi-link-downloader/multi-link-downloader.vue')['default']
|
||||
MyIp: typeof import('./src/tools/my-ip/my-ip.vue')['default']
|
||||
NAlert: typeof import('naive-ui')['NAlert']
|
||||
NA: typeof import('naive-ui')['NA']
|
||||
NanoidGenerator: typeof import('./src/tools/nanoid-generator/nanoid-generator.vue')['default']
|
||||
NanoMemo: typeof import('./src/tools/nano-memo/nano-memo.vue')['default']
|
||||
'NanoMemo.content': typeof import('./src/tools/nano-memo/nano-memo.content.md')['default']
|
||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||
NButton: typeof import('naive-ui')['NButton']
|
||||
NCard: typeof import('naive-ui')['NCard']
|
||||
NCheckbox: typeof import('naive-ui')['NCheckbox']
|
||||
NCode: typeof import('naive-ui')['NCode']
|
||||
NColorPicker: typeof import('naive-ui')['NColorPicker']
|
||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||
NDivider: typeof import('naive-ui')['NDivider']
|
||||
NDynamicTags: typeof import('naive-ui')['NDynamicTags']
|
||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||
NForm: typeof import('naive-ui')['NForm']
|
||||
NFormItem: typeof import('naive-ui')['NFormItem']
|
||||
NGi: typeof import('naive-ui')['NGi']
|
||||
NginxFormatter: typeof import('./src/tools/nginx-formatter/nginx-formatter.vue')['default']
|
||||
NginxMemo: typeof import('./src/tools/nginx-memo/nginx-memo.vue')['default']
|
||||
'NginxMemo.content': typeof import('./src/tools/nginx-memo/nginx-memo.content.md')['default']
|
||||
NGrid: typeof import('naive-ui')['NGrid']
|
||||
NH1: typeof import('naive-ui')['NH1']
|
||||
NH3: typeof import('naive-ui')['NH3']
|
||||
NIcon: typeof import('naive-ui')['NIcon']
|
||||
NInput: typeof import('naive-ui')['NInput']
|
||||
NImage: typeof import('naive-ui')['NImage']
|
||||
NInputGroup: typeof import('naive-ui')['NInputGroup']
|
||||
NInputGroupLabel: typeof import('naive-ui')['NInputGroupLabel']
|
||||
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
||||
NLayout: typeof import('naive-ui')['NLayout']
|
||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||
NMenu: typeof import('naive-ui')['NMenu']
|
||||
NRadio: typeof import('naive-ui')['NRadio']
|
||||
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
|
||||
NModal: typeof import('naive-ui')['NModal']
|
||||
NP: typeof import('naive-ui')['NP']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSelect: typeof import('naive-ui')['NSelect']
|
||||
NSpace: typeof import('naive-ui')['NSpace']
|
||||
NTable: typeof import('naive-ui')['NTable']
|
||||
NTagGroup: typeof import('naive-ui')['NTagGroup']
|
||||
NTooltip: typeof import('naive-ui')['NTooltip']
|
||||
NumberInput: typeof import('./src/tools/pomodoro-timer/app/components/NumberInput.vue')['default']
|
||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||
|
||||
@@ -85,8 +85,64 @@ const qrcodeTerminal = computedAsync(() => {
|
||||
});
|
||||
|
||||
const filename = ref('qr-code');
|
||||
const extension = computed(() => outputType.value.toString());
|
||||
const extension = computed(() => {
|
||||
// Explicitly access the reactive value
|
||||
const type = outputType.value;
|
||||
return type.toString();
|
||||
});
|
||||
const { download } = useDownloadFileFromBase64({ source: qrcode, filename, extension });
|
||||
|
||||
const isCopied = ref(false);
|
||||
|
||||
async function copyQRCode() {
|
||||
try {
|
||||
// Convert base64 to blob
|
||||
const response = await fetch(qrcode.value);
|
||||
const blob = await response.blob();
|
||||
|
||||
// Convert to PNG if it's not already PNG for clipboard compatibility
|
||||
let clipboardBlob = blob;
|
||||
if (blob.type !== 'image/png') {
|
||||
// Create a canvas to convert the image to PNG
|
||||
const img = new Image();
|
||||
const canvas = document.createElement('canvas');
|
||||
const ctx = canvas.getContext('2d');
|
||||
|
||||
await new Promise((resolve) => {
|
||||
img.onload = () => {
|
||||
canvas.width = img.width;
|
||||
canvas.height = img.height;
|
||||
ctx?.drawImage(img, 0, 0);
|
||||
canvas.toBlob((pngBlob) => {
|
||||
if (pngBlob) {
|
||||
clipboardBlob = pngBlob;
|
||||
}
|
||||
resolve(undefined);
|
||||
}, 'image/png');
|
||||
};
|
||||
img.src = qrcode.value;
|
||||
});
|
||||
}
|
||||
|
||||
// Copy to clipboard using the Clipboard API
|
||||
await navigator.clipboard.write([
|
||||
new ClipboardItem({
|
||||
'image/png': clipboardBlob,
|
||||
}),
|
||||
]);
|
||||
|
||||
// Show success feedback
|
||||
isCopied.value = true;
|
||||
setTimeout(() => {
|
||||
isCopied.value = false;
|
||||
}, 2000); // Reset after 2 seconds
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Failed to copy QR code:', error);
|
||||
// Show error feedback and reset
|
||||
isCopied.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -99,11 +155,9 @@ const { download } = useDownloadFileFromBase64({ source: qrcode, filename, exten
|
||||
label-width="130px"
|
||||
label-align="right"
|
||||
:label="t('tools.qr-code-generator.texts.label-text')"
|
||||
multiline
|
||||
rows="1"
|
||||
autosize
|
||||
:placeholder="t('tools.qr-code-generator.texts.placeholder-your-link-or-text')"
|
||||
mb-6
|
||||
autosize mb-6
|
||||
/>
|
||||
<n-form label-width="130" label-placement="left">
|
||||
<n-form-item :label="t('tools.qr-code-generator.texts.label-foreground-color')">
|
||||
@@ -126,6 +180,15 @@ const { download } = useDownloadFileFromBase64({ source: qrcode, filename, exten
|
||||
label-align="right"
|
||||
:options="errorCorrectionLevels.map((value) => ({ label: value, value }))"
|
||||
/>
|
||||
<c-select
|
||||
v-model:value="outputType"
|
||||
mt-3
|
||||
:label="t('tools.qr-code-generator.texts.label-output-format')"
|
||||
label-position="left"
|
||||
label-width="130px"
|
||||
label-align="right"
|
||||
:options="outputTypes.map((value) => ({ label: value.toUpperCase(), value }))"
|
||||
/>
|
||||
</n-form>
|
||||
<c-card :title="t('tools.qr-code-generator.texts.title-image')" mt-3>
|
||||
<c-file-upload :title="t('tools.qr-code-generator.texts.title-drag-and-drop-an-image-here-or-click-to-select-an-image')" @file-upload="onUpload" />
|
||||
@@ -193,22 +256,21 @@ const { download } = useDownloadFileFromBase64({ source: qrcode, filename, exten
|
||||
</n-form>
|
||||
</details>
|
||||
</c-card>
|
||||
<c-select
|
||||
v-model:value="outputType"
|
||||
mt-3
|
||||
:label="t('tools.qr-code-generator.texts.label-output-format')"
|
||||
label-position="left"
|
||||
label-width="130px"
|
||||
label-align="right"
|
||||
:options="outputTypes.map((value) => ({ label: value.toUpperCase(), value }))"
|
||||
/>
|
||||
</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 ({{ outputType.toString().toUpperCase() }})
|
||||
</c-button>
|
||||
<n-image :src="qrcode" width="250" />
|
||||
<div flex gap-3>
|
||||
<c-button @click="copyQRCode">
|
||||
{{ isCopied ? 'Copied!' : 'Copy' }}
|
||||
<icon-mdi-check v-if="isCopied" ml-2 style="color: #10b981;" />
|
||||
<icon-mdi-content-copy v-else ml-2 />
|
||||
</c-button>
|
||||
<c-button @click="download">
|
||||
Download ({{ outputType.toString().toUpperCase() }})
|
||||
<icon-mdi-download ml-2 />
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<n-divider />
|
||||
|
||||
Reference in new issue
Block a user