update 消息盒子支持按类型分组切换展示
This commit is contained in:
@@ -5,6 +5,20 @@ export const PUSH_MESSAGE_TYPE = {
|
||||
CUSTOM: 'custom'
|
||||
} as const;
|
||||
|
||||
export const PUSH_MESSAGE_SOURCE = {
|
||||
BACKEND: 'backend',
|
||||
NOTICE: 'notice',
|
||||
WORKFLOW: 'workflow',
|
||||
LLM: 'llm',
|
||||
CLIENT: 'client'
|
||||
} as const;
|
||||
|
||||
export const NOTICE_GROUP = {
|
||||
SYSTEM: 'system',
|
||||
NOTICE: 'notice',
|
||||
WORKFLOW: 'workflow'
|
||||
} as const;
|
||||
|
||||
export interface PushMessagePayload {
|
||||
type?: string;
|
||||
source?: string;
|
||||
@@ -45,3 +59,24 @@ export const parsePushMessage = (raw: string): PushMessagePayload => {
|
||||
export const shouldAppendNotice = (payload: PushMessagePayload) => {
|
||||
return MESSAGE_CENTER_TYPES.has(payload.type ?? PUSH_MESSAGE_TYPE.MESSAGE);
|
||||
};
|
||||
|
||||
export const resolveNoticeGroup = (payload: PushMessagePayload) => {
|
||||
if (payload.type === PUSH_MESSAGE_TYPE.NOTICE || payload.source === PUSH_MESSAGE_SOURCE.NOTICE) {
|
||||
return NOTICE_GROUP.NOTICE;
|
||||
}
|
||||
if (payload.source === PUSH_MESSAGE_SOURCE.WORKFLOW) {
|
||||
return NOTICE_GROUP.WORKFLOW;
|
||||
}
|
||||
return NOTICE_GROUP.SYSTEM;
|
||||
};
|
||||
|
||||
export const resolveNoticeTitle = (payload: PushMessagePayload) => {
|
||||
const group = resolveNoticeGroup(payload);
|
||||
if (group === NOTICE_GROUP.NOTICE) {
|
||||
return '通知公告消息';
|
||||
}
|
||||
if (group === NOTICE_GROUP.WORKFLOW) {
|
||||
return '工作流消息';
|
||||
}
|
||||
return '系统消息';
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { getToken } from '@/utils/auth';
|
||||
import { ElNotification } from 'element-plus';
|
||||
import { useNoticeStore } from '@/store/modules/notice';
|
||||
import { parsePushMessage, PUSH_MESSAGE_TYPE, shouldAppendNotice } from '@/utils/push-message';
|
||||
import { parsePushMessage, resolveNoticeGroup, resolveNoticeTitle, shouldAppendNotice } from '@/utils/push-message';
|
||||
|
||||
let closePushConnection: (() => void) | undefined;
|
||||
|
||||
@@ -10,8 +10,10 @@ const appendNotice = (raw: string) => {
|
||||
if (!shouldAppendNotice(payload)) {
|
||||
return;
|
||||
}
|
||||
const title = resolveNoticeTitle(payload);
|
||||
useNoticeStore().addNotice({
|
||||
title: payload.type === PUSH_MESSAGE_TYPE.NOTICE ? '通知公告' : '系统消息',
|
||||
title,
|
||||
category: resolveNoticeGroup(payload),
|
||||
type: payload.type,
|
||||
source: payload.source,
|
||||
message: payload.message ?? '',
|
||||
@@ -23,7 +25,7 @@ const appendNotice = (raw: string) => {
|
||||
time: new Date(payload.timestamp ?? Date.now()).toLocaleString()
|
||||
});
|
||||
ElNotification({
|
||||
title: payload.type === PUSH_MESSAGE_TYPE.NOTICE ? '通知公告' : '消息',
|
||||
title,
|
||||
message: payload.message ?? '',
|
||||
type: 'success',
|
||||
duration: 3000
|
||||
|
||||
Reference in New Issue
Block a user