app/src/components/Timer.vue

120 lines
2.6 KiB
Vue
Raw Normal View History

2021-04-19 18:13:54 +02:00
<template>
<div class="timer">
2021-04-19 22:46:31 +02:00
<p v-if="warning == false" class="timeleft reverse">{{ countDown.toString() }}</p>
2021-04-20 13:30:23 +02:00
<p v-if="(warning == true) || (typeof warning == 'undefined')" class="timeout reverse">
2021-04-19 22:46:31 +02:00
<img src="joker.png" alt="joker">
<img src="joker.png" alt="joker">
<img src="joker.png" alt="joker">
<img src="joker.png" alt="joker">
<img src="joker.png" alt="joker">
</p>
2021-04-20 13:30:23 +02:00
<button v-on:click="restartTimer" class="timerBtn"><span class="timerBtn-inner"></span></button>
2021-04-19 22:46:31 +02:00
<p v-if="warning == false" class="timeleft">{{ countDown.toString() }}</p>
2021-04-20 13:30:23 +02:00
<p v-if="warning == true || (typeof warning == 'undefined')" class="timeout">
2021-04-19 22:46:31 +02:00
<img src="joker.png" alt="joker">
<img src="joker.png" alt="joker">
<img src="joker.png" alt="joker">
<img src="joker.png" alt="joker">
<img src="joker.png" alt="joker">
</p>
2021-04-19 18:13:54 +02:00
</div>
</template>
<script>
2021-04-19 22:46:31 +02:00
var Interval;
2021-04-19 18:13:54 +02:00
export default {
name: "Timer",
props: {
time: Number,
2021-05-01 10:29:28 +02:00
playsound: Boolean,
2021-04-20 13:30:23 +02:00
},
data: function() {
return {
countDown: -2,
warning: true,
2021-04-30 13:14:23 +02:00
wakeLock: null,
2021-04-20 13:30:23 +02:00
}
2021-04-19 18:13:54 +02:00
},
mounted: function() {
2021-04-20 13:30:23 +02:00
},
2021-04-19 18:13:54 +02:00
methods: {
timeleft: function(){
this.countDown--;
2021-04-19 22:46:31 +02:00
if(this.countDown == 0) {
this.warning = true
2021-05-01 10:29:28 +02:00
if(this.playsound) {
var audio = new Audio('timeout.wav');
audio.play();
}
2021-04-19 22:46:31 +02:00
clearInterval(Interval);
}
2021-04-19 18:13:54 +02:00
},
restartTimer: function() {
2021-04-30 13:14:23 +02:00
if(this.wakeLock == null && 'wakeLock' in navigator) {
this.wakeLock = navigator.wakeLock.request('screen');
}
2021-04-19 18:13:54 +02:00
this.countDown = this.time;
2021-04-19 22:46:31 +02:00
this.warning = false;
clearInterval(Interval);
Interval = setInterval(() => {
this.timeleft()
}, 1000);
2021-04-19 18:13:54 +02:00
}
},
}
</script>
2021-04-22 13:39:38 +02:00
<style lang="scss" scoped>
2021-04-19 22:46:31 +02:00
.timer {
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
.timeleft {
2021-05-01 10:29:28 +02:00
font-size: 60px;
padding: 23px 20px 84px 20px;
margin: 10px 0;
color: $black;
background-image: url("~@/img/tile-back.svg");
background-size: cover;
text-align: center;
width: 80px;
height: 60px;
2021-04-19 22:46:31 +02:00
}
.timeout {
margin: 40px;
2021-04-22 13:39:38 +02:00
img {
height: 3rem;
}
2021-04-19 22:46:31 +02:00
}
.timerBtn {
appearance: none;
2021-05-01 10:29:28 +02:00
border: 1px solid $white;
2021-04-19 22:46:31 +02:00
border-radius: 3px;
font-size: 3rem;
background: none;
padding: 2rem;
2021-04-22 13:39:38 +02:00
.timerBtn-inner {
display: inline-block;
height: 2rem;
width: 2rem;
2021-05-01 10:29:28 +02:00
background-color: $white;
2021-04-22 13:39:38 +02:00
}
2021-04-20 13:30:23 +02:00
}
2021-04-19 22:46:31 +02:00
.reverse {
transform: scale(-1, -1);
2021-04-19 18:13:54 +02:00
}
2021-04-22 13:39:38 +02:00
}
2021-04-19 18:13:54 +02:00
</style>