File size: 14,778 Bytes
9dd9a58 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | 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; |