2021-07-31 15:07:19 -08:00
|
|
|
<template>
|
|
|
|
<div class="text-center">
|
2025-06-20 00:09:12 +07:00
|
|
|
<v-menu
|
|
|
|
v-model="menu"
|
|
|
|
offset-y
|
|
|
|
top
|
|
|
|
nudge-top="6"
|
|
|
|
:close-on-content-click="false"
|
|
|
|
>
|
|
|
|
<template #activator="{ props }">
|
|
|
|
<v-btn
|
|
|
|
color="accent"
|
|
|
|
dark
|
|
|
|
v-bind="props"
|
|
|
|
>
|
|
|
|
<v-icon start>
|
2021-07-31 15:07:19 -08:00
|
|
|
{{ $globals.icons.fileImage }}
|
|
|
|
</v-icon>
|
|
|
|
{{ $t("general.image") }}
|
|
|
|
</v-btn>
|
|
|
|
</template>
|
|
|
|
<v-card width="400">
|
|
|
|
<v-card-title class="headline flex mb-0">
|
|
|
|
<div>
|
|
|
|
{{ $t("recipe.recipe-image") }}
|
|
|
|
</div>
|
2021-08-02 22:15:11 -08:00
|
|
|
<AppButtonUpload
|
2021-07-31 15:07:19 -08:00
|
|
|
class="ml-auto"
|
|
|
|
url="none"
|
|
|
|
file-name="image"
|
|
|
|
:text-btn="false"
|
|
|
|
:post="false"
|
2021-08-01 19:24:47 -08:00
|
|
|
@uploaded="uploadImage"
|
2021-07-31 15:07:19 -08:00
|
|
|
/>
|
|
|
|
</v-card-title>
|
|
|
|
<v-card-text class="mt-n5">
|
|
|
|
<div>
|
2025-06-20 00:09:12 +07:00
|
|
|
<v-text-field
|
|
|
|
v-model="url"
|
|
|
|
:label="$t('general.url')"
|
|
|
|
class="pt-5"
|
|
|
|
clearable
|
|
|
|
:messages="messages"
|
|
|
|
>
|
2021-08-01 19:24:47 -08:00
|
|
|
<template #append-outer>
|
2025-06-20 00:09:12 +07:00
|
|
|
<v-btn
|
|
|
|
class="ml-2"
|
|
|
|
color="primary"
|
|
|
|
:loading="loading"
|
|
|
|
:disabled="!slug"
|
|
|
|
@click="getImageFromURL"
|
|
|
|
>
|
2021-07-31 15:07:19 -08:00
|
|
|
{{ $t("general.get") }}
|
|
|
|
</v-btn>
|
|
|
|
</template>
|
|
|
|
</v-text-field>
|
|
|
|
</div>
|
|
|
|
</v-card-text>
|
|
|
|
</v-card>
|
|
|
|
</v-menu>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-09 07:15:23 +01:00
|
|
|
<script lang="ts">
|
2021-11-06 11:28:47 -08:00
|
|
|
import { useUserApi } from "~/composables/api";
|
2022-01-09 07:15:23 +01:00
|
|
|
|
2021-08-01 19:24:47 -08:00
|
|
|
const REFRESH_EVENT = "refresh";
|
|
|
|
const UPLOAD_EVENT = "upload";
|
2022-01-09 07:15:23 +01:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
export default defineNuxtComponent({
|
2021-07-31 15:07:19 -08:00
|
|
|
props: {
|
2021-08-03 21:38:45 -08:00
|
|
|
slug: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
2022-01-09 07:15:23 +01:00
|
|
|
setup(props, context) {
|
|
|
|
const state = reactive({
|
|
|
|
url: "",
|
|
|
|
loading: false,
|
|
|
|
menu: false,
|
2025-06-20 00:09:12 +07:00
|
|
|
});
|
2021-08-03 21:38:45 -08:00
|
|
|
|
2022-01-09 07:15:23 +01:00
|
|
|
function uploadImage(fileObject: File) {
|
|
|
|
context.emit(UPLOAD_EVENT, fileObject);
|
|
|
|
state.menu = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const api = useUserApi();
|
|
|
|
async function getImageFromURL() {
|
|
|
|
state.loading = true;
|
|
|
|
if (await api.recipes.updateImagebyURL(props.slug, state.url)) {
|
|
|
|
context.emit(REFRESH_EVENT);
|
2021-07-31 15:07:19 -08:00
|
|
|
}
|
2022-01-09 07:15:23 +01:00
|
|
|
state.loading = false;
|
|
|
|
state.menu = false;
|
|
|
|
}
|
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
const i18n = useI18n();
|
2022-01-09 07:15:23 +01:00
|
|
|
const messages = props.slug ? [""] : [i18n.t("recipe.save-recipe-before-use")];
|
|
|
|
|
|
|
|
return {
|
|
|
|
...toRefs(state),
|
|
|
|
uploadImage,
|
|
|
|
getImageFromURL,
|
|
|
|
messages,
|
|
|
|
};
|
2021-07-31 15:07:19 -08:00
|
|
|
},
|
2021-08-03 21:38:45 -08:00
|
|
|
});
|
2021-07-31 15:07:19 -08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped></style>
|