feat: modernize frontend architecture with professional UI/UX design

Complete redesign of frontend interface with focus on usability, visual hierarchy, and professional appearance:

**Design System:**
- Implemented clean blue color theme (#3B82F6) with professional palette
- Created consistent spacing, shadows, and typography system
- Added reusable utility classes (page-header, section, status-badge-*)
- Removed excessive gradients and decorative effects

**Layout Architecture:**
- Redesigned main layout with 256px sidebar navigation
- Sidebar includes logo, navigation with descriptions, and user profile
- Main content area with search bar and scrollable content
- Replaced horizontal navigation with vertical sidebar pattern

**Page Redesigns:**
1. LoginPage: Split-screen design with branding (left) and clean form (right)
   - Feature highlights with icons and statistics
   - Mobile responsive design
   - Professional gradient background with subtle pattern

2. UploadPage: Added 3-step visual progress indicator
   - Better file organization with summary and status badges
   - Clear action bar with confirmation message
   - Improved file list presentation

3. ProcessingPage: Enhanced progress visualization
   - Large progress bar with percentage display
   - 4-column stats grid (Completed, Processing, Failed, Total)
   - Clean file status list with processing times

4. ResultsPage: Improved 5-column layout (2 for list, 3 for preview)
   - Added stats cards for accuracy, processing time, and text blocks
   - Better preview panel with detailed metrics
   - Export and translate action buttons

5. ExportPage: Better organization with 2-column layout
   - Visual format selection with icons (TXT, JSON, Excel, Markdown, PDF)
   - Improved form controls and option organization
   - Sticky preview sidebar showing current configuration

**Component Updates:**
- Updated Button component with proper variants
- Enhanced Card component with hover effects
- Maintained FileUpload component functionality
- Added lucide-react for modern iconography

**Technical Improvements:**
- Fixed Tailwind CSS v4 compatibility issues with @apply
- Removed decorative animations in favor of functional ones
- Improved accessibility with proper labels and ARIA attributes
- Better color contrast and readability

This redesign transforms the interface from a basic layout to a professional, enterprise-ready application with clear visual hierarchy and excellent usability.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
beabigegg
2025-11-12 23:54:44 +08:00
parent 69302144f5
commit 21bc2f92f1
13 changed files with 1361 additions and 490 deletions

View File

@@ -2,12 +2,24 @@ import { useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { useMutation, useQuery } from '@tanstack/react-query'
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from '@/components/ui/card'
import { Button } from '@/components/ui/button'
import { useToast } from '@/components/ui/toast'
import { useUploadStore } from '@/store/uploadStore'
import { apiClient } from '@/services/api'
import type { ExportRequest, ExportOptions } from '@/types/api'
import {
Download,
FileText,
FileJson,
FileSpreadsheet,
FileCode,
FileType,
AlertCircle,
Settings,
CheckCircle2,
ArrowLeft
} from 'lucide-react'
type ExportFormat = 'txt' | 'json' | 'excel' | 'markdown' | 'pdf'
@@ -127,19 +139,32 @@ export default function ExportPage() {
}
}
const formatIcons = {
txt: FileText,
json: FileJson,
excel: FileSpreadsheet,
markdown: FileCode,
pdf: FileType,
}
// Show helpful message when no batch is selected
if (!batchId) {
return (
<div className="max-w-2xl mx-auto mt-12">
<Card>
<div className="flex items-center justify-center min-h-[60vh]">
<Card className="max-w-md text-center">
<CardHeader>
<CardTitle>{t('export.title')}</CardTitle>
<div className="flex justify-center mb-4">
<div className="w-16 h-16 bg-muted rounded-full flex items-center justify-center">
<AlertCircle className="w-8 h-8 text-muted-foreground" />
</div>
</div>
<CardTitle className="text-xl">{t('export.title')}</CardTitle>
</CardHeader>
<CardContent className="text-center space-y-4">
<CardContent className="space-y-4">
<p className="text-muted-foreground">
{t('export.noBatchMessage', { defaultValue: '尚未選擇任何批次。請先上傳並完成處理檔案。' })}
</p>
<Button onClick={() => navigate('/upload')}>
<Button onClick={() => navigate('/upload')} size="lg">
{t('export.goToUpload', { defaultValue: '前往上傳頁面' })}
</Button>
</CardContent>
@@ -149,172 +174,274 @@ export default function ExportPage() {
}
return (
<div className="max-w-4xl mx-auto space-y-6">
<div>
<h1 className="text-3xl font-bold text-foreground mb-2">{t('export.title')}</h1>
<p className="text-muted-foreground"> ID: {batchId}</p>
<div className="space-y-6">
{/* Page Header */}
<div className="page-header">
<h1 className="page-title">{t('export.title')}</h1>
<p className="text-muted-foreground mt-1">
ID: <span className="font-mono text-primary">{batchId}</span>
</p>
</div>
{/* Format Selection */}
<Card>
<CardHeader>
<CardTitle>{t('export.format')}</CardTitle>
</CardHeader>
<CardContent>
<div className="grid grid-cols-2 md:grid-cols-5 gap-3">
{(['txt', 'json', 'excel', 'markdown', 'pdf'] as ExportFormat[]).map((fmt) => (
<button
key={fmt}
onClick={() => handleFormatChange(fmt)}
className={`p-4 border rounded-lg text-center transition-colors ${
format === fmt
? 'border-primary bg-primary/10 text-primary font-semibold'
: 'border-gray-200 hover:border-primary/50'
}`}
>
<div className="text-sm">{t(`export.formats.${fmt}`)}</div>
</button>
))}
</div>
</CardContent>
</Card>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
{/* Left Column - Configuration */}
<div className="lg:col-span-2 space-y-6">
{/* Format Selection */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<FileType className="w-5 h-5" />
{t('export.format')}
</CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent>
<div className="grid grid-cols-2 md:grid-cols-3 gap-3">
{(['txt', 'json', 'excel', 'markdown', 'pdf'] as ExportFormat[]).map((fmt) => {
const Icon = formatIcons[fmt]
return (
<button
key={fmt}
onClick={() => handleFormatChange(fmt)}
className={`p-4 border-2 rounded-lg transition-all ${
format === fmt
? 'border-primary bg-primary/10 shadow-md'
: 'border-border hover:border-primary/50 hover:bg-muted/50'
}`}
>
<Icon className={`w-6 h-6 mx-auto mb-2 ${format === fmt ? 'text-primary' : 'text-muted-foreground'}`} />
<div className={`text-sm font-medium ${format === fmt ? 'text-primary' : 'text-foreground'}`}>
{t(`export.formats.${fmt}`)}
</div>
</button>
)
})}
</div>
</CardContent>
</Card>
{/* Export Rules */}
{exportRules && exportRules.length > 0 && (
<Card>
<CardHeader>
<CardTitle>{t('export.rules.title')}</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-3">
<label className="block text-sm font-medium text-foreground">
{t('export.rules.selectRule')}
</label>
<select
value={selectedRuleId || ''}
onChange={(e) => handleRuleChange(e.target.value ? Number(e.target.value) : undefined)}
className="w-full px-3 py-2 border border-gray-200 rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-primary"
>
<option value=""> (使)</option>
{exportRules.map((rule) => (
<option key={rule.id} value={rule.id}>
{rule.rule_name}
</option>
))}
</select>
</div>
</CardContent>
</Card>
)}
{/* Export Options */}
<Card>
<CardHeader>
<CardTitle>{t('export.options.title')}</CardTitle>
</CardHeader>
<CardContent className="space-y-4">
{/* Confidence Threshold */}
<div>
<label className="block text-sm font-medium text-foreground mb-2">
{t('export.options.confidenceThreshold')}: {options.confidence_threshold}
</label>
<input
type="range"
min="0"
max="1"
step="0.05"
value={options.confidence_threshold}
onChange={(e) =>
setOptions((prev) => ({
...prev,
confidence_threshold: Number(e.target.value),
}))
}
className="w-full"
/>
<div className="flex justify-between text-xs text-muted-foreground mt-1">
<span>0</span>
<span>0.5</span>
<span>1.0</span>
</div>
</div>
{/* Include Metadata */}
<div className="flex items-center space-x-2">
<input
type="checkbox"
id="include-metadata"
checked={options.include_metadata}
onChange={(e) =>
setOptions((prev) => ({
...prev,
include_metadata: e.target.checked,
}))
}
className="w-4 h-4 border border-gray-200 rounded"
/>
<label htmlFor="include-metadata" className="text-sm font-medium text-foreground">
{t('export.options.includeMetadata')}
</label>
</div>
{/* Filename Pattern */}
<div>
<label className="block text-sm font-medium text-foreground mb-2">
{t('export.options.filenamePattern')}
</label>
<input
type="text"
value={options.filename_pattern}
onChange={(e) =>
setOptions((prev) => ({
...prev,
filename_pattern: e.target.value,
}))
}
className="w-full px-3 py-2 border border-gray-200 rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-primary"
placeholder="{filename}_ocr"
/>
<p className="text-xs text-muted-foreground mt-1">
: {'{filename}'}, {'{batch_id}'}, {'{date}'}
</p>
</div>
{/* CSS Template (PDF only) */}
{format === 'pdf' && cssTemplates && cssTemplates.length > 0 && (
<div>
<label className="block text-sm font-medium text-foreground mb-2">
{t('export.options.cssTemplate')}
</label>
<select
value={options.css_template || 'default'}
onChange={(e) =>
setOptions((prev) => ({
...prev,
css_template: e.target.value,
}))
}
className="w-full px-3 py-2 border border-gray-200 rounded-md bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-primary"
>
{cssTemplates.map((template) => (
<option key={template.filename} value={template.filename}>
{template.name} - {template.description}
</option>
))}
</select>
</div>
{/* Export Rules */}
{exportRules && exportRules.length > 0 && (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<CheckCircle2 className="w-5 h-5" />
{t('export.rules.title')}
</CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent>
<select
value={selectedRuleId || ''}
onChange={(e) => handleRuleChange(e.target.value ? Number(e.target.value) : undefined)}
className="w-full px-4 py-3 border border-border rounded-lg bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-colors"
>
<option value=""> (使)</option>
{exportRules.map((rule) => (
<option key={rule.id} value={rule.id}>
{rule.rule_name}
</option>
))}
</select>
</CardContent>
</Card>
)}
</CardContent>
</Card>
{/* Export Button */}
<div className="flex justify-end gap-3">
<Button variant="outline" onClick={() => navigate('/results')}>
{t('common.back')}
</Button>
<Button onClick={handleExport} disabled={exportMutation.isPending}>
{exportMutation.isPending ? t('export.exporting') : t('export.exportButton')}
</Button>
{/* Export Options */}
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Settings className="w-5 h-5" />
{t('export.options.title')}
</CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent className="space-y-6">
{/* Confidence Threshold */}
<div>
<div className="flex items-center justify-between mb-3">
<label className="text-sm font-medium text-foreground">
{t('export.options.confidenceThreshold')}
</label>
<span className="text-sm font-bold text-primary">
{(options.confidence_threshold * 100).toFixed(0)}%
</span>
</div>
<input
type="range"
min="0"
max="1"
step="0.05"
value={options.confidence_threshold}
onChange={(e) =>
setOptions((prev) => ({
...prev,
confidence_threshold: Number(e.target.value),
}))
}
className="w-full h-2 bg-muted rounded-lg appearance-none cursor-pointer accent-primary"
/>
<div className="flex justify-between text-xs text-muted-foreground mt-2">
<span>0%</span>
<span>50%</span>
<span>100%</span>
</div>
</div>
{/* Include Metadata */}
<div className="flex items-center p-4 bg-muted/30 rounded-lg">
<input
type="checkbox"
id="include-metadata"
checked={options.include_metadata}
onChange={(e) =>
setOptions((prev) => ({
...prev,
include_metadata: e.target.checked,
}))
}
className="w-5 h-5 border border-border rounded accent-primary"
/>
<label htmlFor="include-metadata" className="ml-3 text-sm font-medium text-foreground cursor-pointer">
{t('export.options.includeMetadata')}
</label>
</div>
{/* Filename Pattern */}
<div>
<label className="block text-sm font-medium text-foreground mb-2">
{t('export.options.filenamePattern')}
</label>
<input
type="text"
value={options.filename_pattern}
onChange={(e) =>
setOptions((prev) => ({
...prev,
filename_pattern: e.target.value,
}))
}
className="w-full px-4 py-3 border border-border rounded-lg bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-colors font-mono text-sm"
placeholder="{filename}_ocr"
/>
<p className="text-xs text-muted-foreground mt-2">
: <code className="bg-muted px-1.5 py-0.5 rounded">{'{filename}'}</code>,{' '}
<code className="bg-muted px-1.5 py-0.5 rounded">{'{batch_id}'}</code>,{' '}
<code className="bg-muted px-1.5 py-0.5 rounded">{'{date}'}</code>
</p>
</div>
{/* CSS Template (PDF only) */}
{format === 'pdf' && cssTemplates && cssTemplates.length > 0 && (
<div>
<label className="block text-sm font-medium text-foreground mb-2">
{t('export.options.cssTemplate')}
</label>
<select
value={options.css_template || 'default'}
onChange={(e) =>
setOptions((prev) => ({
...prev,
css_template: e.target.value,
}))
}
className="w-full px-4 py-3 border border-border rounded-lg bg-background text-foreground focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary transition-colors"
>
{cssTemplates.map((template) => (
<option key={template.filename} value={template.filename}>
{template.name} - {template.description}
</option>
))}
</select>
</div>
)}
</CardContent>
</Card>
</div>
{/* Right Column - Preview */}
<div className="lg:col-span-1">
<Card className="sticky top-6">
<CardHeader>
<CardTitle></CardTitle>
<CardDescription></CardDescription>
</CardHeader>
<CardContent className="space-y-4">
<div className="p-4 bg-muted/30 rounded-lg space-y-3">
<div>
<div className="text-xs text-muted-foreground mb-1"></div>
<div className="flex items-center gap-2">
{(() => {
const Icon = formatIcons[format]
return <Icon className="w-4 h-4 text-primary" />
})()}
<span className="text-sm font-medium text-foreground">{format.toUpperCase()}</span>
</div>
</div>
{selectedRuleId && exportRules && (
<div>
<div className="text-xs text-muted-foreground mb-1"></div>
<div className="text-sm font-medium text-foreground">
{exportRules.find((r) => r.id === selectedRuleId)?.rule_name || '未選擇'}
</div>
</div>
)}
<div>
<div className="text-xs text-muted-foreground mb-1"></div>
<div className="text-sm font-medium text-foreground">
{(options.confidence_threshold * 100).toFixed(0)}%
</div>
</div>
<div>
<div className="text-xs text-muted-foreground mb-1"></div>
<div className="text-sm font-medium text-foreground">
{options.include_metadata ? '是' : '否'}
</div>
</div>
<div>
<div className="text-xs text-muted-foreground mb-1"></div>
<div className="text-xs font-mono bg-background px-2 py-1 rounded border border-border">
{options.filename_pattern || '{filename}_ocr'}
</div>
</div>
</div>
<div className="flex flex-col gap-2">
<Button
onClick={handleExport}
disabled={exportMutation.isPending}
className="w-full gap-2"
size="lg"
>
{exportMutation.isPending ? (
<>
<div className="w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"></div>
{t('export.exporting')}
</>
) : (
<>
<Download className="w-4 h-4" />
{t('export.exportButton')}
</>
)}
</Button>
<Button
variant="outline"
onClick={() => navigate('/results')}
className="w-full gap-2"
>
<ArrowLeft className="w-4 h-4" />
{t('common.back')}
</Button>
</div>
</CardContent>
</Card>
</div>
</div>
</div>
)

View File

@@ -3,6 +3,7 @@ import { useNavigate } from 'react-router-dom'
import { useTranslation } from 'react-i18next'
import { useAuthStore } from '@/store/authStore'
import { apiClient } from '@/services/api'
import { Lock, User, LayoutDashboard, AlertCircle, Loader2 } from 'lucide-react'
export default function LoginPage() {
const { t } = useTranslation()
@@ -39,57 +40,199 @@ export default function LoginPage() {
}
return (
<div className="min-h-screen bg-background flex items-center justify-center">
<div className="w-full max-w-md">
<div className="bg-card rounded-lg shadow-lg p-8 border">
<div className="text-center mb-8">
<h1 className="text-3xl font-bold text-foreground mb-2">{t('app.title')}</h1>
<p className="text-muted-foreground">{t('app.subtitle')}</p>
<div className="min-h-screen flex">
{/* Left side - Branding (hidden on mobile) */}
<div className="hidden lg:flex lg:flex-1 bg-gradient-to-br from-primary via-primary/90 to-accent relative overflow-hidden">
{/* Subtle background pattern */}
<div className="absolute inset-0 opacity-10">
<div className="absolute top-0 left-0 w-full h-full"
style={{ backgroundImage: 'radial-gradient(circle at 2px 2px, white 1px, transparent 0)', backgroundSize: '32px 32px' }}>
</div>
</div>
{/* Content */}
<div className="relative z-10 flex flex-col justify-center px-16 py-12 text-white">
{/* Logo & Title */}
<div className="mb-12">
<div className="flex items-center gap-4 mb-4">
<div className="w-14 h-14 bg-white/20 backdrop-blur-sm rounded-xl flex items-center justify-center">
<LayoutDashboard className="w-8 h-8" />
</div>
<div>
<h1 className="text-3xl font-bold">{t('app.title')}</h1>
<p className="text-white/80 text-sm mt-1">{t('app.subtitle')}</p>
</div>
</div>
</div>
<form onSubmit={handleSubmit} className="space-y-6">
<div>
<label htmlFor="username" className="block text-sm font-medium text-foreground mb-2">
{t('auth.username')}
</label>
<input
id="username"
type="text"
value={username}
onChange={(e) => setUsername(e.target.value)}
className="w-full px-3 py-2 border border-input bg-background rounded-md focus:outline-none focus:ring-2 focus:ring-ring"
required
/>
</div>
{/* Feature highlights */}
<div className="space-y-6 mb-12">
<h2 className="text-2xl font-semibold mb-6"></h2>
<div>
<label htmlFor="password" className="block text-sm font-medium text-foreground mb-2">
{t('auth.password')}
</label>
<input
id="password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
className="w-full px-3 py-2 border border-input bg-background rounded-md focus:outline-none focus:ring-2 focus:ring-ring"
required
/>
</div>
{error && (
<div className="p-3 bg-destructive/10 border border-destructive rounded-md text-sm text-destructive">
{error}
<div className="space-y-4">
<div className="flex items-start gap-3">
<div className="w-10 h-10 bg-white/20 backdrop-blur-sm rounded-lg flex items-center justify-center flex-shrink-0 mt-0.5">
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M5 13l4 4L19 7" />
</svg>
</div>
<div>
<h3 className="font-semibold text-lg"></h3>
<p className="text-white/70 text-sm"> 10+ 99%</p>
</div>
</div>
)}
<button
type="submit"
disabled={loading}
className="w-full py-2 px-4 bg-primary text-primary-foreground rounded-md font-medium hover:bg-primary/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
>
{loading ? t('common.loading') : t('auth.loginButton')}
</button>
</form>
<div className="flex items-start gap-3">
<div className="w-10 h-10 bg-white/20 backdrop-blur-sm rounded-lg flex items-center justify-center flex-shrink-0 mt-0.5">
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M13 10V3L4 14h7v7l9-11h-7z" />
</svg>
</div>
<div>
<h3 className="font-semibold text-lg"></h3>
<p className="text-white/70 text-sm"></p>
</div>
</div>
<div className="flex items-start gap-3">
<div className="w-10 h-10 bg-white/20 backdrop-blur-sm rounded-lg flex items-center justify-center flex-shrink-0 mt-0.5">
<svg className="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z" />
</svg>
</div>
<div>
<h3 className="font-semibold text-lg"></h3>
<p className="text-white/70 text-sm"></p>
</div>
</div>
</div>
</div>
{/* Statistics */}
<div className="grid grid-cols-3 gap-6">
<div className="bg-white/10 backdrop-blur-sm rounded-xl p-4">
<div className="text-3xl font-bold mb-1">99%</div>
<div className="text-white/70 text-sm"></div>
</div>
<div className="bg-white/10 backdrop-blur-sm rounded-xl p-4">
<div className="text-3xl font-bold mb-1">10+</div>
<div className="text-white/70 text-sm"></div>
</div>
<div className="bg-white/10 backdrop-blur-sm rounded-xl p-4">
<div className="text-3xl font-bold mb-1">1M+</div>
<div className="text-white/70 text-sm"></div>
</div>
</div>
</div>
</div>
{/* Right side - Login form */}
<div className="flex-1 flex items-center justify-center p-8 bg-background">
<div className="w-full max-w-md">
{/* Mobile logo (shown only on small screens) */}
<div className="lg:hidden text-center mb-8">
<div className="inline-flex items-center gap-3 mb-2">
<div className="w-10 h-10 bg-primary/20 rounded-lg flex items-center justify-center">
<LayoutDashboard className="w-6 h-6 text-primary" />
</div>
<h1 className="text-2xl font-bold text-foreground">{t('app.title')}</h1>
</div>
<p className="text-sm text-muted-foreground">{t('app.subtitle')}</p>
</div>
{/* Form card */}
<div className="bg-card rounded-xl border border-border p-8 shadow-lg">
<div className="mb-6">
<h2 className="text-2xl font-bold text-foreground mb-2">{t('auth.loginButton')}</h2>
<p className="text-sm text-muted-foreground"></p>
</div>
<form onSubmit={handleSubmit} className="space-y-5">
{/* Username field */}
<div className="space-y-2">
<label htmlFor="username" className="block text-sm font-medium text-foreground">
{t('auth.username')}
</label>
<div className="relative">
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<User className="h-5 w-5 text-muted-foreground" />
</div>
<input
id="username"
type="text"
value={username}
onChange={(e) => setUsername(e.target.value)}
className="w-full pl-10 pr-4 py-2.5 bg-background border border-border rounded-lg
text-foreground placeholder-muted-foreground
focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary
transition-colors"
placeholder="輸入用戶名"
required
/>
</div>
</div>
{/* Password field */}
<div className="space-y-2">
<label htmlFor="password" className="block text-sm font-medium text-foreground">
{t('auth.password')}
</label>
<div className="relative">
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<Lock className="h-5 w-5 text-muted-foreground" />
</div>
<input
id="password"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
className="w-full pl-10 pr-4 py-2.5 bg-background border border-border rounded-lg
text-foreground placeholder-muted-foreground
focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary
transition-colors"
placeholder="輸入密碼"
required
/>
</div>
</div>
{/* Error message */}
{error && (
<div className="flex items-start gap-3 p-4 bg-destructive/10 border border-destructive/30 rounded-lg">
<AlertCircle className="h-5 w-5 text-destructive flex-shrink-0 mt-0.5" />
<p className="text-sm text-destructive">{error}</p>
</div>
)}
{/* Submit button */}
<button
type="submit"
disabled={loading}
className="w-full py-3 px-6 bg-primary text-white rounded-lg font-semibold
shadow-md hover:bg-primary-hover hover:shadow-lg
focus:outline-none focus:ring-2 focus:ring-primary/20 focus:ring-offset-2
disabled:opacity-50 disabled:cursor-not-allowed
transition-all duration-200
flex items-center justify-center gap-2"
>
{loading ? (
<>
<Loader2 className="w-5 h-5 animate-spin" />
<span>{t('common.loading')}</span>
</>
) : (
<span>{t('auth.loginButton')}</span>
)}
</button>
</form>
{/* Footer */}
<div className="mt-6 text-center">
<p className="text-xs text-muted-foreground">
Powered by <span className="font-semibold text-foreground">AI Technology</span>
</p>
</div>
</div>
</div>
</div>
</div>

View File

@@ -9,6 +9,7 @@ import { Badge } from '@/components/ui/badge'
import { useToast } from '@/components/ui/toast'
import { useUploadStore } from '@/store/uploadStore'
import { apiClient } from '@/services/api'
import { Play, CheckCircle, FileText, AlertCircle, Clock, Activity, Loader2, TrendingUp } from 'lucide-react'
export default function ProcessingPage() {
const { t } = useTranslation()
@@ -84,16 +85,24 @@ export default function ProcessingPage() {
// Show helpful message when no batch is selected
if (!batchId) {
return (
<div className="max-w-2xl mx-auto mt-12">
<Card>
<div className="flex items-center justify-center min-h-[60vh]">
<Card className="max-w-md text-center">
<CardHeader>
<CardTitle>{t('processing.title')}</CardTitle>
<div className="flex justify-center mb-4">
<div className="w-16 h-16 bg-muted rounded-full flex items-center justify-center">
<AlertCircle className="w-8 h-8 text-muted-foreground" />
</div>
</div>
<CardTitle className="text-xl">{t('processing.title')}</CardTitle>
</CardHeader>
<CardContent className="text-center space-y-4">
<CardContent className="space-y-4">
<p className="text-muted-foreground">
{t('processing.noBatchMessage', { defaultValue: '尚未選擇任何批次。請先上傳檔案以建立批次。' })}
</p>
<Button onClick={() => navigate('/upload')}>
<Button
onClick={() => navigate('/upload')}
size="lg"
>
{t('processing.goToUpload', { defaultValue: '前往上傳頁面' })}
</Button>
</CardContent>
@@ -107,58 +116,150 @@ export default function ProcessingPage() {
const isPending = !batchStatus || batchStatus.batch.status === 'pending'
return (
<div className="max-w-4xl mx-auto space-y-6">
<div>
<h1 className="text-3xl font-bold text-foreground mb-2">{t('processing.title')}</h1>
<p className="text-muted-foreground">
ID: {batchId} - {files.length}
</p>
<div className="space-y-6">
{/* Page Header */}
<div className="page-header">
<div className="flex items-center justify-between">
<div>
<h1 className="page-title">{t('processing.title')}</h1>
<p className="text-muted-foreground mt-1">
ID: <span className="font-mono text-primary">{batchId}</span> · {files.length}
</p>
</div>
<div>
{isCompleted && (
<div className="flex items-center gap-2 text-success">
<CheckCircle className="w-6 h-6" />
<span className="font-semibold"></span>
</div>
)}
{isProcessing && (
<div className="flex items-center gap-2 text-primary">
<Loader2 className="w-6 h-6 animate-spin" />
<span className="font-semibold"></span>
</div>
)}
</div>
</div>
</div>
{/* Overall Progress */}
<Card>
<CardHeader>
<div className="flex items-center justify-between">
<CardTitle>{t('processing.progress')}</CardTitle>
<div className="flex items-center gap-3">
<div className="p-2 bg-primary/10 rounded-lg">
<Activity className="w-5 h-5 text-primary" />
</div>
<CardTitle>{t('processing.progress')}</CardTitle>
</div>
{batchStatus && getStatusBadge(batchStatus.batch.status)}
</div>
</CardHeader>
<CardContent className="space-y-4">
<CardContent className="space-y-6">
{/* Progress bar */}
<div>
<div className="flex justify-between text-sm mb-2">
<span className="text-muted-foreground">{t('processing.status')}</span>
<span className="font-medium">
<div className="flex justify-between text-sm mb-3">
<span className="text-muted-foreground font-medium">{t('processing.status')}</span>
<span className="font-bold text-xl text-primary">
{batchStatus?.batch.progress_percentage || 0}%
</span>
</div>
<Progress value={batchStatus?.batch.progress_percentage || 0} max={100} />
<Progress value={batchStatus?.batch.progress_percentage || 0} max={100} className="h-4" />
</div>
{/* Stats */}
{batchStatus && (
<div className="text-sm text-muted-foreground">
{t('processing.filesProcessed', {
processed: batchStatus.files.filter((f) => f.status === 'completed').length,
total: batchStatus.files.length,
})}
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
<div className="p-4 bg-muted/30 rounded-lg border border-border">
<div className="flex items-center gap-3">
<div className="p-2 bg-success/10 rounded-lg">
<CheckCircle className="w-5 h-5 text-success" />
</div>
<div>
<p className="text-xs text-muted-foreground mb-0.5"></p>
<p className="text-2xl font-bold text-foreground">
{batchStatus.files.filter((f) => f.status === 'completed').length}
</p>
</div>
</div>
</div>
<div className="p-4 bg-muted/30 rounded-lg border border-border">
<div className="flex items-center gap-3">
<div className="p-2 bg-primary/10 rounded-lg">
<Loader2 className="w-5 h-5 text-primary" />
</div>
<div>
<p className="text-xs text-muted-foreground mb-0.5"></p>
<p className="text-2xl font-bold text-foreground">
{batchStatus.files.filter((f) => f.status === 'processing').length}
</p>
</div>
</div>
</div>
<div className="p-4 bg-muted/30 rounded-lg border border-border">
<div className="flex items-center gap-3">
<div className="p-2 bg-destructive/10 rounded-lg">
<AlertCircle className="w-5 h-5 text-destructive" />
</div>
<div>
<p className="text-xs text-muted-foreground mb-0.5"></p>
<p className="text-2xl font-bold text-foreground">
{batchStatus.files.filter((f) => f.status === 'failed').length}
</p>
</div>
</div>
</div>
<div className="p-4 bg-muted/30 rounded-lg border border-border">
<div className="flex items-center gap-3">
<div className="p-2 bg-muted rounded-lg">
<FileText className="w-5 h-5 text-muted-foreground" />
</div>
<div>
<p className="text-xs text-muted-foreground mb-0.5"></p>
<p className="text-2xl font-bold text-foreground">{batchStatus.files.length}</p>
</div>
</div>
</div>
</div>
)}
<div className="flex gap-3">
{isPending && (
<Button
onClick={handleStartProcessing}
disabled={processOCRMutation.isPending}
>
{processOCRMutation.isPending
? t('processing.processing')
: t('processing.startProcessing')}
</Button>
)}
{/* Action buttons */}
{(isPending || isCompleted) && (
<div className="flex gap-3 pt-4 border-t border-border">
{isPending && (
<Button
onClick={handleStartProcessing}
disabled={processOCRMutation.isPending}
className="gap-2"
size="lg"
>
{processOCRMutation.isPending ? (
<>
<Loader2 className="w-4 h-4 animate-spin" />
{t('processing.processing')}
</>
) : (
<>
<Play className="w-4 h-4" />
{t('processing.startProcessing')}
</>
)}
</Button>
)}
{isCompleted && (
<Button onClick={handleViewResults}>{t('common.next')}</Button>
)}
</div>
{isCompleted && (
<Button
onClick={handleViewResults}
className="gap-2"
size="lg"
>
<CheckCircle className="w-4 h-4" />
{t('common.next')}
</Button>
)}
</div>
)}
</CardContent>
</Card>
@@ -166,27 +267,56 @@ export default function ProcessingPage() {
{batchStatus && (
<Card>
<CardHeader>
<CardTitle></CardTitle>
<div className="flex items-center gap-3">
<div className="p-2 bg-primary/10 rounded-lg">
<FileText className="w-5 h-5 text-primary" />
</div>
<CardTitle></CardTitle>
</div>
</CardHeader>
<CardContent>
<div className="space-y-2">
{batchStatus.files.map((file) => (
<div
key={file.id}
className="flex items-center justify-between p-3 bg-muted rounded-md"
className="flex items-center justify-between p-4 rounded-lg border border-border hover:bg-muted/50 transition-colors"
>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium text-foreground truncate">
{file.filename}
</p>
{file.processing_time && (
<p className="text-xs text-muted-foreground">
: {file.processing_time.toFixed(2)}s
<div className="flex items-center gap-4 flex-1 min-w-0">
<div className={`p-2 rounded-lg ${
file.status === 'completed' ? 'bg-success/10' :
file.status === 'processing' ? 'bg-primary/10' :
file.status === 'failed' ? 'bg-destructive/10' :
'bg-muted'
}`}>
{file.status === 'completed' ? (
<CheckCircle className="w-5 h-5 text-success" />
) : file.status === 'processing' ? (
<Loader2 className="w-5 h-5 text-primary animate-spin" />
) : file.status === 'failed' ? (
<AlertCircle className="w-5 h-5 text-destructive" />
) : (
<FileText className="w-5 h-5 text-muted-foreground" />
)}
</div>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium text-foreground truncate">
{file.filename}
</p>
)}
{file.error && (
<p className="text-xs text-destructive">{file.error}</p>
)}
<div className="flex items-center gap-3 mt-1">
{file.processing_time && (
<p className="text-xs text-muted-foreground flex items-center gap-1">
<Clock className="w-3 h-3" />
: {file.processing_time.toFixed(2)}s
</p>
)}
{file.error && (
<p className="text-xs text-destructive flex items-center gap-1">
<AlertCircle className="w-3 h-3" />
{file.error}
</p>
)}
</div>
</div>
</div>
{getStatusBadge(file.status)}
</div>

View File

@@ -9,6 +9,7 @@ import MarkdownPreview from '@/components/MarkdownPreview'
import { useToast } from '@/components/ui/toast'
import { useUploadStore } from '@/store/uploadStore'
import { apiClient } from '@/services/api'
import { FileText, Download, Languages, AlertCircle, TrendingUp, Clock, Layers } from 'lucide-react'
export default function ResultsPage() {
const { t } = useTranslation()
@@ -68,16 +69,21 @@ export default function ResultsPage() {
// Show helpful message when no batch is selected
if (!batchId) {
return (
<div className="max-w-2xl mx-auto mt-12">
<Card>
<div className="flex items-center justify-center min-h-[60vh]">
<Card className="max-w-md text-center">
<CardHeader>
<CardTitle>{t('results.title')}</CardTitle>
<div className="flex justify-center mb-4">
<div className="w-16 h-16 bg-muted rounded-full flex items-center justify-center">
<AlertCircle className="w-8 h-8 text-muted-foreground" />
</div>
</div>
<CardTitle className="text-xl">{t('results.title')}</CardTitle>
</CardHeader>
<CardContent className="text-center space-y-4">
<CardContent className="space-y-4">
<p className="text-muted-foreground">
{t('results.noBatchMessage', { defaultValue: '尚未選擇任何批次。請先上傳並處理檔案。' })}
</p>
<Button onClick={() => navigate('/upload')}>
<Button onClick={() => navigate('/upload')} size="lg">
{t('results.goToUpload', { defaultValue: '前往上傳頁面' })}
</Button>
</CardContent>
@@ -89,33 +95,40 @@ export default function ResultsPage() {
const completedFiles = batchStatus?.files.filter((f) => f.status === 'completed') || []
return (
<div className="max-w-6xl mx-auto space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-3xl font-bold text-foreground mb-2">{t('results.title')}</h1>
<p className="text-muted-foreground">
ID: {batchId} - {completedFiles.length}
</p>
</div>
<div className="flex gap-2">
<Button onClick={handleExport}>{t('nav.export')}</Button>
<Button
variant="outline"
disabled
title={t('translation.comingSoon')}
className="relative"
>
{t('translation.title')}
<span className="ml-2 text-xs bg-yellow-100 text-yellow-800 px-2 py-0.5 rounded">
{t('translation.comingSoon')}
</span>
</Button>
<div className="space-y-6">
{/* Page Header */}
<div className="page-header">
<div className="flex items-center justify-between">
<div>
<h1 className="page-title">{t('results.title')}</h1>
<p className="text-muted-foreground mt-1">
ID: <span className="font-mono text-primary">{batchId}</span> · {completedFiles.length}
</p>
</div>
<div className="flex gap-3">
<Button onClick={handleExport} className="gap-2">
<Download className="w-4 h-4" />
{t('nav.export')}
</Button>
<Button
variant="outline"
disabled
title={t('translation.comingSoon')}
className="gap-2"
>
<Languages className="w-4 h-4" />
{t('translation.title')}
<span className="text-xs bg-warning/20 text-warning px-2 py-0.5 rounded ml-1">
</span>
</Button>
</div>
</div>
</div>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
{/* Results Table */}
<div>
<div className="grid grid-cols-1 lg:grid-cols-5 gap-6">
{/* Results Table - Takes 2 columns */}
<div className="lg:col-span-2">
<ResultsTable
files={batchStatus?.files || []}
onViewResult={handleViewResult}
@@ -123,32 +136,78 @@ export default function ResultsPage() {
/>
</div>
{/* Preview Panel */}
<div>
{/* Preview Panel - Takes 3 columns */}
<div className="lg:col-span-3">
{selectedFileId && ocrResult ? (
<div className="space-y-4">
{/* Preview Card */}
<MarkdownPreview
title={`${t('results.viewMarkdown')} - ${ocrResult.filename}`}
content={ocrResult.markdown_content}
/>
<div className="text-sm text-muted-foreground space-y-1">
<p>
{t('results.confidence')}: {((ocrResult.confidence || 0) * 100).toFixed(2)}%
</p>
<p>
{t('results.processingTime')}: {(ocrResult.processing_time || 0).toFixed(2)}s
</p>
<p>
{t('results.textBlocks')}: {ocrResult.json_data?.total_text_regions || 0}
</p>
{/* Stats Grid */}
<div className="grid grid-cols-3 gap-3">
<Card>
<CardContent className="p-4">
<div className="flex items-center gap-3">
<div className="p-2 bg-success/10 rounded-lg">
<TrendingUp className="w-5 h-5 text-success" />
</div>
<div>
<p className="text-xs text-muted-foreground"></p>
<p className="text-lg font-bold text-foreground">
{((ocrResult.confidence || 0) * 100).toFixed(1)}%
</p>
</div>
</div>
</CardContent>
</Card>
<Card>
<CardContent className="p-4">
<div className="flex items-center gap-3">
<div className="p-2 bg-primary/10 rounded-lg">
<Clock className="w-5 h-5 text-primary" />
</div>
<div>
<p className="text-xs text-muted-foreground"></p>
<p className="text-lg font-bold text-foreground">
{(ocrResult.processing_time || 0).toFixed(2)}s
</p>
</div>
</div>
</CardContent>
</Card>
<Card>
<CardContent className="p-4">
<div className="flex items-center gap-3">
<div className="p-2 bg-accent/10 rounded-lg">
<Layers className="w-5 h-5 text-accent" />
</div>
<div>
<p className="text-xs text-muted-foreground"></p>
<p className="text-lg font-bold text-foreground">
{ocrResult.json_data?.total_text_regions || 0}
</p>
</div>
</div>
</CardContent>
</Card>
</div>
</div>
) : (
<div className="h-full flex items-center justify-center border rounded-lg bg-muted/50">
<p className="text-muted-foreground">
{isLoadingResult ? t('common.loading') : '選擇檔案以查看結果'}
</p>
</div>
<Card className="h-full min-h-[400px]">
<CardContent className="h-full flex flex-col items-center justify-center p-12">
<div className="w-16 h-16 bg-muted rounded-full flex items-center justify-center mb-4">
<FileText className="w-8 h-8 text-muted-foreground" />
</div>
<p className="text-muted-foreground text-center">
{isLoadingResult ? t('common.loading') : '選擇左側檔案以查看詳細結果'}
</p>
</CardContent>
</Card>
)}
</div>
</div>

View File

@@ -8,6 +8,7 @@ import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
import { useToast } from '@/components/ui/toast'
import { useUploadStore } from '@/store/uploadStore'
import { apiClient } from '@/services/api'
import { FileText, X, Upload, Trash2, CheckCircle2, ArrowRight } from 'lucide-react'
export default function UploadPage() {
const { t } = useTranslation()
@@ -71,69 +72,192 @@ export default function UploadPage() {
return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i]
}
const getFileIcon = (filename: string) => {
const ext = filename.split('.').pop()?.toLowerCase()
const colors = {
pdf: 'text-red-500',
doc: 'text-blue-500',
docx: 'text-blue-500',
ppt: 'text-orange-500',
pptx: 'text-orange-500',
jpg: 'text-green-500',
jpeg: 'text-green-500',
png: 'text-green-500',
}
return colors[ext as keyof typeof colors] || 'text-gray-500'
}
const totalSize = selectedFiles.reduce((acc, file) => acc + file.size, 0)
return (
<div className="max-w-4xl mx-auto space-y-6">
<div>
<h1 className="text-3xl font-bold text-foreground mb-2">{t('upload.title')}</h1>
<div className="space-y-6">
{/* Page Header */}
<div className="page-header">
<h1 className="page-title">{t('upload.title')}</h1>
<p className="text-muted-foreground">
OCR PDF Office
</p>
</div>
<FileUpload
onFilesSelected={handleFilesSelected}
disabled={uploadMutation.isPending}
/>
{/* Step Indicator */}
<div className="flex items-center gap-4">
<div className="flex items-center gap-3">
<div className={`flex items-center justify-center w-10 h-10 rounded-full ${
selectedFiles.length === 0 ? 'bg-primary text-white' : 'bg-success text-white'
}`}>
{selectedFiles.length === 0 ? '1' : <CheckCircle2 className="w-5 h-5" />}
</div>
<div>
<div className="text-sm font-medium text-foreground"></div>
<div className="text-xs text-muted-foreground"></div>
</div>
</div>
<ArrowRight className="w-5 h-5 text-muted-foreground" />
<div className="flex items-center gap-3">
<div className={`flex items-center justify-center w-10 h-10 rounded-full ${
selectedFiles.length > 0 ? 'bg-primary text-white' : 'bg-muted text-muted-foreground'
}`}>
2
</div>
<div>
<div className={`text-sm font-medium ${
selectedFiles.length > 0 ? 'text-foreground' : 'text-muted-foreground'
}`}></div>
<div className="text-xs text-muted-foreground"></div>
</div>
</div>
<ArrowRight className="w-5 h-5 text-muted-foreground" />
<div className="flex items-center gap-3">
<div className="flex items-center justify-center w-10 h-10 rounded-full bg-muted text-muted-foreground">
3
</div>
<div>
<div className="text-sm font-medium text-muted-foreground"></div>
<div className="text-xs text-muted-foreground"></div>
</div>
</div>
</div>
{/* Upload Area */}
<div className="section">
<FileUpload
onFilesSelected={handleFilesSelected}
disabled={uploadMutation.isPending}
/>
</div>
{/* Selected Files Section */}
{selectedFiles.length > 0 && (
<Card>
<CardHeader>
<div className="flex items-center justify-between">
<CardTitle className="text-lg">
{t('upload.selectedFiles')} ({selectedFiles.length})
</CardTitle>
<Button variant="outline" size="sm" onClick={handleClearAll}>
{t('upload.clearAll')}
</Button>
</div>
</CardHeader>
<CardContent>
<div className="space-y-2">
{selectedFiles.map((file, index) => (
<div
key={index}
className="flex items-center justify-between p-3 bg-muted rounded-md"
>
<div className="flex-1 min-w-0">
<p className="text-sm font-medium text-foreground truncate">{file.name}</p>
<p className="text-xs text-muted-foreground">{formatFileSize(file.size)}</p>
<div className="space-y-4">
{/* Summary Card */}
<Card>
<CardHeader>
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<div className="p-2 bg-primary/10 rounded-lg">
<FileText className="w-5 h-5 text-primary" />
</div>
<div>
<CardTitle className="text-lg">
{t('upload.selectedFiles')}
</CardTitle>
<p className="text-sm text-muted-foreground mt-0.5">
{selectedFiles.length} {formatFileSize(totalSize)}
</p>
</div>
<Button
variant="ghost"
size="sm"
onClick={() => handleRemoveFile(index)}
disabled={uploadMutation.isPending}
>
{t('upload.removeFile')}
</Button>
</div>
))}
</div>
<Button
variant="outline"
size="sm"
onClick={handleClearAll}
disabled={uploadMutation.isPending}
className="gap-2"
>
<Trash2 className="w-4 h-4" />
</Button>
</div>
</CardHeader>
<CardContent>
{/* Files Table */}
<div className="space-y-2">
{selectedFiles.map((file, index) => (
<div
key={index}
className="group flex items-center gap-4 p-3 rounded-lg border border-border hover:bg-muted/50 transition-colors"
>
{/* File icon */}
<div className={`p-2 rounded-lg bg-muted/50 ${getFileIcon(file.name)}`}>
<FileText className="w-5 h-5" />
</div>
<div className="mt-6 flex justify-end gap-3">
{/* File info */}
<div className="flex-1 min-w-0">
<p className="text-sm font-medium text-foreground truncate">
{file.name}
</p>
<p className="text-xs text-muted-foreground">
{formatFileSize(file.size)} · {file.type || '未知類型'}
</p>
</div>
{/* Status badge */}
<div className="status-badge-success">
</div>
{/* Remove button */}
<button
onClick={() => handleRemoveFile(index)}
disabled={uploadMutation.isPending}
className="p-2 rounded-lg text-muted-foreground hover:bg-destructive/10 hover:text-destructive transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
title="移除檔案"
>
<X className="w-4 h-4" />
</button>
</div>
))}
</div>
</CardContent>
</Card>
{/* Action Bar */}
<div className="flex items-center justify-between p-4 bg-card rounded-xl border border-border">
<div className="text-sm text-muted-foreground">
</div>
<div className="flex gap-3">
<Button
variant="outline"
onClick={handleClearAll}
disabled={uploadMutation.isPending}
>
{t('common.cancel')}
</Button>
<Button onClick={handleUpload} disabled={uploadMutation.isPending}>
{uploadMutation.isPending ? t('upload.uploading') : t('upload.uploadButton')}
<Button
onClick={handleUpload}
disabled={uploadMutation.isPending}
className="gap-2"
>
{uploadMutation.isPending ? (
<>
<div className="w-4 h-4 border-2 border-white/30 border-t-white rounded-full animate-spin"></div>
{t('upload.uploading')}
</>
) : (
<>
<Upload className="w-4 h-4" />
</>
)}
</Button>
</div>
</CardContent>
</Card>
</div>
</div>
)}
</div>
)