import React from 'react'; import { Box, List, ListItem, ListItemText, Avatar, Typography, Button, Divider, useTheme, Paper } from '@mui/material'; import { Add, Settings } from '@mui/icons-material'; interface Conversation { id: string; name: string; lastMessage?: string; timestamp?: Date; isActive?: boolean; avatar?: string; unreadCount?: number; } export const Sidebar: React.FC = () => { const theme = useTheme(); // 模拟对话历史数据 const conversations: Conversation[] = [ { id: '1', name: '开始', lastMessage: '守正出奇,让你的内容脱颖而出', timestamp: new Date(), isActive: true, avatar: '🤖', unreadCount: 0 }, { id: '2', name: '营销文案', lastMessage: '爆款标题的3个关键要素...', timestamp: new Date(Date.now() - 3600000), isActive: false, avatar: '📝', unreadCount: 1 }, { id: '3', name: '社交媒体策略', lastMessage: '如何提高社交媒体互动率?', timestamp: new Date(Date.now() - 86400000), isActive: false, avatar: '📱', unreadCount: 0 } ]; // 处理新建对话 const handleNewConversation = () => { console.log('创建新对话'); }; // 处理选择对话 const handleSelectConversation = (conversationId: string) => { console.log('选择对话:', conversationId); }; // 格式化时间 const formatTime = (date: Date) => { const now = new Date(); const diff = now.getTime() - date.getTime(); if (diff < 86400000) { // 24小时内 return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); } else if (diff < 172800000) { // 48小时内 return '昨天'; } else { return date.toLocaleDateString('zh-CN', { month: '2-digit', day: '2-digit' }); } }; return ( {/* 用户信息区域 */} 爆款文案助手 亲爱的安先生 {/* 新建对话按钮 */} {/* 对话历史列表 */} 最近对话 {conversations.map((conversation) => ( handleSelectConversation(conversation.id)} sx={{ borderRadius: 1, mx: 1, '&:hover': { backgroundColor: theme.palette.action.hover, }, backgroundColor: conversation.isActive ? theme.palette.action.selected : 'transparent', transition: 'all 0.2s ease', paddingX: 2, paddingY: 1.5, }} > {conversation.avatar} {conversation.name} {conversation.timestamp && formatTime(conversation.timestamp)} } secondary={ {conversation.lastMessage} {conversation.unreadCount && conversation.unreadCount > 0 && ( {conversation.unreadCount} )} } primaryTypographyProps={{ component: 'div' }} secondaryTypographyProps={{ component: 'div' }} /> ))} {/* 底部设置区域 */} ); };