skillbox/client/src/components/content-forms/ImageForm.vue

83 lines
1.8 KiB
Vue

<template>
<div class="image-form">
<div v-if="!value.url" ref="uploadcare-panel"></div>
<div v-if="value.url">
<img :src="previewUrl">
</div>
</div>
</template>
<script>
import uploadcare from 'uploadcare-widget';
export default {
props: ['value', 'index'],
mounted() {
let uploadcarePanel = openImagePanel(this.$refs['uploadcare-panel']);
uploadcarePanel.done(panelResult => {
console.log(panelResult);
panelResult.done(fileInfo => {
console.log(fileInfo);
this.$emit('link-change-url', fileInfo.cdnUrl, this.index)
});
panelResult.progress(p => {
console.log(p);
});
panelResult.fail(uploadResult => {
console.log('fail');
console.log(uploadResult);
});
});
function openImagePanel(panelElement) {
return uploadcare.openPanel(panelElement, null, {
tabs: ['file'],
publicKey: '78212ff39934a59775ac'
});
}
},
computed: {
previewUrl: function() {
console.log(this.value);
if (this.value && this.value.url) {
return this.value.url + '-/preview/200x200/';
}
return null;
}
}
}
</script>
<style scoped lang="scss">
@import "@/styles/_variables.scss";
.image-form {
&__file-input {
width: 0.1px;
height: 0.1px;
overflow: hidden;
opacity: 0;
position: absolute;
z-index: -1;
& + label {
cursor: pointer;
background-color: $color-lightgrey;
height: 150px;
display: flex;
width: 100%;
justify-content: center;
align-items: center;
font-family: $sans-serif-font-family;
font-weight: 500;
text-decoration: underline;
}
}
}
</style>