refactor: update image URL variable and improve translation keys in CanvasComponent and MainLayout
This commit is contained in:
parent
74df7c81f5
commit
4eadd58473
2 changed files with 39 additions and 62 deletions
|
|
@ -18,7 +18,7 @@ const cropper = ref();
|
||||||
|
|
||||||
const tab = ref('draw');
|
const tab = ref('draw');
|
||||||
const uploadFile = ref<File | undefined>(undefined);
|
const uploadFile = ref<File | undefined>(undefined);
|
||||||
const profileUrl = ref<string | null>('');
|
const imgUrl = ref<string | null>('');
|
||||||
const inputFile = (() => {
|
const inputFile = (() => {
|
||||||
const element = document.createElement('input');
|
const element = document.createElement('input');
|
||||||
element.type = 'file';
|
element.type = 'file';
|
||||||
|
|
@ -26,7 +26,7 @@ const inputFile = (() => {
|
||||||
|
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.addEventListener('load', () => {
|
reader.addEventListener('load', () => {
|
||||||
if (typeof reader.result === 'string') profileUrl.value = reader.result;
|
if (typeof reader.result === 'string') imgUrl.value = reader.result;
|
||||||
});
|
});
|
||||||
|
|
||||||
element.addEventListener('change', () => {
|
element.addEventListener('change', () => {
|
||||||
|
|
@ -39,9 +39,11 @@ const inputFile = (() => {
|
||||||
return element;
|
return element;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
async function initializeSignaturePad(canva?: HTMLCanvasElement) {
|
async function initializeSignaturePad() {
|
||||||
if (canva) {
|
const canvas = canvasRef.value;
|
||||||
signaturePad.value = new SignaturePad(canva, {
|
|
||||||
|
if (canvas) {
|
||||||
|
signaturePad.value = new SignaturePad(canvas, {
|
||||||
backgroundColor: isDarkActive.value
|
backgroundColor: isDarkActive.value
|
||||||
? 'rgb(21,25,29)'
|
? 'rgb(21,25,29)'
|
||||||
: 'rgb(248,249,250)',
|
: 'rgb(248,249,250)',
|
||||||
|
|
@ -82,29 +84,27 @@ function clearCanvas() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearUpload() {
|
function clearUpload() {
|
||||||
profileUrl.value = '';
|
imgUrl.value = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => tab.value,
|
() => tab.value,
|
||||||
async () => {
|
async () => {
|
||||||
await initializeSignaturePad(canvasRef.value);
|
await initializeSignaturePad();
|
||||||
await initializeCropper(imageRef.value);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await initializeSignaturePad(canvasRef.value);
|
await initializeSignaturePad();
|
||||||
await initializeCropper(imageRef.value);
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div class="surface-1 bordered rounded full-width">
|
<div class="surface-1 column full-width full-height">
|
||||||
<q-tabs
|
<q-tabs
|
||||||
v-model="tab"
|
v-model="tab"
|
||||||
dense
|
dense
|
||||||
align="left"
|
align="left"
|
||||||
class="text-grey"
|
class="text-grey surface-2"
|
||||||
active-color="primary"
|
active-color="primary"
|
||||||
indicator-color="primary"
|
indicator-color="primary"
|
||||||
>
|
>
|
||||||
|
|
@ -112,18 +112,18 @@ onMounted(async () => {
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<q-tab
|
<q-tab
|
||||||
name="draw"
|
name="draw"
|
||||||
label="Draw"
|
:label="$t('general.draw')"
|
||||||
style="border-top-left-radius: var(--radius-2)"
|
style="border-top-left-radius: var(--radius-2)"
|
||||||
/>
|
/>
|
||||||
<q-tab name="upload" label="Upload" />
|
<q-tab name="upload" :label="$t('general.upload')" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="q-pr-md">
|
<div class="q-pr-md">
|
||||||
<q-btn
|
<q-btn
|
||||||
|
v-if="tab === 'upload'"
|
||||||
dense
|
dense
|
||||||
flat
|
flat
|
||||||
v-if="tab === 'upload'"
|
:label="$t('general.newUpload')"
|
||||||
:label="$t('newUpload')"
|
|
||||||
color="info"
|
color="info"
|
||||||
@click="inputFile.click()"
|
@click="inputFile.click()"
|
||||||
/>
|
/>
|
||||||
|
|
@ -132,89 +132,66 @@ onMounted(async () => {
|
||||||
</q-tabs>
|
</q-tabs>
|
||||||
<q-separator />
|
<q-separator />
|
||||||
|
|
||||||
<div v-show="tab === 'draw'" class="q-pa-md">
|
<section v-show="tab === 'draw'" class="q-pa-md col">
|
||||||
<div class="column relative-position">
|
<div class="column relative-position">
|
||||||
<div class="absolute-top-right q-ma-md q-gutter-x-md row items-center">
|
<article
|
||||||
|
class="absolute-top-right q-ma-md q-gutter-x-md row items-center"
|
||||||
|
>
|
||||||
<span
|
<span
|
||||||
|
v-for="color in ['black', 'red', 'blue']"
|
||||||
|
:key="color"
|
||||||
|
:class="{ active: currentColor === color }"
|
||||||
class="dot"
|
class="dot"
|
||||||
:class="{ active: currentColor === 'black' }"
|
:style="`background-color: ${color}`"
|
||||||
style="background-color: black"
|
@click="changeColor(color)"
|
||||||
@click="changeColor('black')"
|
|
||||||
>
|
>
|
||||||
<q-icon
|
<q-icon
|
||||||
v-if="currentColor === 'black'"
|
v-if="currentColor === color"
|
||||||
name="mdi-check"
|
name="mdi-check"
|
||||||
color="white"
|
color="white"
|
||||||
size="sm"
|
size="sm"
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
<span
|
</article>
|
||||||
:class="{ active: currentColor === 'red' }"
|
|
||||||
class="dot"
|
|
||||||
style="background-color: red"
|
|
||||||
@click="changeColor('red')"
|
|
||||||
>
|
|
||||||
<q-icon
|
|
||||||
v-if="currentColor === 'red'"
|
|
||||||
name="mdi-check"
|
|
||||||
color="white"
|
|
||||||
size="sm"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
<span
|
|
||||||
:class="{ active: currentColor === 'blue' }"
|
|
||||||
class="dot"
|
|
||||||
style="background-color: blue"
|
|
||||||
@click="changeColor('blue')"
|
|
||||||
>
|
|
||||||
<q-icon
|
|
||||||
v-if="currentColor === 'blue'"
|
|
||||||
name="mdi-check"
|
|
||||||
color="white"
|
|
||||||
size="sm"
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<canvas
|
<canvas
|
||||||
class="signature-canvas"
|
class="signature-canvas"
|
||||||
ref="canvasRef"
|
ref="canvasRef"
|
||||||
id="signature-pad"
|
id="signature-pad"
|
||||||
width="700"
|
width="766"
|
||||||
height="310"
|
height="364"
|
||||||
></canvas>
|
></canvas>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</section>
|
||||||
|
|
||||||
<div v-show="tab === 'upload'" class="q-pa-md">
|
<section v-show="tab === 'upload'" class="q-pa-md col">
|
||||||
<div
|
<div
|
||||||
class="bordered upload-border rounded column items-center justify-center"
|
class="bordered upload-border rounded column items-center justify-center full-height"
|
||||||
style="height: 312px"
|
|
||||||
>
|
>
|
||||||
<q-img
|
<q-img
|
||||||
v-show="profileUrl"
|
v-show="imgUrl"
|
||||||
ref="imageRef"
|
ref="imageRef"
|
||||||
:src="profileUrl ?? ''"
|
:src="imgUrl ?? ''"
|
||||||
style="object-fit: cover; width: 100%; height: 100%"
|
style="object-fit: cover; width: 100%; height: 100%"
|
||||||
/>
|
/>
|
||||||
<div v-if="!profileUrl">
|
<div v-if="!imgUrl">
|
||||||
<q-icon
|
<q-icon
|
||||||
name="mdi-cloud-upload"
|
name="mdi-cloud-upload"
|
||||||
size="10rem"
|
size="10rem"
|
||||||
style="color: hsla(var(--text-mute) / 0.2)"
|
style="color: hsla(var(--text-mute) / 0.2)"
|
||||||
/>
|
/>
|
||||||
<div>
|
<div class="text-center">
|
||||||
<q-btn
|
<q-btn
|
||||||
unelevated
|
unelevated
|
||||||
color="info"
|
color="info"
|
||||||
:label="$t('uploadFile')"
|
:label="$t('general.upload')"
|
||||||
icon="mdi-plus"
|
icon="mdi-plus"
|
||||||
@click="inputFile.click()"
|
@click="inputFile.click()"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|
|
||||||
|
|
@ -508,7 +508,7 @@ onMounted(async () => {
|
||||||
<q-btn
|
<q-btn
|
||||||
flat
|
flat
|
||||||
dense
|
dense
|
||||||
:label="$t('clear')"
|
:label="$t('general.clear')"
|
||||||
@click="
|
@click="
|
||||||
() => {
|
() => {
|
||||||
canvasRef.clearCanvas(), canvasRef.clearUpload();
|
canvasRef.clearCanvas(), canvasRef.clearUpload();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue