This commit is contained in:
parent
4bef95bbfa
commit
8312d7f738
@ -94,7 +94,7 @@ function handleViewAll() {
|
||||
<template #notification>
|
||||
<Notification
|
||||
:dot="notifyStore.showDot"
|
||||
:notifications="notifyStore.notificationList"
|
||||
:notifications="notifyStore.notifications"
|
||||
@clear="notifyStore.clearAllMessage"
|
||||
@make-all="notifyStore.setAllRead"
|
||||
@read="notifyStore.setRead"
|
||||
|
@ -3,7 +3,7 @@ import type { NotificationItem } from '@vben/layouts';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
import { useAppConfig } from '@vben/hooks';
|
||||
import { useAccessStore } from '@vben/stores';
|
||||
import { useAccessStore, useUserStore } from '@vben/stores';
|
||||
|
||||
import { useEventSource } from '@vueuse/core';
|
||||
import { notification } from 'ant-design-vue';
|
||||
@ -19,8 +19,22 @@ const { apiURL, clientId } = useAppConfig(
|
||||
export const useNotifyStore = defineStore(
|
||||
'app-notify',
|
||||
() => {
|
||||
/**
|
||||
* return才会被持久化 存储全部消息
|
||||
*/
|
||||
const notificationList = ref<NotificationItem[]>([]);
|
||||
|
||||
const userStore = useUserStore();
|
||||
const userId = computed(() => {
|
||||
return userStore.userInfo?.userId || '0';
|
||||
});
|
||||
|
||||
const notifications = computed(() => {
|
||||
return notificationList.value.filter(
|
||||
(item) => item.userId === userId.value,
|
||||
);
|
||||
});
|
||||
|
||||
/**
|
||||
* 开始监听sse消息
|
||||
*/
|
||||
@ -57,6 +71,7 @@ export const useNotifyStore = defineStore(
|
||||
isRead: false,
|
||||
message,
|
||||
title: '消息',
|
||||
userId: userId.value,
|
||||
});
|
||||
|
||||
data.value = null;
|
||||
@ -67,7 +82,9 @@ export const useNotifyStore = defineStore(
|
||||
* 设置全部已读
|
||||
*/
|
||||
function setAllRead() {
|
||||
notificationList.value.forEach((item) => {
|
||||
notificationList.value
|
||||
.filter((item) => item.userId === userId.value)
|
||||
.forEach((item) => {
|
||||
item.isRead = true;
|
||||
});
|
||||
}
|
||||
@ -84,7 +101,9 @@ export const useNotifyStore = defineStore(
|
||||
* 清空全部消息
|
||||
*/
|
||||
function clearAllMessage() {
|
||||
notificationList.value = [];
|
||||
notificationList.value = notificationList.value.filter(
|
||||
(item) => item.userId !== userId.value,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -98,13 +117,16 @@ export const useNotifyStore = defineStore(
|
||||
* 显示小圆点
|
||||
*/
|
||||
const showDot = computed(() =>
|
||||
notificationList.value.some((item) => !item.isRead),
|
||||
notificationList.value
|
||||
.filter((item) => item.userId === userId.value)
|
||||
.some((item) => !item.isRead),
|
||||
);
|
||||
|
||||
return {
|
||||
$reset,
|
||||
clearAllMessage,
|
||||
notificationList,
|
||||
notifications,
|
||||
setAllRead,
|
||||
setRead,
|
||||
showDot,
|
||||
|
@ -4,6 +4,7 @@ interface NotificationItem {
|
||||
isRead?: boolean;
|
||||
message: string;
|
||||
title: string;
|
||||
userId: number | string;
|
||||
}
|
||||
|
||||
export type { NotificationItem };
|
||||
|
Loading…
Reference in New Issue
Block a user