-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a print progress bar instead of a spinner
The progress bar is degressive and it's completion time is set based on the number of layer to print
- Loading branch information
Showing
2 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<script setup> | ||
import { onBeforeUnmount, onMounted, ref, toRefs } from 'vue' | ||
import log from '@/utils/logging' | ||
const props = defineProps({ | ||
duration: { | ||
type: Number, | ||
required: true, | ||
}, | ||
barClass: { | ||
type: String, | ||
default: '', | ||
}, | ||
}) | ||
const { duration, barClass } = toRefs(props) | ||
const value = ref(0) | ||
const waitTime = ref(0) | ||
const totalTime = ref(0) | ||
const slot = ref(0) | ||
const maxValue = 100 | ||
let started = null | ||
let timer = null | ||
onMounted(() => { | ||
started = Date.now() | ||
totalTime.value = duration.value * 1000 | ||
slot.value = Math.floor((maxValue * 2) / 3) | ||
waitTime.value = (totalTime.value * 2) / 3 / slot.value | ||
log.debug( | ||
`progress value=${value.value} slot=${slot.value} duration=${duration.value} waitTime=${waitTime.value}` | ||
) | ||
timer = setTimeout(progress, waitTime.value) | ||
}) | ||
onBeforeUnmount(() => { | ||
clearTimeout(timer) | ||
log.debug(`progress finished after ${Date.now() - started}ms`) | ||
}) | ||
function progress() { | ||
value.value += 1 | ||
if (value.value < maxValue) { | ||
if (value.value === slot.value) { | ||
slot.value = Math.floor((100 - slot.value) / 2 + slot.value) | ||
waitTime.value *= 2 | ||
log.debug( | ||
`progress value=${value.value} slot=${slot.value} new waitTime=${waitTime.value}` | ||
) | ||
} | ||
timer = setTimeout(progress, waitTime.value) | ||
} | ||
} | ||
</script> | ||
|
||
<template> | ||
<div class="progress"> | ||
<div | ||
class="progress-bar" | ||
:class="barClass" | ||
role="progressbar" | ||
:style="`width: ${value}%`" | ||
:aria-valuenow="value" | ||
aria-valuemin="0" | ||
aria-valuemax="100" | ||
/> | ||
</div> | ||
</template> |