2021-01-06 12:26:29 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<div
|
|
|
|
v-for="(attachment, index) in attachments"
|
|
|
|
:key="attachment.id"
|
|
|
|
class="preview-item"
|
|
|
|
>
|
|
|
|
<div class="thumb-wrap">
|
|
|
|
<img
|
|
|
|
v-if="isTypeImage(attachment.resource.type)"
|
|
|
|
class="image-thumb"
|
|
|
|
:src="attachment.thumb"
|
|
|
|
/>
|
2021-04-15 16:58:19 +00:00
|
|
|
<span v-else class="attachment-thumb"> 📄 </span>
|
2021-01-06 12:26:29 +00:00
|
|
|
</div>
|
|
|
|
<div class="file-name-wrap">
|
|
|
|
<span class="item">
|
|
|
|
{{ attachment.resource.name }}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div class="file-size-wrap">
|
|
|
|
<span class="item">
|
|
|
|
{{ formatFileSize(attachment.resource.size) }}
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div class="remove-file-wrap">
|
|
|
|
<button
|
|
|
|
class="remove--attachment"
|
|
|
|
@click="() => onRemoveAttachment(index)"
|
|
|
|
>
|
|
|
|
<i class="ion-android-close"></i>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script>
|
2021-04-15 16:58:19 +00:00
|
|
|
import { formatBytes } from 'shared/helpers/FileHelper';
|
2021-01-06 12:26:29 +00:00
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
attachments: {
|
|
|
|
type: Array,
|
|
|
|
default: () => [],
|
|
|
|
},
|
|
|
|
removeAttachment: {
|
|
|
|
type: Function,
|
|
|
|
default: () => {},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onRemoveAttachment(index) {
|
|
|
|
this.removeAttachment(index);
|
|
|
|
},
|
|
|
|
formatFileSize(size) {
|
|
|
|
return formatBytes(size, 0);
|
|
|
|
},
|
|
|
|
isTypeImage(type) {
|
|
|
|
return type.includes('image');
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.preview-item {
|
|
|
|
display: flex;
|
2021-01-13 12:36:25 +00:00
|
|
|
padding: var(--space-slab) 0 0;
|
|
|
|
background: var(--color-background-light);
|
2021-06-20 14:24:57 +00:00
|
|
|
background: var(--b-50);
|
|
|
|
border-radius: var(--border-radius-normal);
|
|
|
|
width: fit-content;
|
|
|
|
padding: var(--space-smaller);
|
|
|
|
margin-top: var(--space-normal);
|
2021-01-06 12:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.thumb-wrap {
|
|
|
|
max-width: var(--space-jumbo);
|
|
|
|
flex-shrink: 0;
|
|
|
|
width: var(--space-medium);
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.image-thumb {
|
|
|
|
width: var(--space-medium);
|
|
|
|
height: var(--space-medium);
|
|
|
|
object-fit: cover;
|
|
|
|
border-radius: var(--border-radius-small);
|
|
|
|
}
|
|
|
|
|
|
|
|
.attachment-thumb {
|
|
|
|
width: var(--space-medium);
|
|
|
|
height: var(--space-medium);
|
|
|
|
font-size: var(--font-size-medium);
|
|
|
|
text-align: center;
|
2021-01-13 12:36:25 +00:00
|
|
|
position: relative;
|
|
|
|
top: -1px;
|
|
|
|
text-align: left;
|
2021-01-06 12:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.file-name-wrap,
|
|
|
|
.file-size-wrap {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2021-01-13 12:36:25 +00:00
|
|
|
padding: 0 var(--space-smaller);
|
2021-01-06 12:26:29 +00:00
|
|
|
|
|
|
|
> .item {
|
|
|
|
margin: 0;
|
|
|
|
font-size: var(--font-size-mini);
|
|
|
|
font-weight: var(--font-weight-medium);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.preview-header {
|
|
|
|
padding: var(--space-slab) var(--space-slab) 0 var(--space-slab);
|
|
|
|
}
|
|
|
|
|
|
|
|
.file-name-wrap {
|
2021-01-13 12:36:25 +00:00
|
|
|
max-width: 50%;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
2021-06-20 14:24:57 +00:00
|
|
|
margin-left: var(--space-small);
|
|
|
|
|
2021-01-13 12:36:25 +00:00
|
|
|
.item {
|
|
|
|
height: var(--space-normal);
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
white-space: nowrap;
|
|
|
|
}
|
2021-01-06 12:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.file-size-wrap {
|
2021-06-20 14:24:57 +00:00
|
|
|
width: 30%;
|
2021-01-13 12:36:25 +00:00
|
|
|
justify-content: center;
|
2021-01-06 12:26:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
.remove-file-wrap {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.remove--attachment {
|
|
|
|
width: var(--space-medium);
|
|
|
|
height: var(--space-medium);
|
|
|
|
border-radius: var(--space-medium);
|
|
|
|
font-size: var(--font-size-small);
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: var(--color-background);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|