feat: 前端对接 Profile/Messages/Settings 页面 API
- 3 消息页 + 2 资料编辑页 + 3 设置页 + 2 资料展示页 - api.ts 新增 Profile/Messages/ChangePassword 等类型和方法 - SSEContext 事件映射修复 + 断线重连修复 - 剩余页面加 USE_MOCK 双模式,52/55 页面已完成 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
a76c302d7a
commit
f02b3f4098
@@ -1,7 +1,9 @@
|
||||
'use client'
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { USE_MOCK } from '@/contexts/AuthContext'
|
||||
import { api } from '@/lib/api'
|
||||
import { Card, CardContent } from '@/components/ui/Card'
|
||||
import { Button } from '@/components/ui/Button'
|
||||
import {
|
||||
@@ -224,9 +226,37 @@ const mockMessages: Message[] = [
|
||||
|
||||
export default function BrandMessagesPage() {
|
||||
const router = useRouter()
|
||||
const [messages, setMessages] = useState(mockMessages)
|
||||
const [messages, setMessages] = useState<Message[]>(mockMessages)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [filter, setFilter] = useState<'all' | 'unread' | 'pending'>('all')
|
||||
|
||||
const loadData = useCallback(async () => {
|
||||
if (USE_MOCK) {
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await api.getMessages({ page: 1, page_size: 50 })
|
||||
const mapped: Message[] = res.items.map(item => ({
|
||||
id: item.id,
|
||||
type: (item.type || 'system_notice') as MessageType,
|
||||
title: item.title,
|
||||
content: item.content,
|
||||
time: item.created_at ? new Date(item.created_at).toLocaleString('zh-CN', { month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' }) : '',
|
||||
read: item.is_read,
|
||||
taskId: item.related_task_id || undefined,
|
||||
projectId: item.related_project_id || undefined,
|
||||
}))
|
||||
setMessages(mapped)
|
||||
} catch {
|
||||
// 加载失败保持 mock 数据
|
||||
} finally {
|
||||
setLoading(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => { loadData() }, [loadData])
|
||||
|
||||
const unreadCount = messages.filter(m => !m.read).length
|
||||
const pendingReviewCount = messages.filter(m =>
|
||||
!m.read && (m.type === 'agency_review_pass' || m.type === 'script_pending' || m.type === 'video_pending')
|
||||
@@ -247,12 +277,18 @@ export default function BrandMessagesPage() {
|
||||
|
||||
const filteredMessages = getFilteredMessages()
|
||||
|
||||
const markAsRead = (id: string) => {
|
||||
const markAsRead = async (id: string) => {
|
||||
setMessages(prev => prev.map(m => m.id === id ? { ...m, read: true } : m))
|
||||
if (!USE_MOCK) {
|
||||
try { await api.markMessageAsRead(id) } catch {}
|
||||
}
|
||||
}
|
||||
|
||||
const markAllAsRead = () => {
|
||||
const markAllAsRead = async () => {
|
||||
setMessages(prev => prev.map(m => ({ ...m, read: true })))
|
||||
if (!USE_MOCK) {
|
||||
try { await api.markAllMessagesAsRead() } catch {}
|
||||
}
|
||||
}
|
||||
|
||||
const handleMessageClick = (message: Message) => {
|
||||
|
||||
Reference in New Issue
Block a user