2020-03-30 06:45:06 +00:00
|
|
|
<template>
|
2020-04-02 06:58:38 +00:00
|
|
|
<file-upload :size="4096 * 2048" @input-file="onFileUpload">
|
2020-03-30 06:45:06 +00:00
|
|
|
<span class="attachment-button ">
|
2020-04-29 08:24:56 +00:00
|
|
|
<i v-if="!isUploading.image" class="ion-android-attach" />
|
2020-03-30 06:45:06 +00:00
|
|
|
<spinner v-if="isUploading" size="small" />
|
|
|
|
</span>
|
|
|
|
</file-upload>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import FileUpload from 'vue-upload-component';
|
|
|
|
import Spinner from 'shared/components/Spinner.vue';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: { FileUpload, Spinner },
|
|
|
|
props: {
|
|
|
|
onAttach: {
|
|
|
|
type: Function,
|
|
|
|
default: () => {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return { isUploading: false };
|
|
|
|
},
|
|
|
|
methods: {
|
2020-04-02 06:58:38 +00:00
|
|
|
getFileType(fileType) {
|
|
|
|
return fileType.includes('image') ? 'image' : 'file';
|
|
|
|
},
|
2020-03-30 06:45:06 +00:00
|
|
|
async onFileUpload(file) {
|
|
|
|
this.isUploading = true;
|
|
|
|
try {
|
|
|
|
const thumbUrl = window.URL.createObjectURL(file.file);
|
|
|
|
await this.onAttach({
|
2020-04-02 06:58:38 +00:00
|
|
|
fileType: this.getFileType(file.type),
|
2020-03-30 06:45:06 +00:00
|
|
|
file: file.file,
|
|
|
|
thumbUrl,
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
// Error
|
|
|
|
}
|
|
|
|
this.isUploading = false;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
|
|
@import '~widget/assets/scss/variables.scss';
|
|
|
|
|
|
|
|
.attachment-button {
|
|
|
|
background: transparent;
|
|
|
|
border: 0;
|
|
|
|
cursor: pointer;
|
|
|
|
position: relative;
|
|
|
|
width: 20px;
|
|
|
|
|
|
|
|
i {
|
2020-04-29 08:24:56 +00:00
|
|
|
font-size: $font-size-large;
|
|
|
|
color: $color-gray;
|
2020-03-30 06:45:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|
2020-04-29 08:24:56 +00:00
|
|
|
<style lang="scss">
|
|
|
|
.file-uploads .attachment-button + label {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
</style>
|