提交 | 用户 | 时间
|
cb6cd2
|
1 |
<script lang="ts" setup> |
H |
2 |
import { formatDate } from '@/utils/formatTime' |
|
3 |
import * as NotifyMessageApi from '@/api/system/notify/message' |
|
4 |
|
|
5 |
defineOptions({ name: 'Message' }) |
|
6 |
|
|
7 |
const { push } = useRouter() |
|
8 |
const activeName = ref('notice') |
|
9 |
const unreadCount = ref(0) // 未读消息数量 |
|
10 |
const list = ref<any[]>([]) // 消息列表 |
|
11 |
|
|
12 |
// 获得消息列表 |
|
13 |
const getList = async () => { |
|
14 |
list.value = await NotifyMessageApi.getUnreadNotifyMessageList() |
|
15 |
// 强制设置 unreadCount 为 0,避免小红点因为轮询太慢,不消除 |
|
16 |
unreadCount.value = 0 |
|
17 |
} |
|
18 |
|
|
19 |
// 获得未读消息数 |
|
20 |
const getUnreadCount = async () => { |
|
21 |
NotifyMessageApi.getUnreadNotifyMessageCount().then((data) => { |
|
22 |
unreadCount.value = data |
|
23 |
}) |
|
24 |
} |
|
25 |
|
|
26 |
// 跳转我的站内信 |
|
27 |
const goMyList = () => { |
|
28 |
push({ |
|
29 |
name: 'MyNotifyMessage' |
|
30 |
}) |
|
31 |
} |
|
32 |
|
|
33 |
// ========== 初始化 ========= |
|
34 |
onMounted(() => { |
|
35 |
// 首次加载小红点 |
|
36 |
// getUnreadCount() |
|
37 |
// // 轮询刷新小红点 |
|
38 |
// setInterval( |
|
39 |
// () => { |
|
40 |
// getUnreadCount() |
|
41 |
// }, |
|
42 |
// 1000 * 60 * 2 |
|
43 |
// ) |
|
44 |
}) |
|
45 |
</script> |
|
46 |
<template> |
|
47 |
<div class="message"> |
|
48 |
<ElPopover :width="400" placement="bottom" trigger="click"> |
|
49 |
<template #reference> |
|
50 |
<ElBadge :is-dot="unreadCount > 0" class="item"> |
|
51 |
<Icon :size="18" class="cursor-pointer" icon="ep:bell" @click="getList" /> |
|
52 |
</ElBadge> |
|
53 |
</template> |
|
54 |
<ElTabs v-model="activeName"> |
|
55 |
<ElTabPane label="我的站内信" name="notice"> |
|
56 |
<el-scrollbar class="message-list"> |
|
57 |
<template v-for="item in list" :key="item.id"> |
|
58 |
<div class="message-item"> |
|
59 |
<img alt="" class="message-icon" src="@/assets/imgs/avatar.gif" /> |
|
60 |
<div class="message-content"> |
|
61 |
<span class="message-title"> |
|
62 |
{{ item.templateNickname }}:{{ item.templateContent }} |
|
63 |
</span> |
|
64 |
<span class="message-date"> |
|
65 |
{{ formatDate(item.createTime) }} |
|
66 |
</span> |
|
67 |
</div> |
|
68 |
</div> |
|
69 |
</template> |
|
70 |
</el-scrollbar> |
|
71 |
</ElTabPane> |
|
72 |
</ElTabs> |
|
73 |
<!-- 更多 --> |
|
74 |
<div style="margin-top: 10px; text-align: right"> |
|
75 |
<XButton preIcon="ep:view" title="查看全部" type="primary" @click="goMyList" /> |
|
76 |
</div> |
|
77 |
</ElPopover> |
|
78 |
</div> |
|
79 |
</template> |
|
80 |
<style lang="scss" scoped> |
|
81 |
.message-empty { |
|
82 |
display: flex; |
|
83 |
flex-direction: column; |
|
84 |
align-items: center; |
|
85 |
justify-content: center; |
|
86 |
height: 260px; |
|
87 |
line-height: 45px; |
|
88 |
} |
|
89 |
|
|
90 |
.message-list { |
|
91 |
display: flex; |
|
92 |
height: 400px; |
|
93 |
flex-direction: column; |
|
94 |
|
|
95 |
.message-item { |
|
96 |
display: flex; |
|
97 |
align-items: center; |
|
98 |
padding: 20px 0; |
|
99 |
border-bottom: 1px solid var(--el-border-color-light); |
|
100 |
|
|
101 |
&:last-child { |
|
102 |
border: none; |
|
103 |
} |
|
104 |
|
|
105 |
.message-icon { |
|
106 |
width: 40px; |
|
107 |
height: 40px; |
|
108 |
margin: 0 20px 0 5px; |
|
109 |
} |
|
110 |
|
|
111 |
.message-content { |
|
112 |
display: flex; |
|
113 |
flex-direction: column; |
|
114 |
|
|
115 |
.message-title { |
|
116 |
margin-bottom: 5px; |
|
117 |
} |
|
118 |
|
|
119 |
.message-date { |
|
120 |
font-size: 12px; |
|
121 |
color: var(--el-text-color-secondary); |
|
122 |
} |
|
123 |
} |
|
124 |
} |
|
125 |
} |
|
126 |
</style> |