"use client" import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar" import { Badge } from "@/components/ui/badge" import { Card, CardContent } from "@/components/ui/card" import { listChatSessions } from "@/lib/api" import { useAuthStore } from "@/store/auth" import { Lock, MessageSquare } from "lucide-react" import Link from "next/link" import { useEffect, useState } from "react" export default function ChatListPage() { const [sessions, setSessions] = useState>>([]) const userId = useAuthStore((state) => state.user?.id) useEffect(() => { let cancelled = false void (async () => { try { const result = await Promise.resolve(listChatSessions()) if (!cancelled) setSessions(result) } catch { if (!cancelled) setSessions([]) } })() return () => { cancelled = true } }, []) return (

消息

{sessions.map((session) => { const other = session.participants.find((participant) => participant.id !== userId) ?? session.participants[0] return ( {other.name[0]}
{other.name} {session.type === "order" ? "订单" : "咨询"} {session.readonly && }

{session.lastMessage}

{session.lastMessageAt && ( {new Date(session.lastMessageAt).toLocaleDateString("zh-CN")} )} {session.unreadCount > 0 && ( {session.unreadCount} )}
) })} {sessions.length === 0 && ( 暂无消息 )}
) }