2022-04-15 14:24:30 +00:00
|
|
|
<template>
|
2022-05-10 16:05:03 +00:00
|
|
|
<div :class="cssClass" :title="file.message" class="upload-item">
|
|
|
|
<span :style="{ width: `${file.progress}%` }" class="progress"/>
|
2022-04-15 14:24:30 +00:00
|
|
|
<span class="details">
|
|
|
|
<span class="name">{{ file.name }}</span>
|
|
|
|
<span class="controls">
|
2022-05-10 16:05:03 +00:00
|
|
|
<Btn v-if="canRetry" icon-only title="Retry" transparent unrounded @click="retry">
|
2022-04-15 14:24:30 +00:00
|
|
|
<i class="fa fa-repeat"></i>
|
|
|
|
</Btn>
|
2022-05-10 16:05:03 +00:00
|
|
|
<Btn v-if="canRemove" icon-only title="Remove" transparent unrounded @click="remove">
|
2022-04-15 14:24:30 +00:00
|
|
|
<i class="fa fa-times"></i>
|
|
|
|
</Btn>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
<script lang="ts" setup>
|
2022-05-10 16:05:03 +00:00
|
|
|
import slugify from 'slugify'
|
2022-04-15 17:00:08 +00:00
|
|
|
import { computed, defineAsyncComponent, toRefs } from 'vue'
|
2022-04-15 14:24:30 +00:00
|
|
|
import { UploadFile } from '@/config'
|
2022-04-24 08:50:45 +00:00
|
|
|
import { uploadService } from '@/services'
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-21 18:39:18 +00:00
|
|
|
const Btn = defineAsyncComponent(() => import('@/components/ui/Btn.vue'))
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const props = defineProps<{ file: UploadFile }>()
|
|
|
|
const { file } = toRefs(props)
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-15 17:00:08 +00:00
|
|
|
const canRetry = computed(() => file.value.status === 'Canceled' || file.value.status === 'Errored')
|
|
|
|
const canRemove = computed(() => file.value.status !== 'Uploading') // we're not supporting cancel tokens (yet).
|
2022-05-10 16:05:03 +00:00
|
|
|
const cssClass = computed(() => slugify(file.value.status).toLowerCase())
|
2022-04-15 14:24:30 +00:00
|
|
|
|
2022-04-24 08:50:45 +00:00
|
|
|
const remove = () => uploadService.remove(file.value)
|
|
|
|
const retry = () => uploadService.retry(file.value)
|
2022-04-15 14:24:30 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.upload-item {
|
|
|
|
position: relative;
|
|
|
|
margin-bottom: 5px;
|
|
|
|
border-radius: 3px;
|
|
|
|
min-height: 32px;
|
|
|
|
overflow: hidden;
|
|
|
|
background: var(--color-bg-secondary);
|
|
|
|
|
|
|
|
.progress {
|
|
|
|
position: absolute;
|
|
|
|
height: 100%;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
background: var(--color-highlight);
|
|
|
|
z-index: 0;
|
|
|
|
transition: .3s ease-out;
|
|
|
|
}
|
|
|
|
|
2022-05-10 16:05:03 +00:00
|
|
|
&.uploaded {
|
2022-04-15 14:24:30 +00:00
|
|
|
background: var(--color-green);
|
|
|
|
|
|
|
|
.progress {
|
|
|
|
background: transparent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-10 16:05:03 +00:00
|
|
|
&.errored {
|
2022-04-15 14:24:30 +00:00
|
|
|
background: var(--color-red);
|
|
|
|
|
|
|
|
.progress {
|
|
|
|
background: transparent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.details {
|
|
|
|
z-index: 1;
|
|
|
|
position: absolute;
|
|
|
|
height: 100%;
|
|
|
|
width: 100%;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
|
|
.name {
|
|
|
|
padding: 0 12px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.controls {
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
|
|
|
|
button {
|
|
|
|
padding: 8px 8px;
|
|
|
|
background: rgba(0, 0, 0, .1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|