|
|
@@ -9,7 +9,7 @@
|
|
|
<div
|
|
|
v-if="!imageUrl"
|
|
|
class="full-width full-height flex flex-center column gap-xs no-image-state"
|
|
|
- @click="triggerFilePicker"
|
|
|
+ @click="openChangeDialog"
|
|
|
>
|
|
|
<q-icon name="add_photo_alternate" size="32px" color="grey-5" />
|
|
|
<span class="text-grey-6" style="font-size: 12px">adicione uma imagem</span>
|
|
|
@@ -26,7 +26,7 @@
|
|
|
icon="edit"
|
|
|
color="grey-8"
|
|
|
text-color="white"
|
|
|
- @click.stop="triggerFilePicker"
|
|
|
+ @click.stop="openChangeDialog"
|
|
|
>
|
|
|
<q-tooltip>Trocar imagem</q-tooltip>
|
|
|
</q-btn>
|
|
|
@@ -44,43 +44,29 @@
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
- <q-file
|
|
|
- ref="filePickerRef"
|
|
|
- v-model="fileModel"
|
|
|
- accept="image/*"
|
|
|
- style="display: none"
|
|
|
- @update:model-value="onFileSelected"
|
|
|
- />
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script setup>
|
|
|
import { ref } from "vue";
|
|
|
+import { useQuasar } from "quasar";
|
|
|
+import ChangeImageDialog from "src/components/shared/ChangeImageDialog.vue";
|
|
|
|
|
|
const emit = defineEmits(["update:file"]);
|
|
|
|
|
|
-const filePickerRef = ref(null);
|
|
|
-const fileModel = ref(null);
|
|
|
+const $q = useQuasar();
|
|
|
const imageUrl = ref(null);
|
|
|
const isDragOver = ref(false);
|
|
|
|
|
|
-function triggerFilePicker() {
|
|
|
- filePickerRef.value.pickFiles();
|
|
|
-}
|
|
|
-
|
|
|
-function onFileSelected(file) {
|
|
|
- if (!file) return;
|
|
|
- const reader = new FileReader();
|
|
|
- reader.onload = (e) => {
|
|
|
- imageUrl.value = e.target.result;
|
|
|
- };
|
|
|
- reader.readAsDataURL(file);
|
|
|
- emit("update:file", file);
|
|
|
+function openChangeDialog() {
|
|
|
+ $q.dialog({ component: ChangeImageDialog }).onOk(({ file, previewUrl }) => {
|
|
|
+ imageUrl.value = previewUrl;
|
|
|
+ emit("update:file", file);
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
function removeImage() {
|
|
|
imageUrl.value = null;
|
|
|
- fileModel.value = null;
|
|
|
emit("update:file", null);
|
|
|
}
|
|
|
|
|
|
@@ -88,8 +74,12 @@ function onDrop(event) {
|
|
|
isDragOver.value = false;
|
|
|
const file = event.dataTransfer.files[0];
|
|
|
if (file && file.type.startsWith("image/")) {
|
|
|
- fileModel.value = file;
|
|
|
- onFileSelected(file);
|
|
|
+ const reader = new FileReader();
|
|
|
+ reader.onload = (e) => {
|
|
|
+ imageUrl.value = e.target.result;
|
|
|
+ };
|
|
|
+ reader.readAsDataURL(file);
|
|
|
+ emit("update:file", file);
|
|
|
}
|
|
|
}
|
|
|
</script>
|