blob: 3835032d78068149f11158eba836dee6c9cac250 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
<template>
<el-dropdown trigger="click" placement="bottom-end" max-height="280" popper-class="fc_popper">
<el-badge v-if="notifications.length != 0" :value="notifications.length" :max="9" class="item" type="primary">
<el-button color="white" icon="BellFilled" circle />
</el-badge>
<el-button v-else color="white" icon="BellFilled" circle />
<template #dropdown>
<el-dropdown-menu :key="counter">
<el-alert
v-if="notifications.length != 0"
v-for="(notification, i) in notifications"
:key="i"
:title="notification.title"
:description="notification.text"
:type="notification.type"
show-icon
style="width: 300px"
@close.stop="removeNotification(i)"
/>
<el-result
v-else
icon="success"
:title="i18n.global.tc('notification.no_new.title')"
:sub-title="i18n.global.tc('notification.no_new.text')"
>
<template #icon>
</template>
</el-result>
</el-dropdown-menu>
</template>
</el-dropdown>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import {Notification} from '../plugins/modules/notifications';
import {i18n} from "../main";
export default defineComponent({
name: 'NotificationButton',
data: () => ({
// This variable is used as a key for the dropdown menu, so we can force it to refresh when a item is deleted.
counter: 0
}),
computed: {
i18n() {
return i18n
},
notifications(): Notification[] {
return this.$store.state.notifications.notifications;
}
},
methods: {
removeNotification(index: number) {
this.$store.commit('removeNotification', index);
// By refreshing the notifications list, we ensure the first notification get the index 0, ensuring this list
// is synchronized with the store list.
this.counter += 1;
}
}
})
</script>
<style scoped>
.el-dropdown {
height: 100%;
max-height: 300px;
}
.el-button {
margin: auto 25px auto 0 !important;
}
.el-alert {
margin: 5px 10px 5px 5px;
}
.el-badge:deep(sup) {
transform: translate(-10px, 5px) !important;
}
</style>
|