2019-05-22 14:12:11 +02:00
|
|
|
<template>
|
2019-06-17 17:15:27 +02:00
|
|
|
<div class="root">
|
2019-10-12 19:23:32 +02:00
|
|
|
<figure class="image" v-if="imageSrc">
|
2020-02-18 08:57:00 +01:00
|
|
|
<img :src="imageSrc" />
|
2019-10-12 19:23:32 +02:00
|
|
|
</figure>
|
|
|
|
<figure class="image is-128x128" v-else>
|
|
|
|
<div class="image-placeholder">
|
|
|
|
<span class="has-text-centered">{{ textFallback }}</span>
|
|
|
|
</div>
|
2019-06-17 17:15:27 +02:00
|
|
|
</figure>
|
|
|
|
|
2019-10-12 19:23:32 +02:00
|
|
|
<b-upload @input="onFileChanged" :accept="accept">
|
2019-06-17 17:15:27 +02:00
|
|
|
<a class="button is-primary">
|
|
|
|
<b-icon icon="upload"></b-icon>
|
2020-02-18 08:57:00 +01:00
|
|
|
<span>{{ $t("Click to upload") }}</span>
|
2019-06-17 17:15:27 +02:00
|
|
|
</a>
|
|
|
|
</b-upload>
|
|
|
|
</div>
|
2019-05-22 14:12:11 +02:00
|
|
|
</template>
|
|
|
|
|
2019-10-12 19:23:32 +02:00
|
|
|
<style scoped lang="scss">
|
2020-02-18 08:57:00 +01:00
|
|
|
.root {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
2019-06-17 17:15:27 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
figure.image {
|
|
|
|
margin-right: 30px;
|
|
|
|
max-height: 200px;
|
|
|
|
max-width: 200px;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
2019-06-17 17:15:27 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
.image-placeholder {
|
|
|
|
background-color: grey;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
border-radius: 100%;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
span {
|
|
|
|
flex: 1;
|
|
|
|
color: #eee;
|
2019-06-17 17:15:27 +02:00
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
2019-06-17 17:15:27 +02:00
|
|
|
</style>
|
|
|
|
|
2019-05-22 14:12:11 +02:00
|
|
|
<script lang="ts">
|
2020-02-18 08:57:00 +01:00
|
|
|
import { Component, Model, Prop, Vue, Watch } from "vue-property-decorator";
|
2019-05-22 14:12:11 +02:00
|
|
|
|
|
|
|
@Component
|
|
|
|
export default class PictureUpload extends Vue {
|
2020-02-18 08:57:00 +01:00
|
|
|
@Model("change", { type: File }) readonly pictureFile!: File;
|
|
|
|
|
|
|
|
@Prop({ type: String, required: false, default: "image/gif,image/png,image/jpeg,image/webp" })
|
|
|
|
accept!: string;
|
|
|
|
|
|
|
|
@Prop({
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default() {
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
return this.$t("Avatar");
|
|
|
|
},
|
|
|
|
})
|
|
|
|
textFallback!: string;
|
2019-06-17 17:15:27 +02:00
|
|
|
|
|
|
|
imageSrc: string | null = null;
|
|
|
|
|
2019-09-09 11:21:42 +02:00
|
|
|
mounted() {
|
|
|
|
this.updatePreview(this.pictureFile);
|
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
@Watch("pictureFile")
|
2019-09-09 11:21:42 +02:00
|
|
|
onPictureFileChanged(val: File) {
|
2019-06-17 17:15:27 +02:00
|
|
|
this.updatePreview(val);
|
|
|
|
}
|
2019-05-22 14:12:11 +02:00
|
|
|
|
|
|
|
onFileChanged(file: File) {
|
2020-02-18 08:57:00 +01:00
|
|
|
this.$emit("change", file);
|
2019-06-17 17:15:27 +02:00
|
|
|
|
|
|
|
this.updatePreview(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
private updatePreview(file?: File) {
|
|
|
|
if (file) {
|
|
|
|
this.imageSrc = URL.createObjectURL(file);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.imageSrc = null;
|
2019-05-22 14:12:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|