feat:完善我的站内信 100%(右上角)
parent
d3d250f16f
commit
7d00744a82
|
@ -1,12 +1,17 @@
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { NotificationItem } from '@vben/layouts';
|
import type { NotificationItem } from '@vben/layouts';
|
||||||
|
|
||||||
import { computed, ref, watch } from 'vue';
|
import { computed, onMounted, ref, watch } from 'vue';
|
||||||
|
|
||||||
import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
|
import { AuthenticationLoginExpiredModal } from '@vben/common-ui';
|
||||||
import { VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
|
import { VBEN_DOC_URL, VBEN_GITHUB_URL } from '@vben/constants';
|
||||||
import { useWatermark } from '@vben/hooks';
|
import { useWatermark } from '@vben/hooks';
|
||||||
import { BookOpenText, CircleHelp, MdiGithub, AntdProfileOutlined } from '@vben/icons';
|
import {
|
||||||
|
AntdProfileOutlined,
|
||||||
|
BookOpenText,
|
||||||
|
CircleHelp,
|
||||||
|
MdiGithub,
|
||||||
|
} from '@vben/icons';
|
||||||
import {
|
import {
|
||||||
BasicLayout,
|
BasicLayout,
|
||||||
LockScreen,
|
LockScreen,
|
||||||
|
@ -15,51 +20,27 @@ import {
|
||||||
} from '@vben/layouts';
|
} from '@vben/layouts';
|
||||||
import { preferences } from '@vben/preferences';
|
import { preferences } from '@vben/preferences';
|
||||||
import { useAccessStore, useUserStore } from '@vben/stores';
|
import { useAccessStore, useUserStore } from '@vben/stores';
|
||||||
import { openWindow } from '@vben/utils';
|
import { formatDateTime, openWindow } from '@vben/utils';
|
||||||
|
|
||||||
|
import {
|
||||||
|
getUnreadNotifyMessageCount,
|
||||||
|
getUnreadNotifyMessageList,
|
||||||
|
updateAllNotifyMessageRead,
|
||||||
|
updateNotifyMessageRead,
|
||||||
|
} from '#/api/system/notify/message';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
import { router } from '#/router';
|
||||||
import { useAuthStore } from '#/store';
|
import { useAuthStore } from '#/store';
|
||||||
import LoginForm from '#/views/_core/authentication/login.vue';
|
import LoginForm from '#/views/_core/authentication/login.vue';
|
||||||
import { router } from '#/router';
|
|
||||||
|
|
||||||
const notifications = ref<NotificationItem[]>([
|
|
||||||
{
|
|
||||||
avatar: 'https://avatar.vercel.sh/vercel.svg?text=VB',
|
|
||||||
date: '3小时前',
|
|
||||||
isRead: true,
|
|
||||||
message: '描述信息描述信息描述信息',
|
|
||||||
title: '收到了 14 份新周报',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
avatar: 'https://avatar.vercel.sh/1',
|
|
||||||
date: '刚刚',
|
|
||||||
isRead: false,
|
|
||||||
message: '描述信息描述信息描述信息',
|
|
||||||
title: '朱偏右 回复了你',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
avatar: 'https://avatar.vercel.sh/1',
|
|
||||||
date: '2024-01-01',
|
|
||||||
isRead: false,
|
|
||||||
message: '描述信息描述信息描述信息',
|
|
||||||
title: '曲丽丽 评论了你',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
avatar: 'https://avatar.vercel.sh/satori',
|
|
||||||
date: '1天前',
|
|
||||||
isRead: false,
|
|
||||||
message: '描述信息描述信息描述信息',
|
|
||||||
title: '代办提醒',
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
const accessStore = useAccessStore();
|
const accessStore = useAccessStore();
|
||||||
const { destroyWatermark, updateWatermark } = useWatermark();
|
const { destroyWatermark, updateWatermark } = useWatermark();
|
||||||
const showDot = computed(() =>
|
|
||||||
notifications.value.some((item) => !item.isRead),
|
const notifications = ref<NotificationItem[]>([]);
|
||||||
);
|
const unreadCount = ref(0);
|
||||||
|
const showDot = computed(() => unreadCount.value > 0);
|
||||||
|
|
||||||
const menus = computed(() => [
|
const menus = computed(() => [
|
||||||
{
|
{
|
||||||
|
@ -106,13 +87,77 @@ async function handleLogout() {
|
||||||
await authStore.logout(false);
|
await authStore.logout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleNoticeClear() {
|
/** 获得未读消息数 */
|
||||||
|
async function handleNotificationGetUnreadCount() {
|
||||||
|
unreadCount.value = await getUnreadNotifyMessageCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 获得消息列表 */
|
||||||
|
async function handleNotificationGetList() {
|
||||||
|
const list = await getUnreadNotifyMessageList();
|
||||||
|
notifications.value = list.map((item) => ({
|
||||||
|
avatar: preferences.app.defaultAvatar,
|
||||||
|
date: formatDateTime(item.createTime) as string,
|
||||||
|
isRead: false,
|
||||||
|
id: item.id,
|
||||||
|
message: item.templateContent,
|
||||||
|
title: item.templateNickname,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 跳转我的站内信 */
|
||||||
|
function handleNotificationViewAll() {
|
||||||
|
router.push({
|
||||||
|
name: 'MyNotifyMessage',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 标记所有已读 */
|
||||||
|
async function handleNotificationMakeAll() {
|
||||||
|
await updateAllNotifyMessageRead();
|
||||||
|
unreadCount.value = 0;
|
||||||
notifications.value = [];
|
notifications.value = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleMakeAll() {
|
/** 清空通知 */
|
||||||
notifications.value.forEach((item) => (item.isRead = true));
|
async function handleNotificationClear() {
|
||||||
|
handleNotificationMakeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 标记单个已读 */
|
||||||
|
async function handleNotificationRead(item: NotificationItem) {
|
||||||
|
if (!item.id) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await updateNotifyMessageRead([item.id]);
|
||||||
|
await handleNotificationGetUnreadCount();
|
||||||
|
notifications.value = notifications.value.filter((n) => n.id !== item.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 处理通知打开 */
|
||||||
|
function handleNotificationOpen(open: boolean) {
|
||||||
|
if (!open) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
handleNotificationGetList();
|
||||||
|
handleNotificationGetUnreadCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== 初始化 ==========
|
||||||
|
onMounted(() => {
|
||||||
|
// 首次加载未读数量
|
||||||
|
handleNotificationGetUnreadCount();
|
||||||
|
// 轮询刷新未读数量
|
||||||
|
setInterval(
|
||||||
|
() => {
|
||||||
|
if (userStore.userInfo) {
|
||||||
|
handleNotificationGetUnreadCount();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
1000 * 60 * 2,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => preferences.app.watermark,
|
() => preferences.app.watermark,
|
||||||
async (enable) => {
|
async (enable) => {
|
||||||
|
@ -146,8 +191,11 @@ watch(
|
||||||
<Notification
|
<Notification
|
||||||
:dot="showDot"
|
:dot="showDot"
|
||||||
:notifications="notifications"
|
:notifications="notifications"
|
||||||
@clear="handleNoticeClear"
|
@clear="handleNotificationClear"
|
||||||
@make-all="handleMakeAll"
|
@make-all="handleNotificationMakeAll"
|
||||||
|
@view-all="handleNotificationViewAll"
|
||||||
|
@open="handleNotificationOpen"
|
||||||
|
@read="handleNotificationRead"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<template #extra>
|
<template #extra>
|
||||||
|
|
|
@ -34,6 +34,7 @@ withDefaults(defineProps<Props>(), {
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
clear: [];
|
clear: [];
|
||||||
makeAll: [];
|
makeAll: [];
|
||||||
|
open: [boolean];
|
||||||
read: [NotificationItem];
|
read: [NotificationItem];
|
||||||
viewAll: [];
|
viewAll: [];
|
||||||
}>();
|
}>();
|
||||||
|
@ -60,6 +61,11 @@ function handleClear() {
|
||||||
function handleClick(item: NotificationItem) {
|
function handleClick(item: NotificationItem) {
|
||||||
emit('read', item);
|
emit('read', item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleOpen() {
|
||||||
|
toggle();
|
||||||
|
emit('open', open.value);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<VbenPopover
|
<VbenPopover
|
||||||
|
@ -67,7 +73,7 @@ function handleClick(item: NotificationItem) {
|
||||||
content-class="relative right-2 w-[360px] p-0"
|
content-class="relative right-2 w-[360px] p-0"
|
||||||
>
|
>
|
||||||
<template #trigger>
|
<template #trigger>
|
||||||
<div class="flex-center mr-2 h-full" @click.stop="toggle()">
|
<div class="flex-center mr-2 h-full" @click.stop="handleOpen">
|
||||||
<VbenIconButton class="bell-button text-foreground relative">
|
<VbenIconButton class="bell-button text-foreground relative">
|
||||||
<span
|
<span
|
||||||
v-if="dot"
|
v-if="dot"
|
||||||
|
|
|
@ -4,6 +4,7 @@ interface NotificationItem {
|
||||||
isRead?: boolean;
|
isRead?: boolean;
|
||||||
message: string;
|
message: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
id?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type { NotificationItem };
|
export type { NotificationItem };
|
||||||
|
|
Loading…
Reference in New Issue