mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-05 13:10:24 +00:00
Image failed to load placeholder (#531)
* Image failed to load placeholder * Use broken image placeholder in gallery * nit
This commit is contained in:
58
src/components/common/ComfyImage.vue
Normal file
58
src/components/common/ComfyImage.vue
Normal file
@@ -0,0 +1,58 @@
|
||||
<!-- A image with placeholder fallback on error -->
|
||||
<template>
|
||||
<img
|
||||
:src="src"
|
||||
@error="handleImageError"
|
||||
:class="[{ 'broken-image': imageBroken }, ...classArray]"
|
||||
/>
|
||||
<div v-if="imageBroken" class="broken-image-placeholder">
|
||||
<i class="pi pi-image"></i>
|
||||
<span>{{ $t('imageFailedToLoad') }}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
|
||||
const props = defineProps<{
|
||||
src: string
|
||||
class?: string | string[] | object
|
||||
}>()
|
||||
|
||||
const imageBroken = ref(false)
|
||||
const handleImageError = (e: Event) => {
|
||||
imageBroken.value = true
|
||||
}
|
||||
|
||||
const classArray = computed(() => {
|
||||
if (Array.isArray(props.class)) {
|
||||
return props.class
|
||||
} else if (typeof props.class === 'string') {
|
||||
return props.class.split(' ')
|
||||
} else if (typeof props.class === 'object') {
|
||||
return Object.keys(props.class).filter((key) => props.class[key])
|
||||
}
|
||||
return []
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.broken-image {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.broken-image-placeholder {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 2rem;
|
||||
}
|
||||
|
||||
.broken-image-placeholder i {
|
||||
font-size: 3rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
</style>
|
||||
@@ -13,7 +13,7 @@
|
||||
:showThumbnails="false"
|
||||
>
|
||||
<template #item="{ item }">
|
||||
<img :src="item.url" alt="gallery item" class="galleria-image" />
|
||||
<ComfyImage :key="item.url" :src="item.url" class="galleria-image" />
|
||||
</template>
|
||||
</Galleria>
|
||||
</template>
|
||||
@@ -22,6 +22,7 @@
|
||||
import { defineProps, ref, watch, onMounted, onUnmounted } from 'vue'
|
||||
import Galleria from 'primevue/galleria'
|
||||
import { ResultItemImpl } from '@/stores/queueStore'
|
||||
import ComfyImage from '@/components/common/ComfyImage.vue'
|
||||
|
||||
const galleryVisible = ref(false)
|
||||
|
||||
@@ -85,8 +86,10 @@ onUnmounted(() => {
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.galleria-image {
|
||||
<style>
|
||||
/* PrimeVue's galleria teleports the fullscreen gallery out of subtree so we
|
||||
cannot use scoped style here. */
|
||||
img.galleria-image {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
object-fit: contain;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
rounded
|
||||
/>
|
||||
</div>
|
||||
<img :src="result.url" class="task-output-image" />
|
||||
<ComfyImage :src="result.url" class="task-output-image" />
|
||||
</template>
|
||||
<!-- TODO: handle more media types -->
|
||||
<div v-else class="task-result-preview">
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ResultItemImpl } from '@/stores/queueStore'
|
||||
import ComfyImage from '@/components/common/ComfyImage.vue'
|
||||
import Button from 'primevue/button'
|
||||
import { onMounted, ref } from 'vue'
|
||||
|
||||
@@ -31,7 +32,7 @@ const props = defineProps<{
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'preview', ResultItemImpl): void
|
||||
(e: 'preview', result: ResultItemImpl): void
|
||||
}>()
|
||||
|
||||
const resultContainer = ref<HTMLElement | null>(null)
|
||||
@@ -57,7 +58,7 @@ onMounted(() => {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.task-output-image {
|
||||
:deep(.task-output-image) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
|
||||
@@ -2,6 +2,7 @@ import { createI18n } from 'vue-i18n'
|
||||
|
||||
const messages = {
|
||||
en: {
|
||||
imageFailedToLoad: 'Image failed to load',
|
||||
reconnecting: 'Reconnecting',
|
||||
reconnected: 'Reconnected',
|
||||
delete: 'Delete',
|
||||
@@ -27,6 +28,7 @@ const messages = {
|
||||
}
|
||||
},
|
||||
zh: {
|
||||
imageFailedToLoad: '图像加载失败',
|
||||
reconnecting: '重新连接中',
|
||||
reconnected: '已重新连接',
|
||||
delete: '删除',
|
||||
|
||||
Reference in New Issue
Block a user