diff --git a/src/components/ui/VnImg.vue b/src/components/ui/VnImg.vue new file mode 100644 index 000000000..9e12cf1b9 --- /dev/null +++ b/src/components/ui/VnImg.vue @@ -0,0 +1,68 @@ + + + + + + + + + diff --git a/src/pages/Item/Card/ItemDescriptorImage.vue b/src/pages/Item/Card/ItemDescriptorImage.vue index f16a57548..0523f0c10 100644 --- a/src/pages/Item/Card/ItemDescriptorImage.vue +++ b/src/pages/Item/Card/ItemDescriptorImage.vue @@ -3,8 +3,7 @@ import { ref, onMounted } from 'vue'; import { useI18n } from 'vue-i18n'; import EditPictureForm from 'components/EditPictureForm.vue'; - -import { useSession } from 'src/composables/useSession'; +import VnImg from 'src/components/ui/VnImg.vue'; import axios from 'axios'; const $props = defineProps({ @@ -27,19 +26,12 @@ const $props = defineProps({ }); const { t } = useI18n(); -const { getTokenMultimedia } = useSession(); const image = ref(null); const editPhotoFormDialog = ref(null); const showEditPhotoForm = ref(false); 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 = () => { showEditPhotoForm.value = !showEditPhotoForm.value; }; @@ -62,14 +54,20 @@ const getWarehouseName = async (warehouseFk) => { }; onMounted(async () => { - getItemAvatar(); getItemConfigs(); + image.value.store.$subscribe((x, v) => { + handlePhotoUpdated(x.events.effect.newValue); + }); }); + +const handlePhotoUpdated = (url = null) => { + image.value.reload(url); +}; - + @@ -82,7 +80,7 @@ onMounted(async () => { - + { collection="catalog" :id="entityId" @close-form="toggleEditPictureForm()" - @on-photo-uploaded="getItemAvatar()" + @on-photo-uploaded="handlePhotoUpdated" /> diff --git a/src/stores/useImagesStore.js b/src/stores/useImagesStore.js new file mode 100644 index 000000000..d2edf1110 --- /dev/null +++ b/src/stores/useImagesStore.js @@ -0,0 +1,16 @@ +import { defineStore } from 'pinia'; + +export const useImagesStore = defineStore('imagesStore', { + state: () => ({ + images: new Map(), + }), + getters: { + get: (state) => () => state.images(), + }, + actions: { + setImage(value) { + const [url, query] = value.split('?'); + this.images.set(url, value); + }, + }, +});