mirror of
https://github.com/hay-kot/mealie.git
synced 2025-07-05 20:42:23 -07:00
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Docker Nightly Production / Backend Server Tests (push) Waiting to run
Docker Nightly Production / Frontend Tests (push) Waiting to run
Docker Nightly Production / Build Package (push) Waiting to run
Docker Nightly Production / Build Tagged Release (push) Blocked by required conditions
Docker Nightly Production / Notify Discord (push) Blocked by required conditions
Release Drafter / ✏️ Draft release (push) Waiting to run
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com> Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
129 lines
2.3 KiB
Vue
129 lines
2.3 KiB
Vue
<template>
|
|
<v-img
|
|
v-if="!fallBackImage"
|
|
:height="height"
|
|
cover
|
|
min-height="125"
|
|
max-height="fill-height"
|
|
:src="getImage(recipeId)"
|
|
@click="$emit('click')"
|
|
@load="fallBackImage = false"
|
|
@error="fallBackImage = true"
|
|
>
|
|
<slot />
|
|
</v-img>
|
|
<div
|
|
v-else
|
|
class="icon-slot"
|
|
@click="$emit('click')"
|
|
>
|
|
<v-icon
|
|
color="primary"
|
|
class="icon-position"
|
|
:size="iconSize"
|
|
>
|
|
{{ $globals.icons.primary }}
|
|
</v-icon>
|
|
<slot />
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import { useStaticRoutes, useUserApi } from "~/composables/api";
|
|
|
|
export default defineNuxtComponent({
|
|
props: {
|
|
tiny: {
|
|
type: Boolean,
|
|
default: null,
|
|
},
|
|
small: {
|
|
type: Boolean,
|
|
default: null,
|
|
},
|
|
large: {
|
|
type: Boolean,
|
|
default: null,
|
|
},
|
|
iconSize: {
|
|
type: [Number, String],
|
|
default: 100,
|
|
},
|
|
slug: {
|
|
type: String,
|
|
default: null,
|
|
},
|
|
recipeId: {
|
|
type: String,
|
|
required: true,
|
|
},
|
|
imageVersion: {
|
|
type: String,
|
|
default: null,
|
|
},
|
|
height: {
|
|
type: [Number, String],
|
|
default: "100%",
|
|
},
|
|
},
|
|
emits: ["click"],
|
|
setup(props) {
|
|
const api = useUserApi();
|
|
|
|
const { recipeImage, recipeSmallImage, recipeTinyImage } = useStaticRoutes();
|
|
|
|
const fallBackImage = ref(false);
|
|
const imageSize = computed(() => {
|
|
if (props.tiny) return "tiny";
|
|
if (props.small) return "small";
|
|
if (props.large) return "large";
|
|
return "large";
|
|
});
|
|
|
|
watch(
|
|
() => props.recipeId,
|
|
() => {
|
|
fallBackImage.value = false;
|
|
},
|
|
);
|
|
|
|
function getImage(recipeId: string) {
|
|
switch (imageSize.value) {
|
|
case "tiny":
|
|
return recipeTinyImage(recipeId, props.imageVersion);
|
|
case "small":
|
|
return recipeSmallImage(recipeId, props.imageVersion);
|
|
case "large":
|
|
return recipeImage(recipeId, props.imageVersion);
|
|
}
|
|
}
|
|
|
|
return {
|
|
api,
|
|
fallBackImage,
|
|
imageSize,
|
|
getImage,
|
|
};
|
|
},
|
|
});
|
|
</script>
|
|
|
|
<style scoped>
|
|
.icon-slot {
|
|
position: relative;
|
|
}
|
|
|
|
.icon-slot > div {
|
|
top: 0;
|
|
position: absolute;
|
|
z-index: 1;
|
|
}
|
|
|
|
.icon-position {
|
|
opacity: 0.8;
|
|
display: flex !important;
|
|
position: relative;
|
|
margin-left: auto !important;
|
|
margin-right: auto !important;
|
|
}
|
|
</style>
|