|
@@ -1,3 +1,9 @@
|
|
|
|
|
+<!--
|
|
|
|
|
+Composant Image permettant de charger et d'afficher une image stockée sur les serveurs Opentalent à partir de son id.
|
|
|
|
|
+Permet d'afficher une image par défaut si l'image demandée n'est pas disponible ou invalide.
|
|
|
|
|
+
|
|
|
|
|
+Si la propriété 'upload' est à 'true', propose aussi un input pour uploader une nouvelle image.
|
|
|
|
|
+-->
|
|
|
<template>
|
|
<template>
|
|
|
<main>
|
|
<main>
|
|
|
<div class="image-wrapper" :style="{width: width + 'px'}">
|
|
<div class="image-wrapper" :style="{width: width + 'px'}">
|
|
@@ -7,6 +13,7 @@
|
|
|
:height="height"
|
|
:height="height"
|
|
|
:width="width"
|
|
:width="width"
|
|
|
aspect-ratio="1"
|
|
aspect-ratio="1"
|
|
|
|
|
+ @click="refresh"
|
|
|
>
|
|
>
|
|
|
<template #placeholder>
|
|
<template #placeholder>
|
|
|
<v-row
|
|
<v-row
|
|
@@ -43,8 +50,6 @@
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
<script setup lang="ts">
|
|
|
import {ref, Ref} from "@vue/reactivity";
|
|
import {ref, Ref} from "@vue/reactivity";
|
|
|
-import {useContext} from "unctx";
|
|
|
|
|
-import {useNuxtApp} from "#app";
|
|
|
|
|
import {useImageFetch} from "~/composables/data/useImageFetch";
|
|
import {useImageFetch} from "~/composables/data/useImageFetch";
|
|
|
import {onUnmounted, watch, WatchStopHandle} from "@vue/runtime-core";
|
|
import {onUnmounted, watch, WatchStopHandle} from "@vue/runtime-core";
|
|
|
import {useImageManager} from "~/composables/data/useImageManager";
|
|
import {useImageManager} from "~/composables/data/useImageManager";
|
|
@@ -55,10 +60,6 @@ const props = defineProps({
|
|
|
required: true,
|
|
required: true,
|
|
|
default: null
|
|
default: null
|
|
|
},
|
|
},
|
|
|
- field: {
|
|
|
|
|
- type: String,
|
|
|
|
|
- required: false
|
|
|
|
|
- },
|
|
|
|
|
defaultImage: {
|
|
defaultImage: {
|
|
|
type: String,
|
|
type: String,
|
|
|
required: false
|
|
required: false
|
|
@@ -71,6 +72,10 @@ const props = defineProps({
|
|
|
type: Number,
|
|
type: Number,
|
|
|
required: false
|
|
required: false
|
|
|
},
|
|
},
|
|
|
|
|
+ field: {
|
|
|
|
|
+ type: String,
|
|
|
|
|
+ required: false
|
|
|
|
|
+ },
|
|
|
upload: {
|
|
upload: {
|
|
|
type: Boolean,
|
|
type: Boolean,
|
|
|
required: false,
|
|
required: false,
|
|
@@ -89,27 +94,14 @@ const defaultImagePath = props.defaultImage ?? imageManager.defaultImage
|
|
|
|
|
|
|
|
const openUpload: Ref<Boolean> = ref(false)
|
|
const openUpload: Ref<Boolean> = ref(false)
|
|
|
|
|
|
|
|
-const imageSrc: Ref<string | null> = ref(null)
|
|
|
|
|
-let pending = ref(true)
|
|
|
|
|
-
|
|
|
|
|
-const fetchImage = async () => {
|
|
|
|
|
- pending.value = true
|
|
|
|
|
- imageSrc.value = await imageManager.get(props.id ?? null, defaultImagePath, props.height, props.width)
|
|
|
|
|
- pending.value = false
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-onMounted(
|
|
|
|
|
- () => {
|
|
|
|
|
- fetchImage()
|
|
|
|
|
- }
|
|
|
|
|
-)
|
|
|
|
|
|
|
+const { data: imageSrc, pending, refresh } = fetch(props.id ?? null, defaultImagePath, props.height, props.width)
|
|
|
|
|
|
|
|
const unwatch: WatchStopHandle = watch(() => props.id, async (newValue, oldValue) => {
|
|
const unwatch: WatchStopHandle = watch(() => props.id, async (newValue, oldValue) => {
|
|
|
- await fetchImage()
|
|
|
|
|
|
|
+ await refresh()
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
const onReload = async () => {
|
|
const onReload = async () => {
|
|
|
- await fetchImage()
|
|
|
|
|
|
|
+ await refresh()
|
|
|
openUpload.value = false
|
|
openUpload.value = false
|
|
|
}
|
|
}
|
|
|
|
|
|