2020-03-30 06:45:06 +00:00
|
|
|
<template>
|
2020-12-07 08:18:41 +00:00
|
|
|
<file-upload
|
|
|
|
:size="4096 * 2048"
|
|
|
|
accept="image/*, application/pdf, audio/mpeg, video/mp4, audio/ogg, text/csv"
|
|
|
|
@input-file="onFileUpload"
|
|
|
|
>
|
2021-04-15 16:58:19 +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';
|
2021-04-15 16:58:19 +00:00
|
|
|
import { checkFileSizeLimit } from 'shared/helpers/FileHelper';
|
|
|
|
import { MAXIMUM_FILE_UPLOAD_SIZE } from 'shared/constants/messages';
|
|
|
|
import { BUS_EVENTS } from 'shared/constants/busEvents';
|
2020-03-30 06:45:06 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: { FileUpload, Spinner },
|
|
|
|
props: {
|
|
|
|
onAttach: {
|
|
|
|
type: Function,
|
|
|
|
default: () => {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return { isUploading: false };
|
|
|
|
},
|
2021-07-13 06:01:21 +00:00
|
|
|
computed: {
|
|
|
|
fileUploadSizeLimit() {
|
|
|
|
return MAXIMUM_FILE_UPLOAD_SIZE;
|
|
|
|
},
|
|
|
|
},
|
2020-03-30 06:45:06 +00:00
|
|
|
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) {
|
2021-04-15 16:58:19 +00:00
|
|
|
if (!file) {
|
|
|
|
return;
|
|
|
|
}
|
2020-03-30 06:45:06 +00:00
|
|
|
this.isUploading = true;
|
|
|
|
try {
|
2021-04-15 16:58:19 +00:00
|
|
|
if (checkFileSizeLimit(file, MAXIMUM_FILE_UPLOAD_SIZE)) {
|
|
|
|
const thumbUrl = window.URL.createObjectURL(file.file);
|
|
|
|
await this.onAttach({
|
|
|
|
fileType: this.getFileType(file.type),
|
|
|
|
file: file.file,
|
|
|
|
thumbUrl,
|
|
|
|
});
|
|
|
|
} else {
|
2021-07-13 06:01:21 +00:00
|
|
|
window.bus.$emit(BUS_EVENTS.SHOW_ALERT, {
|
|
|
|
message: this.$t('FILE_SIZE_LIMIT', {
|
|
|
|
MAXIMUM_FILE_UPLOAD_SIZE: this.fileUploadSizeLimit,
|
|
|
|
}),
|
|
|
|
});
|
2021-04-15 16:58:19 +00:00
|
|
|
}
|
2020-03-30 06:45:06 +00:00
|
|
|
} catch (error) {
|
|
|
|
// Error
|
|
|
|
}
|
|
|
|
this.isUploading = false;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<style scoped lang="scss">
|
|
|
|
@import '~widget/assets/scss/variables.scss';
|
2021-09-02 06:43:53 +00:00
|
|
|
@import '~widget/assets/scss/mixins.scss';
|
2020-03-30 06:45:06 +00:00
|
|
|
|
|
|
|
.attachment-button {
|
2021-09-02 06:43:53 +00:00
|
|
|
@include button-size;
|
|
|
|
|
2020-03-30 06:45:06 +00:00
|
|
|
background: transparent;
|
|
|
|
border: 0;
|
|
|
|
cursor: pointer;
|
|
|
|
position: relative;
|
|
|
|
width: 20px;
|
2021-09-02 06:43:53 +00:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
2020-03-30 06:45:06 +00:00
|
|
|
|
|
|
|
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>
|