2022-12-08 11:04:25 +00:00
|
|
|
<template>
|
2023-05-31 08:53:28 +00:00
|
|
|
<div v-for="(file, index) of files" :key="file.name + file.type + file.size" :class="cx('file')" v-bind="ptm('file')">
|
|
|
|
<img role="presentation" :class="cx('thumbnail')" :alt="file.name" :src="file.objectURL" :width="previewWidth" v-bind="ptm('thumbnail')" />
|
|
|
|
<div :class="cx('details')" v-bind="ptm('details')">
|
|
|
|
<div :class="cx('fileName')" v-bind="ptm('fileName')">{{ file.name }}</div>
|
|
|
|
<span :class="cx('fileSize')" v-bind="ptm('fileSize')">{{ formatSize(file.size) }}</span>
|
2023-06-05 08:10:25 +00:00
|
|
|
<FileUploadBadge :value="badgeValue" :class="cx('badge')" :severity="badgeSeverity" :unstyled="unstyled" :pt="ptm('badge')" />
|
2022-12-08 11:04:25 +00:00
|
|
|
</div>
|
2023-05-31 08:53:28 +00:00
|
|
|
<div :class="cx('actions')" v-bind="ptm('actions')">
|
2023-06-05 08:10:25 +00:00
|
|
|
<FileUploadButton @click="$emit('remove', index)" text rounded severity="danger" :class="cx('removeButton')" :unstyled="unstyled" :pt="ptm('removeButton')">
|
2023-04-15 11:34:56 +00:00
|
|
|
<template #icon="iconProps">
|
|
|
|
<component v-if="templates.fileremoveicon" :is="templates.fileremoveicon" :class="iconProps.class" :file="file" :index="index" />
|
2023-04-28 16:03:29 +00:00
|
|
|
<TimesIcon v-else :class="iconProps.class" aria-hidden="true" v-bind="ptm('removeButton')['icon']" />
|
2023-04-15 11:34:56 +00:00
|
|
|
</template>
|
|
|
|
</FileUploadButton>
|
2022-12-08 11:04:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Badge from 'primevue/badge';
|
2023-04-28 16:03:29 +00:00
|
|
|
import BaseComponent from 'primevue/basecomponent';
|
2022-12-08 11:04:25 +00:00
|
|
|
import Button from 'primevue/button';
|
2023-04-18 12:53:43 +00:00
|
|
|
import TimesIcon from 'primevue/icons/times';
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
export default {
|
2023-06-05 08:56:39 +00:00
|
|
|
name: 'FileContent',
|
2023-07-04 06:29:36 +00:00
|
|
|
hostName: 'FileUpload',
|
2023-04-28 16:03:29 +00:00
|
|
|
extends: BaseComponent,
|
2022-12-08 11:04:25 +00:00
|
|
|
emits: ['remove'],
|
|
|
|
props: {
|
|
|
|
files: {
|
|
|
|
type: Array,
|
|
|
|
default: () => []
|
|
|
|
},
|
|
|
|
badgeSeverity: {
|
|
|
|
type: String,
|
|
|
|
default: 'warning'
|
|
|
|
},
|
|
|
|
badgeValue: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
|
|
|
previewWidth: {
|
|
|
|
type: Number,
|
|
|
|
default: 50
|
2023-04-15 11:34:56 +00:00
|
|
|
},
|
|
|
|
templates: {
|
|
|
|
type: null,
|
|
|
|
default: null
|
2022-12-08 11:04:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
formatSize(bytes) {
|
2023-09-05 02:01:27 +00:00
|
|
|
const k = 1024;
|
|
|
|
const dm = 3;
|
|
|
|
const sizes = this.$primevue.config.locale.fileSizeTypes;
|
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
if (bytes === 0) {
|
2023-09-05 02:01:27 +00:00
|
|
|
return `0 ${sizes[0]}`;
|
2022-12-08 11:04:25 +00:00
|
|
|
}
|
|
|
|
|
2023-09-05 02:01:27 +00:00
|
|
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
|
|
const formattedSize = parseFloat((bytes / Math.pow(k, i)).toFixed(dm));
|
2022-12-08 11:04:25 +00:00
|
|
|
|
2023-09-05 02:01:27 +00:00
|
|
|
return `${formattedSize} ${sizes[i]}`;
|
2022-12-08 11:04:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
FileUploadButton: Button,
|
2023-04-15 11:34:56 +00:00
|
|
|
FileUploadBadge: Badge,
|
|
|
|
TimesIcon
|
2022-12-08 11:04:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|