'use client'; // 私信 - 会话列表 import { useEffect, useState } from 'react'; import { API } from '@/lib/api'; import { Icon } from '../Icons'; function avatar(username) { return 'https://ui-avatars.com/api/?name=' + encodeURIComponent(username || 'U') + '&background=6366f1&color=fff&size=64'; } export default function ConversationList({ onOpenChat, onClose }) { const [conversations, setConversations] = useState(null); const load = () => { API.getConversations() .then((data) => setConversations(data || [])) .catch(() => setConversations([])); }; useEffect(load, []); return (
{ if (e.target === e.currentTarget) onClose(); }}>

私信

×
{conversations === null ? (
加载中...
) : conversations.length === 0 ? (
暂无私信
) : ( conversations.map((c) => { const unread = c.unread_count || 0; const lastMsg = c.last_message || '暂无消息'; const time = c.last_message_time ? new Date(c.last_message_time).toLocaleString('zh-CN') : ''; return (
onOpenChat(c.id, c.other_user_id, c.other_username)} >
{c.other_username} {time}
{lastMsg} {unread > 0 && ( {unread} )}
); }) )}
); }