import React, { useState, useEffect } from 'react'; import { Novel } from '../../types'; import { useNotification } from '../../contexts/NotificationContext'; import { MagnifyingGlassIcon, PencilIcon, ArrowDownTrayIcon, TrashIcon, EyeIcon, ShareIcon, DocumentTextIcon, PlusIcon } from '@heroicons/react/24/outline'; import LoadingSpinner from '../UI/LoadingSpinner'; const ProjectManagement: React.FC = () => { const { showNotification } = useNotification(); const [novels, setNovels] = useState([]); const [searchTerm, setSearchTerm] = useState(''); const [filterStatus, setFilterStatus] = useState<'all' | 'draft' | 'published' | 'archived'>('all'); const [isLoading, setIsLoading] = useState(true); const [selectedNovel, setSelectedNovel] = useState(null); // 模拟数据加载 useEffect(() => { const loadNovels = async () => { setIsLoading(true); // 模拟网络延迟 await new Promise(resolve => setTimeout(resolve, 1500)); const mockNovels: Novel[] = [ { id: '1', user_id: 'user_1', title: '未来之光', content: '在远在的星系中,人类建立了一个庞大的太空站...', word_count: 45678, status: 'draft', genre: '科幻小说', created_at: '2024-08-01T10:00:00Z', updated_at: '2024-08-06T15:30:00Z', metadata: { writing_style: '现代简约', target_word_count: 100000, completion_rate: 45.7 } }, { id: '2', user_id: 'user_1', title: '龙印传说', content: '在古老的东方大陆上,传说中的龙印再次出现...', word_count: 78923, status: 'published', genre: '玄幻小说', created_at: '2024-07-15T14:20:00Z', updated_at: '2024-07-30T09:15:00Z', metadata: { writing_style: '古典雅致', target_word_count: 80000, completion_rate: 98.7 } }, { id: '3', user_id: 'user_1', title: '都市追梦人', content: '在繁华的大都市中,一个年轻人为了梦想而奋斗...', word_count: 23456, status: 'draft', genre: '都市小说', created_at: '2024-08-05T08:45:00Z', updated_at: '2024-08-07T12:00:00Z', metadata: { writing_style: '激情潮湃', target_word_count: 120000, completion_rate: 19.5 } }, { id: '4', user_id: 'user_1', title: '时间的谜题', content: '一个神秘的遇害案发生在小镇上...', word_count: 67890, status: 'archived', genre: '悬疑小说', created_at: '2024-06-10T16:30:00Z', updated_at: '2024-06-25T11:20:00Z', metadata: { writing_style: '细腻温婉', target_word_count: 90000, completion_rate: 75.4 } } ]; setNovels(mockNovels); setIsLoading(false); }; loadNovels(); }, []); // 筛选小说 const filteredNovels = novels.filter(novel => { const matchesSearch = novel.title.toLowerCase().includes(searchTerm.toLowerCase()) || novel.genre?.toLowerCase().includes(searchTerm.toLowerCase()); const matchesStatus = filterStatus === 'all' || novel.status === filterStatus; return matchesSearch && matchesStatus; }); // 处理操作 const handleAction = (action: string, novel: Novel) => { switch (action) { case 'edit': showNotification('打开编辑器', `正在打开《${novel.title}》...`, 'info'); break; case 'download': showNotification('开始下载', `正在下载《${novel.title}》...`, 'success'); break; case 'delete': if (window.confirm(`确定要删除《${novel.title}》吗?`)) { setNovels(prev => prev.filter(n => n.id !== novel.id)); showNotification('删除成功', `《${novel.title}》已被删除`, 'success'); } break; case 'view': setSelectedNovel(novel); break; case 'share': showNotification('准备分享', `正在生成《${novel.title}》的分享链接...`, 'info'); break; } }; const getStatusColor = (status: Novel['status']) => { switch (status) { case 'published': return 'text-success-green'; case 'draft': return 'text-warning-yellow'; case 'archived': return 'text-text-secondary'; default: return 'text-text-primary'; } }; const getStatusText = (status: Novel['status']) => { switch (status) { case 'published': return '已发布'; case 'draft': return '草稿'; case 'archived': return '已存档'; default: return '未知'; } }; if (isLoading) { return (

正在加载您的作品...

); } return (
{/* 页面标题 */}

作品管理

管理您的小说创作项目

{/* 搜索和筛选 */}
setSearchTerm(e.target.value)} className="cyber-input pl-10" />
{/* 作品列表 */}
{filteredNovels.map(novel => (

{novel.title}

{getStatusText(novel.status)} {novel.genre} {novel.word_count.toLocaleString()} 字

{novel.content}

{/* 进度条 */} {novel.metadata?.completion_rate && (
完成进度 {novel.metadata.completion_rate}%
)} {/* 操作按钮 */}
最后编辑: {new Date(novel.updated_at).toLocaleDateString('zh-CN')}
))}
{filteredNovels.length === 0 && (

{searchTerm || filterStatus !== 'all' ? '没有找到符合条件的作品' : '您还没有创作任何作品'}

)} {/* 作品详情模态框 */} {selectedNovel && (

{selectedNovel.title}

状态: {getStatusText(selectedNovel.status)}
题材: {selectedNovel.genre}
字数: {selectedNovel.word_count.toLocaleString()}
创建时间: {new Date(selectedNovel.created_at).toLocaleDateString('zh-CN')}

内容预览

{selectedNovel.content}

)}
); }; export default ProjectManagement;