Message.vue
2.85 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<script setup lang="ts">
import dayjs from 'dayjs'
import * as NotifyMessageApi from '@/api/system/notify/message'
const { push } = useRouter()
const activeName = ref('notice')
const count = ref(0) // 未读消息数量
const list = ref([]) // 消息列表
// 获得消息列表
const getList = async () => {
list.value = await NotifyMessageApi.getUnreadNotifyMessageListApi()
}
// 获得未读消息数
const getUnreadCount = async () => {
NotifyMessageApi.getUnreadNotifyMessageCountApi().then((data) => {
count.value = data
})
}
// 跳转我的站内信
const goMyList = () => {
push({
name: 'MyNotifyMessage'
})
}
// ========== 初始化 =========
onMounted(() => {
// 首次加载小红点
getUnreadCount()
// 轮询刷新小红点
setInterval(() => {
getUnreadCount()
}, 1000 * 60 * 2)
})
</script>
<template>
<div class="message">
<ElPopover placement="bottom" :width="400" trigger="click">
<template #reference>
<ElBadge :is-dot="count > 0" class="item">
<Icon icon="ep:bell" :size="18" class="cursor-pointer" @click="getList" />
</ElBadge>
</template>
<ElTabs v-model="activeName">
<ElTabPane label="我的站内信" name="notice">
<div class="message-list">
<template v-for="item in list" :key="item.id">
<div class="message-item">
<img src="@/assets/imgs/avatar.gif" alt="" class="message-icon" />
<div class="message-content">
<span class="message-title">
{{ item.templateNickname }}:{{ item.templateContent }}
</span>
<span class="message-date">
{{ dayjs(item.createTime).format('YYYY-MM-DD HH:mm:ss') }}
</span>
</div>
</div>
</template>
</div>
</ElTabPane>
</ElTabs>
<!-- 更多 -->
<div style="text-align: right; margin-top: 10px">
<XButton type="primary" preIcon="ep:view" title="查看全部" @click="goMyList" />
</div>
</ElPopover>
</div>
</template>
<style scoped lang="scss">
.message-empty {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 260px;
line-height: 45px;
}
.message-list {
display: flex;
flex-direction: column;
.message-item {
display: flex;
align-items: center;
padding: 20px 0;
border-bottom: 1px solid var(--el-border-color-light);
&:last-child {
border: none;
}
.message-icon {
width: 40px;
height: 40px;
margin: 0 20px 0 5px;
}
.message-content {
display: flex;
flex-direction: column;
.message-title {
margin-bottom: 5px;
}
.message-date {
font-size: 12px;
color: var(--el-text-color-secondary);
}
}
}
}
</style>