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