0
0
Fork 0

refactor: refs #6896 refactor VnImg

This commit is contained in:
Jon Elias 2024-06-18 13:31:25 +02:00
parent a5f4f85c80
commit 3023280108
4 changed files with 42 additions and 32 deletions

View File

@ -3,4 +3,11 @@ import qFormMixin from './qformMixin';
export default boot(({ app }) => { export default boot(({ app }) => {
app.mixin(qFormMixin); app.mixin(qFormMixin);
app.config.globalProperties.$emitEvent = function (eventName, payload) {
app._instance?.emit(eventName, payload);
};
app.config.globalProperties.$onEvent = function (eventName, callback) {
app._instance?.on(eventName, callback);
};
}); });

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { ref, computed } from 'vue'; import { ref, computed, onMounted } from 'vue';
import { useSession } from 'src/composables/useSession'; import { useSession } from 'src/composables/useSession';
const $props = defineProps({ const $props = defineProps({
@ -23,42 +23,38 @@ const $props = defineProps({
}); });
const show = ref(false); const show = ref(false);
const token = useSession().getTokenMultimedia(); const token = useSession().getTokenMultimedia();
const timeStamp = `timestamp=${Date.now()}`; const timeStamp = ref(`timestamp=${Date.now()}`);
const url = computed( const url = computed(
() => () =>
`/api/${$props.collection}/catalog/${$props.size}/${$props.id}/download?access_token=${token}&${timeStamp}` `/api/${$props.collection}/catalog/${$props.size}/${$props.id}/download?access_token=${token}&${timeStamp.value}`
); );
const emits = defineEmits(['refresh']);
const reload = (emit = false) => {
timeStamp.value = `timestamp=${Date.now()}`;
};
defineExpose({
reload,
});
onMounted(() => {});
</script> </script>
<template> <template>
<QImg <QImg :src="url" v-bind="$attrs" @click="show = !show" spinner-color="primary" />
:src="url"
class="img"
v-bind="$attrs"
@click="show = !show"
spinner-color="primary"
:ratio="1"
/>
<QDialog v-model="show" v-if="$props.zoomSize"> <QDialog v-model="show" v-if="$props.zoomSize">
<QImg <QImg :src="url" class="img_zoom" v-bind="$attrs" spinner-color="primary" />
:src="url"
class="img_zoom"
v-bind="$attrs"
spinner-color="primary"
:ratio="1"
style="border-radius: 0%"
/>
</QDialog> </QDialog>
</template> </template>
<style lang="scss" scoped> <style lang="scss" scoped>
.img { .q-img {
cursor: zoom-in; cursor: zoom-in;
} }
.rounded { .rounded {
border-radius: 50%; border-radius: 50%;
} }
.img_zoom { .img_zoom {
width: 72%; width: 100%;
height: auto; height: auto;
border-radius: 0%;
} }
</style> </style>

View File

@ -4,7 +4,6 @@ import { useI18n } from 'vue-i18n';
import EditPictureForm from 'components/EditPictureForm.vue'; import EditPictureForm from 'components/EditPictureForm.vue';
import VnImg from 'src/components/ui/VnImg.vue'; import VnImg from 'src/components/ui/VnImg.vue';
import { useSession } from 'src/composables/useSession';
import axios from 'axios'; import axios from 'axios';
const $props = defineProps({ const $props = defineProps({
@ -27,19 +26,12 @@ const $props = defineProps({
}); });
const { t } = useI18n(); const { t } = useI18n();
const { getTokenMultimedia } = useSession();
const image = ref(null); const image = ref(null);
const editPhotoFormDialog = ref(null); const editPhotoFormDialog = ref(null);
const showEditPhotoForm = ref(false); const showEditPhotoForm = ref(false);
const warehouseName = ref(null); const warehouseName = ref(null);
const getItemAvatar = async () => {
const token = getTokenMultimedia();
const timeStamp = `timestamp=${Date.now()}`;
image.value = `/api/Images/catalog/200x200/${$props.entityId}/download?access_token=${token}&${timeStamp}`;
};
const toggleEditPictureForm = () => { const toggleEditPictureForm = () => {
showEditPhotoForm.value = !showEditPhotoForm.value; showEditPhotoForm.value = !showEditPhotoForm.value;
}; };
@ -62,14 +54,17 @@ const getWarehouseName = async (warehouseFk) => {
}; };
onMounted(async () => { onMounted(async () => {
getItemAvatar();
getItemConfigs(); getItemConfigs();
}); });
const handlePhotoUpdated = (evt = false) => {
image.value.reload(evt);
};
</script> </script>
<template> <template>
<div class="relative-position"> <div class="relative-position">
<VnImg :id="$props.entityId"> <VnImg ref="image" :id="$props.entityId" @refresh="handlePhotoUpdated(true)">
<template #error> <template #error>
<div class="absolute-full picture text-center q-pa-md flex flex-center"> <div class="absolute-full picture text-center q-pa-md flex flex-center">
<div> <div>
@ -97,7 +92,7 @@ onMounted(async () => {
collection="catalog" collection="catalog"
:id="entityId" :id="entityId"
@close-form="toggleEditPictureForm()" @close-form="toggleEditPictureForm()"
@on-photo-uploaded="getItemAvatar()" @on-photo-uploaded="handlePhotoUpdated"
/> />
</QDialog> </QDialog>
</QBtn> </QBtn>

View File

@ -0,0 +1,12 @@
import { defineStore } from 'pinia';
export const useImagesStore = defineStore('imagesStore', {
state: () => ({
images: {},
}),
actions: {
async pushImage(url, data) {
this.images[url] = data;
},
},
});