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-11-18 09:48:51 +00:00
|
|
|
<button class="icon-button flex items-center justify-center">
|
|
|
|
<fluent-icon v-if="!isUploading.image" icon="attach" />
|
2020-03-30 06:45:06 +00:00
|
|
|
<spinner v-if="isUploading" size="small" />
|
2021-11-18 09:48:51 +00:00
|
|
|
</button>
|
2020-03-30 06:45:06 +00:00
|
|
|
</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';
|
2021-11-18 09:48:51 +00:00
|
|
|
import FluentIcon from 'shared/components/FluentIcon/Index.vue';
|
2020-03-30 06:45:06 +00:00
|
|
|
export default {
|
2021-11-18 09:48:51 +00:00
|
|
|
components: { FluentIcon, FileUpload, Spinner },
|
2020-03-30 06:45:06 +00:00
|
|
|
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>
|