2022-12-08 11:04:25 +00:00
|
|
|
<template>
|
|
|
|
<div v-for="(file, index) of files" :key="file.name + file.type + file.size" class="p-fileupload-file">
|
|
|
|
<img role="presentation" class="p-fileupload-file-thumbnail" :alt="file.name" :src="file.objectURL" :width="previewWidth" />
|
|
|
|
<div class="p-fileupload-file-details">
|
|
|
|
<div class="p-fileupload-file-name">{{ file.name }}</div>
|
|
|
|
<span class="p-fileupload-file-size">{{ formatSize(file.size) }}</span>
|
|
|
|
<FileUploadBadge :value="badgeValue" class="p-fileupload-file-badge" :severity="badgeSeverity" />
|
|
|
|
</div>
|
|
|
|
<div class="p-fileupload-file-actions">
|
2023-04-15 11:34:56 +00:00
|
|
|
<FileUploadButton @click="$emit('remove', index)" text rounded severity="danger" class="p-fileupload-file-remove">
|
|
|
|
<template #icon="iconProps">
|
|
|
|
<component v-if="templates.fileremoveicon" :is="templates.fileremoveicon" :class="iconProps.class" :file="file" :index="index" />
|
|
|
|
<component v-else :is="'TimesIcon'" :class="iconProps.class" aria-hidden="true" />
|
|
|
|
</template>
|
|
|
|
</FileUploadButton>
|
2022-12-08 11:04:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Badge from 'primevue/badge';
|
|
|
|
import Button from 'primevue/button';
|
2023-04-15 11:34:56 +00:00
|
|
|
import TimesIcon from 'primevue/icon/times';
|
2022-12-08 11:04:25 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
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) {
|
|
|
|
if (bytes === 0) {
|
|
|
|
return '0 B';
|
|
|
|
}
|
|
|
|
|
|
|
|
let k = 1000,
|
|
|
|
dm = 3,
|
|
|
|
sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
|
|
|
i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
|
|
|
|
|
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
FileUploadButton: Button,
|
2023-04-15 11:34:56 +00:00
|
|
|
FileUploadBadge: Badge,
|
|
|
|
TimesIcon
|
2022-12-08 11:04:25 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|