luom2645's picture
Upload folder using huggingface_hub
9dd9a58 verified
Raw History Blame
14.8 kB
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<Novel[]>([]);
const [searchTerm, setSearchTerm] = useState('');
const [filterStatus, setFilterStatus] = useState<'all' | 'draft' | 'published' | 'archived'>('all');
const [isLoading, setIsLoading] = useState(true);
const [selectedNovel, setSelectedNovel] = useState<Novel | null>(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 (
<div className="flex items-center justify-center h-96">
<div className="text-center">
<LoadingSpinner size="lg" />
<p className="text-text-secondary mt-4">正在加载您的作品...</p>
</div>
</div>
);
}
return (
<div className="space-y-6">
{/* 页面标题 */}
<div className="text-center">
<h1 className="text-4xl font-bold text-text-highlight mb-4">
<span className="bg-gradient-to-r from-accent-cyan to-accent-blue bg-clip-text text-transparent">
作品管理
</span>
</h1>
<p className="text-lg text-text-secondary">
管理您的小说创作项目
</p>
</div>
{/* 搜索和筛选 */}
<div className="glass-panel p-6">
<div className="flex flex-col md:flex-row gap-4">
<div className="flex-1 relative">
<MagnifyingGlassIcon className="w-5 h-5 text-text-secondary absolute left-3 top-1/2 transform -translate-y-1/2" />
<input
type="text"
placeholder="搜索作品名称或题材..."
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="cyber-input pl-10"
/>
</div>
<select
value={filterStatus}
onChange={(e) => setFilterStatus(e.target.value as any)}
className="cyber-input md:w-40"
>
<option value="all">全部状态</option>
<option value="draft">草稿</option>
<option value="published">已发布</option>
<option value="archived">已存档</option>
</select>
<button className="cyber-btn cyber-btn-primary px-6">
<PlusIcon className="w-5 h-5 mr-2" />
新建作品
</button>
</div>
</div>
{/* 作品列表 */}
<div className="grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-3 gap-6">
{filteredNovels.map(novel => (
<div key={novel.id} className="glass-panel p-6 hover:scale-105 transition-transform duration-200">
<div className="flex items-start justify-between mb-4">
<div className="flex-1">
<h3 className="text-xl font-semibold text-text-highlight mb-2 line-clamp-1">
{novel.title}
</h3>
<div className="flex items-center space-x-4 text-sm text-text-secondary mb-3">
<span className={getStatusColor(novel.status)}>
{getStatusText(novel.status)}
</span>
<span>{novel.genre}</span>
<span>{novel.word_count.toLocaleString()} 字</span>
</div>
</div>
<DocumentTextIcon className="w-8 h-8 text-accent-cyan flex-shrink-0" />
</div>
<p className="text-text-secondary text-sm mb-4 line-clamp-3">
{novel.content}
</p>
{/* 进度条 */}
{novel.metadata?.completion_rate && (
<div className="mb-4">
<div className="flex justify-between text-sm mb-1">
<span className="text-text-secondary">完成进度</span>
<span className="text-accent-cyan">{novel.metadata.completion_rate}%</span>
</div>
<div className="progress-bar">
<div
className="progress-fill"
style={{ width: `${novel.metadata.completion_rate}%` }}
></div>
</div>
</div>
)}
{/* 操作按钮 */}
<div className="flex items-center justify-between">
<div className="flex space-x-2">
<button
onClick={() => handleAction('edit', novel)}
className="p-2 text-text-secondary hover:text-accent-cyan transition-colors duration-200"
title="编辑"
>
<PencilIcon className="w-4 h-4" />
</button>
<button
onClick={() => handleAction('view', novel)}
className="p-2 text-text-secondary hover:text-accent-cyan transition-colors duration-200"
title="查看"
>
<EyeIcon className="w-4 h-4" />
</button>
<button
onClick={() => handleAction('download', novel)}
className="p-2 text-text-secondary hover:text-success-green transition-colors duration-200"
title="下载"
>
<ArrowDownTrayIcon className="w-4 h-4" />
</button>
<button
onClick={() => handleAction('share', novel)}
className="p-2 text-text-secondary hover:text-accent-blue transition-colors duration-200"
title="分享"
>
<ShareIcon className="w-4 h-4" />
</button>
</div>
<button
onClick={() => handleAction('delete', novel)}
className="p-2 text-text-secondary hover:text-danger-red transition-colors duration-200"
title="删除"
>
<TrashIcon className="w-4 h-4" />
</button>
</div>
<div className="text-xs text-text-secondary mt-3 pt-3 border-t border-border-color">
最后编辑: {new Date(novel.updated_at).toLocaleDateString('zh-CN')}
</div>
</div>
))}
</div>
{filteredNovels.length === 0 && (
<div className="text-center py-12">
<DocumentTextIcon className="w-16 h-16 text-text-secondary mx-auto mb-4" />
<p className="text-text-secondary text-lg">
{searchTerm || filterStatus !== 'all' ? '没有找到符合条件的作品' : '您还没有创作任何作品'}
</p>
<button className="cyber-btn cyber-btn-primary mt-4">
<PlusIcon className="w-5 h-5 mr-2" />
开始创作
</button>
</div>
)}
{/* 作品详情模态框 */}
{selectedNovel && (
<div className="fixed inset-0 bg-black/50 backdrop-blur-sm z-50 flex items-center justify-center p-4">
<div className="glass-panel max-w-2xl w-full max-h-[80vh] overflow-y-auto">
<div className="p-6">
<div className="flex items-start justify-between mb-6">
<h2 className="text-2xl font-bold text-text-highlight">
{selectedNovel.title}
</h2>
<button
onClick={() => setSelectedNovel(null)}
className="text-text-secondary hover:text-text-primary transition-colors"
>
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<div className="space-y-4">
<div className="grid grid-cols-2 gap-4 text-sm">
<div>
<span className="text-text-secondary">状态:</span>
<span className={getStatusColor(selectedNovel.status)}>
{getStatusText(selectedNovel.status)}
</span>
</div>
<div>
<span className="text-text-secondary">题材:</span>
<span className="text-text-primary">{selectedNovel.genre}</span>
</div>
<div>
<span className="text-text-secondary">字数:</span>
<span className="text-text-primary">{selectedNovel.word_count.toLocaleString()}</span>
</div>
<div>
<span className="text-text-secondary">创建时间:</span>
<span className="text-text-primary">
{new Date(selectedNovel.created_at).toLocaleDateString('zh-CN')}
</span>
</div>
</div>
<div>
<h3 className="font-medium text-text-primary mb-2">内容预览</h3>
<p className="text-text-secondary leading-relaxed">
{selectedNovel.content}
</p>
</div>
<div className="flex space-x-3 pt-4">
<button
onClick={() => {
handleAction('edit', selectedNovel);
setSelectedNovel(null);
}}
className="cyber-btn cyber-btn-primary flex-1"
>
<PencilIcon className="w-4 h-4 mr-2" />
编辑
</button>
<button
onClick={() => {
handleAction('download', selectedNovel);
setSelectedNovel(null);
}}
className="cyber-btn cyber-btn-secondary flex-1"
>
<ArrowDownTrayIcon className="w-4 h-4 mr-2" />
下载
</button>
</div>
</div>
</div>
</div>
</div>
)}
</div>
);
};
export default ProjectManagement;