|
|
@@ -203,14 +203,27 @@ export default function AppMessage() {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- // 查看详情
|
|
|
+ // 查看详情(点击阅读时若未读先调用 update-read 再展示详情)
|
|
|
const handleViewDetail = async (id: number) => {
|
|
|
+ const currentMessage = messages.find(msg => msg.id === id);
|
|
|
+ const isUnread = currentMessage?.status === 'unread';
|
|
|
+
|
|
|
+ if (isUnread) {
|
|
|
+ try {
|
|
|
+ await app_message.updateRead([id]);
|
|
|
+ await fetchMessages();
|
|
|
+ window.dispatchEvent(new CustomEvent('messageRead'));
|
|
|
+ } catch (error: any) {
|
|
|
+ console.error('标记已读失败:', error);
|
|
|
+ toast.error(error?.response?.data?.message || t('notificationManagement.markReadFailed'));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
setDetailLoading(true);
|
|
|
try {
|
|
|
- // 获取消息详情(这里假设有详情接口,如果没有可以只显示列表中的数据)
|
|
|
- const currentMessage = messages.find(msg => msg.id === id);
|
|
|
if (currentMessage) {
|
|
|
- setDetailMessage(currentMessage);
|
|
|
+ setDetailMessage(isUnread ? { ...currentMessage, status: 'read' as const } : currentMessage);
|
|
|
setDetailModalVisible(true);
|
|
|
} else {
|
|
|
toast.error(t('notificationManagement.messageDetailNotFound'));
|
|
|
@@ -223,6 +236,23 @@ export default function AppMessage() {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ // 全部已读
|
|
|
+ const handleMarkAllAsRead = async () => {
|
|
|
+ setLoading(true);
|
|
|
+ try {
|
|
|
+ await app_message.updateAllRead();
|
|
|
+ setSelectedIds([]);
|
|
|
+ await fetchMessages();
|
|
|
+ toast.success(t('notificationManagement.markAllReadSuccess'));
|
|
|
+ window.dispatchEvent(new CustomEvent('messageRead'));
|
|
|
+ } catch (error: any) {
|
|
|
+ console.error('全部标记已读失败:', error);
|
|
|
+ toast.error(error?.response?.data?.message || t('notificationManagement.markAllReadFailed'));
|
|
|
+ } finally {
|
|
|
+ setLoading(false);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
// 使用从API获取的消息列表(已根据筛选条件过滤)
|
|
|
const filteredMessages = messages;
|
|
|
|
|
|
@@ -445,6 +475,13 @@ export default function AppMessage() {
|
|
|
>
|
|
|
{t('common.reset')}
|
|
|
</AntButton>
|
|
|
+ <AntButton
|
|
|
+ icon={<BookOpen className="w-4 h-4" />}
|
|
|
+ onClick={handleMarkAllAsRead}
|
|
|
+ disabled={loading}
|
|
|
+ >
|
|
|
+ {t('notificationManagement.markAllRead')}
|
|
|
+ </AntButton>
|
|
|
</Space>
|
|
|
</div>
|
|
|
</div>
|