|
|
|
|
@ -2,6 +2,7 @@ import type { NotificationItem } from '@vben/layouts';
|
|
|
|
|
|
|
|
|
|
import { computed, ref, watch } from 'vue';
|
|
|
|
|
|
|
|
|
|
import { SSEEvent } from '@vben/constants';
|
|
|
|
|
import { SvgMessageUrl } from '@vben/icons';
|
|
|
|
|
import { $t } from '@vben/locales';
|
|
|
|
|
import { useUserStore } from '@vben/stores';
|
|
|
|
|
@ -46,27 +47,28 @@ export const useNotifyStore = defineStore(
|
|
|
|
|
if (!sseReturnData) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const { data } = sseReturnData;
|
|
|
|
|
const { event, data } = sseReturnData;
|
|
|
|
|
|
|
|
|
|
watch(data, (message) => {
|
|
|
|
|
if (!message) return;
|
|
|
|
|
console.log(`接收到消息: ${message}`);
|
|
|
|
|
|
|
|
|
|
notification.success({
|
|
|
|
|
description: message,
|
|
|
|
|
duration: 3,
|
|
|
|
|
message: $t('component.notice.received'),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
notificationList.value.unshift({
|
|
|
|
|
// avatar: `https://api.multiavatar.com/${random(0, 10_000)}.png`, 随机头像
|
|
|
|
|
avatar: SvgMessageUrl,
|
|
|
|
|
date: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
|
isRead: false,
|
|
|
|
|
message,
|
|
|
|
|
title: $t('component.notice.title'),
|
|
|
|
|
userId: userId.value,
|
|
|
|
|
});
|
|
|
|
|
if (!event || !message) return;
|
|
|
|
|
console.log(`接收到事件为:${event.value} 的消息: ${message}`);
|
|
|
|
|
if (event.value === SSEEvent.MESSAGE) {
|
|
|
|
|
notification.success({
|
|
|
|
|
description: message,
|
|
|
|
|
duration: 3,
|
|
|
|
|
message: $t('component.notice.received'),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
notificationList.value.unshift({
|
|
|
|
|
// avatar: `https://api.multiavatar.com/${random(0, 10_000)}.png`, 随机头像
|
|
|
|
|
avatar: SvgMessageUrl,
|
|
|
|
|
date: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
|
isRead: false,
|
|
|
|
|
message,
|
|
|
|
|
title: $t('component.notice.title'),
|
|
|
|
|
userId: userId.value,
|
|
|
|
|
});
|
|
|
|
|
} else if (event.value === SSEEvent.HAZARD) { /* empty */ }
|
|
|
|
|
|
|
|
|
|
// 需要手动置空 vue3在值相同时不会触发watch
|
|
|
|
|
data.value = null;
|
|
|
|
|
|