|
| 1 | +/** |
| 2 | + * 批量整理控件(入口按钮 + 操作条 + 进度条) |
| 3 | + * Batch sort controls (entry button, action bar and progress bar). |
| 4 | + * |
| 5 | + * @ai-context: 从 InspirationPage 拆出的批量模式 UI:进入/退出批量、全选/取消全选、 |
| 6 | + * 一键分析(AIThinkingIndicator 分析中状态)、分析进度文案与进度条。选中数量与 |
| 7 | + * 进度经 props 由页面状态驱动,渲染结构与原内联 JSX 完全一致。 |
| 8 | + * @ai-context: Extracted from InspirationPage; selection count and progress are |
| 9 | + * driven by page state via props, markup identical to the original inline JSX. |
| 10 | + */ |
| 11 | + |
| 12 | +import { motion, AnimatePresence } from 'framer-motion'; |
| 13 | +import { Layers, Wand2 } from 'lucide-react'; |
| 14 | +import { AIThinkingIndicator } from '@/components/ui/AIThinkingIndicator'; |
| 15 | +import { cn } from '@/lib/utils'; |
| 16 | + |
| 17 | +interface BatchControlsProps { |
| 18 | + batchMode: boolean; |
| 19 | + onToggleBatchMode: () => void; |
| 20 | + selectedCount: number; |
| 21 | + onSelectAll: () => void; |
| 22 | + onDeselectAll: () => void; |
| 23 | + onBatchSort: () => void; |
| 24 | + batchProcessing: boolean; |
| 25 | + progress: number; |
| 26 | + total: number; |
| 27 | +} |
| 28 | + |
| 29 | +export default function BatchControls({ |
| 30 | + batchMode, |
| 31 | + onToggleBatchMode, |
| 32 | + selectedCount, |
| 33 | + onSelectAll, |
| 34 | + onDeselectAll, |
| 35 | + onBatchSort, |
| 36 | + batchProcessing, |
| 37 | + progress, |
| 38 | + total, |
| 39 | +}: BatchControlsProps) { |
| 40 | + return ( |
| 41 | + <> |
| 42 | + {/* ── 批量模式入口 ── */} |
| 43 | + <div className="flex items-center justify-between mt-1"> |
| 44 | + <motion.button |
| 45 | + whileTap={{ scale: 0.95 }} |
| 46 | + onClick={onToggleBatchMode} |
| 47 | + className={cn( |
| 48 | + 'flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-medium border transition-colors', |
| 49 | + batchMode |
| 50 | + ? 'bg-accent-500/10 border-accent-400/40 text-accent-600 dark:text-accent-400' |
| 51 | + : 'bg-bg-secondary border-border/40 text-text-tertiary hover:text-text-secondary', |
| 52 | + )} |
| 53 | + > |
| 54 | + <Layers className="w-3.5 h-3.5" /> |
| 55 | + {batchMode ? '退出批量' : '批量整理'} |
| 56 | + </motion.button> |
| 57 | + {batchMode && selectedCount > 0 && ( |
| 58 | + <span className="text-c1 text-text-tertiary">已选中 {selectedCount} 条</span> |
| 59 | + )} |
| 60 | + </div> |
| 61 | + {/* ── 批量操作条 ── */} |
| 62 | + <AnimatePresence> |
| 63 | + {batchMode && ( |
| 64 | + <motion.div |
| 65 | + initial={{ opacity: 0, height: 0 }} |
| 66 | + animate={{ opacity: 1, height: 'auto' }} |
| 67 | + exit={{ opacity: 0, height: 0 }} |
| 68 | + className="flex items-center gap-2 flex-wrap pt-1" |
| 69 | + > |
| 70 | + <motion.button whileTap={{ scale: 0.95 }} onClick={onSelectAll} |
| 71 | + className="px-2 py-0.5 rounded-full text-xs font-medium text-text-secondary bg-bg-secondary border border-border/40 hover:text-text-primary transition-colors"> |
| 72 | + 全选 |
| 73 | + </motion.button> |
| 74 | + <motion.button whileTap={{ scale: 0.95 }} onClick={onDeselectAll} |
| 75 | + className="px-2 py-0.5 rounded-full text-xs font-medium text-text-tertiary bg-bg-secondary border border-border/40 hover:text-text-secondary transition-colors"> |
| 76 | + 取消全选 |
| 77 | + </motion.button> |
| 78 | + <motion.button |
| 79 | + whileTap={{ scale: 0.95 }} |
| 80 | + onClick={onBatchSort} |
| 81 | + disabled={selectedCount === 0 || batchProcessing} |
| 82 | + className={cn( |
| 83 | + 'flex items-center gap-1 px-3 py-1 rounded-full text-xs font-medium', |
| 84 | + 'bg-gradient-to-r from-cyber to-brand-500 text-text-inverse', |
| 85 | + 'hover:from-cyber/90 hover:to-brand-600 shadow-sm shadow-cyber/20', |
| 86 | + 'disabled:opacity-50 disabled:cursor-not-allowed', |
| 87 | + )} |
| 88 | + > |
| 89 | + {batchProcessing ? (<><AIThinkingIndicator size={3} gap={2} />分析中...</>) : (<><Wand2 className="w-3 h-3" />一键分析</>)} |
| 90 | + </motion.button> |
| 91 | + {batchProcessing && ( |
| 92 | + <span className="text-c1 text-text-tertiary">正在分析 {progress}/{total}...</span> |
| 93 | + )} |
| 94 | + </motion.div> |
| 95 | + )} |
| 96 | + </AnimatePresence> |
| 97 | + {/* ── 批量进度条 ── */} |
| 98 | + {batchProcessing && total > 0 && ( |
| 99 | + <div className="w-full h-1.5 rounded-full bg-bg-secondary overflow-hidden mt-1"> |
| 100 | + <motion.div |
| 101 | + className="h-full rounded-full bg-gradient-to-r from-cyber to-brand-500" |
| 102 | + initial={{ width: 0 }} |
| 103 | + animate={{ width: `${(progress / total) * 100}%` }} |
| 104 | + transition={{ duration: 0.3 }} |
| 105 | + /> |
| 106 | + </div> |
| 107 | + )} |
| 108 | + </> |
| 109 | + ); |
| 110 | +} |
0 commit comments