2018-11-07 23:18:45 +01:00
|
|
|
<template>
|
|
|
|
<div class="alert-wrapper">
|
2018-11-25 17:43:54 +01:00
|
|
|
<v-alert
|
|
|
|
class="alert"
|
|
|
|
:type="type"
|
|
|
|
v-model="showAlert"
|
|
|
|
:dismissible="true"
|
|
|
|
transition="slide-y-transition"
|
|
|
|
>
|
2018-11-08 23:36:10 +01:00
|
|
|
{{ text }}
|
2018-11-07 23:18:45 +01:00
|
|
|
<v-progress-linear
|
2018-11-08 23:36:10 +01:00
|
|
|
v-if="autoDismiss"
|
2018-11-07 23:18:45 +01:00
|
|
|
class="progress"
|
|
|
|
v-model="progressValue"
|
|
|
|
background-opacity="0"
|
|
|
|
color="rgba(0,0,0,0.3)"
|
|
|
|
></v-progress-linear>
|
|
|
|
</v-alert>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
beforeDestroy() {
|
|
|
|
this.clearTimer();
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
interval: null,
|
|
|
|
progressValue: 100,
|
|
|
|
showAlert: true,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
clearTimer() {
|
|
|
|
if (this.interval !== null) {
|
|
|
|
clearInterval(this.interval);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
2018-11-08 23:36:10 +01:00
|
|
|
updated() {
|
|
|
|
this.clearTimer();
|
|
|
|
if (this.autoDismiss) {
|
|
|
|
this.interval = setInterval(() => {
|
|
|
|
this.progressValue -= 4;
|
|
|
|
if (this.progressValue < 0) {
|
|
|
|
this.showAlert = false;
|
|
|
|
this.clearTimer();
|
|
|
|
}
|
|
|
|
}, 100);
|
|
|
|
}
|
2018-11-07 23:18:45 +01:00
|
|
|
},
|
|
|
|
props: {
|
2018-11-08 23:36:10 +01:00
|
|
|
autoDismiss: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true,
|
|
|
|
},
|
|
|
|
text: String,
|
2018-11-07 23:18:45 +01:00
|
|
|
onDismiss: Function,
|
2018-11-08 23:36:10 +01:00
|
|
|
type: String,
|
2018-11-07 23:18:45 +01:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
showAlert(newAlert) {
|
|
|
|
if (!newAlert && this.onDismiss) {
|
|
|
|
this.onDismiss();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.alert-wrapper {
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
2018-11-08 23:36:10 +01:00
|
|
|
z-index: 1001;
|
2018-11-07 23:18:45 +01:00
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.alert {
|
|
|
|
margin-left: auto;
|
|
|
|
margin-right: auto;
|
|
|
|
margin-top: 0;
|
|
|
|
width: 50%;
|
|
|
|
}
|
|
|
|
|
|
|
|
.progress {
|
|
|
|
position: absolute;
|
|
|
|
bottom: 0;
|
|
|
|
left: 0;
|
|
|
|
margin-bottom: 0;
|
|
|
|
}
|
|
|
|
</style>
|