557 lines
24 KiB
React
557 lines
24 KiB
React
import { useState, useEffect, useRef, useCallback } from 'react';
|
||
import {
|
||
Droplets, Eraser, Loader2, X, Play, Square, CheckCircle2,
|
||
AlertTriangle, Save, FileEdit, Eye
|
||
} from 'lucide-react';
|
||
import { batchAPI, imageAPI } from '../api';
|
||
|
||
/**
|
||
* 批量水印弹窗(文件夹级)
|
||
* mode='add' 批量加水印:文字水印(九宫格单个 / 平铺)
|
||
* mode='remove' 批量去水印:按百分比区域生成 mask → 后端 LaMa inpaint
|
||
*
|
||
* 流程:配置 → 启动任务(立即返回 taskId)→ 1s 轮询进度 → 完成/取消
|
||
*/
|
||
|
||
// 九宫格位置(与后端 makeWatermarkSvg 的 pos 规则一致)
|
||
const POSITIONS = [
|
||
['top-left', 'top-center', 'top-right'],
|
||
['middle-left', 'middle-center', 'middle-right'],
|
||
['bottom-left', 'bottom-center', 'bottom-right']
|
||
];
|
||
const POSITION_LABEL = {
|
||
'top-left': '左上', 'top-center': '顶部', 'top-right': '右上',
|
||
'middle-left': '左侧', 'middle-center': '居中', 'middle-right': '右侧',
|
||
'bottom-left': '左下', 'bottom-center': '底部', 'bottom-right': '右下'
|
||
};
|
||
|
||
// 去水印预设区域(百分比)
|
||
const REGION_PRESETS = [
|
||
{ key: 'bottom-right', label: '右下角', region: { x: 68, y: 86, w: 30, h: 11 } },
|
||
{ key: 'bottom-left', label: '左下角', region: { x: 2, y: 86, w: 30, h: 11 } },
|
||
{ key: 'top-right', label: '右上角', region: { x: 68, y: 3, w: 30, h: 11 } },
|
||
{ key: 'top-left', label: '左上角', region: { x: 2, y: 3, w: 30, h: 11 } },
|
||
{ key: 'center', label: '画面居中', region: { x: 35, y: 42, w: 30, h: 16 } },
|
||
{ key: 'bottom-bar', label: '底部横条', region: { x: 0, y: 88, w: 100, h: 11 } },
|
||
{ key: 'right-bar', label: '右侧竖条', region: { x: 85, y: 0, w: 15, h: 100 } },
|
||
{ key: 'custom', label: '自定义', region: null }
|
||
];
|
||
|
||
const clampPct = (v) => Math.max(0, Math.min(100, Number(v) || 0));
|
||
|
||
function Field({ label, children, hint }) {
|
||
return (
|
||
<div className="mb-4">
|
||
<div className="text-xs font-medium text-gray-500 dark:text-gray-400 mb-1.5">{label}</div>
|
||
{children}
|
||
{hint && <div className="text-[11px] text-gray-400 dark:text-gray-500 mt-1">{hint}</div>}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function Slider({ value, onChange, min, max, step = 1, suffix = '' }) {
|
||
return (
|
||
<div className="flex items-center gap-3">
|
||
<input
|
||
type="range"
|
||
className="flex-1 accent-blue-500"
|
||
value={value}
|
||
min={min}
|
||
max={max}
|
||
step={step}
|
||
onChange={(e) => onChange(Number(e.target.value))}
|
||
/>
|
||
<span className="text-xs text-gray-600 dark:text-gray-300 w-12 text-right tabular-nums">
|
||
{value}{suffix}
|
||
</span>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function BatchWatermarkModal({ isOpen, mode, folder, libraryId, onClose, onFinished }) {
|
||
const [phase, setPhase] = useState('config'); // config | running | done
|
||
const [imageCount, setImageCount] = useState(0);
|
||
const [starting, setStarting] = useState(false);
|
||
const [error, setError] = useState('');
|
||
|
||
// 加水印配置
|
||
const [text, setText] = useState('');
|
||
const [tile, setTile] = useState(false);
|
||
const [position, setPosition] = useState('bottom-right');
|
||
const [fontSizePct, setFontSizePct] = useState(4);
|
||
const [opacity, setOpacity] = useState(50);
|
||
const [color, setColor] = useState('#ffffff');
|
||
const [marginPct, setMarginPct] = useState(2);
|
||
const [rotate, setRotate] = useState(-30);
|
||
const [stroke, setStroke] = useState(true);
|
||
|
||
// 去水印配置
|
||
const [presetKey, setPresetKey] = useState('bottom-right');
|
||
const [region, setRegion] = useState({ x: 68, y: 86, w: 30, h: 11 });
|
||
|
||
// 输出方式
|
||
const [output, setOutput] = useState('overwrite');
|
||
|
||
// 任务进度
|
||
const [taskId, setTaskId] = useState(null);
|
||
const [progress, setProgress] = useState(null);
|
||
const pollRef = useRef(null);
|
||
|
||
// 打开时重置 + 取图片数
|
||
useEffect(() => {
|
||
if (!isOpen) return;
|
||
setPhase('config');
|
||
setError('');
|
||
setTaskId(null);
|
||
setProgress(null);
|
||
setStarting(false);
|
||
setOutput('overwrite');
|
||
if (mode === 'remove') {
|
||
setPresetKey('bottom-right');
|
||
setRegion({ x: 68, y: 86, w: 30, h: 11 });
|
||
}
|
||
let cancelled = false;
|
||
(async () => {
|
||
try {
|
||
const resp = await imageAPI.getCount(libraryId, { folder });
|
||
if (!cancelled) setImageCount(resp.count ?? 0);
|
||
} catch (_) {
|
||
if (!cancelled) setImageCount(0);
|
||
}
|
||
})();
|
||
return () => { cancelled = true; };
|
||
}, [isOpen, mode, folder, libraryId]);
|
||
|
||
// 停止轮询
|
||
const stopPolling = useCallback(() => {
|
||
if (pollRef.current) {
|
||
clearInterval(pollRef.current);
|
||
pollRef.current = null;
|
||
}
|
||
}, []);
|
||
|
||
useEffect(() => stopPolling, [stopPolling]);
|
||
|
||
const startPolling = useCallback((id) => {
|
||
stopPolling();
|
||
pollRef.current = setInterval(async () => {
|
||
try {
|
||
const s = await batchAPI.status(id);
|
||
setProgress(s);
|
||
if (s.status !== 'running') {
|
||
stopPolling();
|
||
setPhase('done');
|
||
onFinished?.(s);
|
||
}
|
||
} catch (_) {
|
||
/* 网络抖动,继续轮询 */
|
||
}
|
||
}, 1000);
|
||
}, [stopPolling, onFinished]);
|
||
|
||
const handleStart = async () => {
|
||
setError('');
|
||
if (mode === 'add' && !text.trim()) {
|
||
setError('请输入水印文字');
|
||
return;
|
||
}
|
||
setStarting(true);
|
||
try {
|
||
const payload = { libraryId, folder, type: mode, output };
|
||
payload.options = mode === 'add'
|
||
? { text: text.trim(), tile, position, fontSizePct, opacity, color, marginPct, rotate, stroke }
|
||
: { region };
|
||
const resp = await batchAPI.start(payload);
|
||
setTaskId(resp.taskId);
|
||
setPhase('running');
|
||
setProgress({
|
||
status: 'running', total: resp.total, done: 0, failed: 0,
|
||
skipped: 0, current: '', errors: []
|
||
});
|
||
startPolling(resp.taskId);
|
||
} catch (err) {
|
||
setError(err?.message || '启动失败');
|
||
} finally {
|
||
setStarting(false);
|
||
}
|
||
};
|
||
|
||
const handleCancel = async () => {
|
||
if (!taskId) return;
|
||
try {
|
||
await batchAPI.cancel(taskId);
|
||
} catch (_) { /* 任务可能已结束 */ }
|
||
stopPolling();
|
||
setPhase('done');
|
||
};
|
||
|
||
const handleClose = () => {
|
||
stopPolling();
|
||
onClose();
|
||
};
|
||
|
||
if (!isOpen) return null;
|
||
|
||
const isAdd = mode === 'add';
|
||
const title = isAdd ? '批量加水印' : '批量去水印';
|
||
const Icon = isAdd ? Droplets : Eraser;
|
||
const accent = isAdd ? 'text-blue-500' : 'text-emerald-500';
|
||
const accentBtn = isAdd ? 'bg-blue-500 hover:bg-blue-600' : 'bg-emerald-500 hover:bg-emerald-600';
|
||
|
||
const pct = progress && progress.total > 0
|
||
? Math.round(((progress.done + progress.failed + progress.skipped) / progress.total) * 100)
|
||
: 0;
|
||
|
||
return (
|
||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
|
||
<div
|
||
className="bg-white dark:bg-gray-800 rounded-xl shadow-2xl w-full max-w-2xl max-h-[90vh] overflow-hidden flex flex-col"
|
||
onClick={(e) => e.stopPropagation()}
|
||
>
|
||
{/* 头部 */}
|
||
<div className="flex items-center justify-between px-5 py-4 border-b border-gray-200 dark:border-gray-700">
|
||
<div className="flex items-center gap-2.5">
|
||
<Icon className={`w-5 h-5 ${accent}`} />
|
||
<h2 className="text-lg font-semibold text-gray-900 dark:text-white">{title}</h2>
|
||
<span className="text-xs px-2 py-0.5 rounded-full bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300 truncate max-w-[240px]">
|
||
{folder}
|
||
</span>
|
||
<span className="text-xs text-gray-400">{imageCount} 个文件</span>
|
||
</div>
|
||
<button onClick={handleClose} className="p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700">
|
||
<X className="w-5 h-5 text-gray-500" />
|
||
</button>
|
||
</div>
|
||
|
||
{/* 内容 */}
|
||
<div className="flex-1 overflow-y-auto p-5">
|
||
{phase === 'config' && (
|
||
<>
|
||
{isAdd ? (
|
||
<>
|
||
<Field label="水印文字">
|
||
<input
|
||
type="text"
|
||
value={text}
|
||
onChange={(e) => setText(e.target.value)}
|
||
placeholder="例如:素材室出品"
|
||
maxLength={50}
|
||
className="w-full px-3 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||
/>
|
||
</Field>
|
||
|
||
<Field label="水印形式">
|
||
<div className="flex gap-2">
|
||
<button
|
||
onClick={() => setTile(false)}
|
||
className={`flex-1 px-3 py-2 rounded-lg text-sm border transition-colors ${!tile
|
||
? 'border-blue-500 bg-blue-50 dark:bg-blue-900/40 text-blue-600 dark:text-blue-300'
|
||
: 'border-gray-300 dark:border-gray-600 text-gray-600 dark:text-gray-300'}`}
|
||
>
|
||
单个水印
|
||
</button>
|
||
<button
|
||
onClick={() => setTile(true)}
|
||
className={`flex-1 px-3 py-2 rounded-lg text-sm border transition-colors ${tile
|
||
? 'border-blue-500 bg-blue-50 dark:bg-blue-900/40 text-blue-600 dark:text-blue-300'
|
||
: 'border-gray-300 dark:border-gray-600 text-gray-600 dark:text-gray-300'}`}
|
||
>
|
||
全屏平铺
|
||
</button>
|
||
</div>
|
||
</Field>
|
||
|
||
{!tile && (
|
||
<Field label="位置">
|
||
<div className="grid grid-cols-3 gap-1.5 w-44">
|
||
{POSITIONS.flat().map((pos) => (
|
||
<button
|
||
key={pos}
|
||
onClick={() => setPosition(pos)}
|
||
title={POSITION_LABEL[pos]}
|
||
className={`px-1 py-1.5 rounded text-xs border transition-colors ${position === pos
|
||
? 'border-blue-500 bg-blue-50 dark:bg-blue-900/40 text-blue-600 dark:text-blue-300 font-medium'
|
||
: 'border-gray-300 dark:border-gray-600 text-gray-500 dark:text-gray-400 hover:border-gray-400'}`}
|
||
>
|
||
{POSITION_LABEL[pos]}
|
||
</button>
|
||
))}
|
||
</div>
|
||
</Field>
|
||
)}
|
||
|
||
<div className="grid grid-cols-2 gap-x-5">
|
||
<Field label="字号(占图宽比例)">
|
||
<Slider value={fontSizePct} onChange={setFontSizePct} min={1} max={15} suffix="%" />
|
||
</Field>
|
||
<Field label="透明度">
|
||
<Slider value={opacity} onChange={setOpacity} min={5} max={100} suffix="%" />
|
||
</Field>
|
||
<Field label={tile ? '倾斜角度' : '旋转角度'}>
|
||
<Slider value={rotate} onChange={setRotate} min={-90} max={90} suffix="°" />
|
||
</Field>
|
||
<Field label="边距(占图宽比例)">
|
||
<Slider value={marginPct} onChange={setMarginPct} min={0} max={10} suffix="%" />
|
||
</Field>
|
||
</div>
|
||
|
||
<div className="grid grid-cols-2 gap-x-5">
|
||
<Field label="颜色">
|
||
<div className="flex items-center gap-2">
|
||
<input
|
||
type="color"
|
||
value={color}
|
||
onChange={(e) => setColor(e.target.value)}
|
||
className="w-9 h-9 rounded cursor-pointer border border-gray-300 dark:border-gray-600 bg-transparent"
|
||
/>
|
||
{['#ffffff', '#000000', '#ff3b30', '#ffd60a'].map((c) => (
|
||
<button
|
||
key={c}
|
||
onClick={() => setColor(c)}
|
||
title={c}
|
||
className={`w-6 h-6 rounded-full border-2 ${color === c ? 'border-blue-500' : 'border-gray-300 dark:border-gray-600'}`}
|
||
style={{ backgroundColor: c }}
|
||
/>
|
||
))}
|
||
<span className="text-xs text-gray-500 tabular-nums">{color}</span>
|
||
</div>
|
||
</Field>
|
||
<Field label="描边(浅色背景更清晰)">
|
||
<label className="flex items-center gap-2 text-sm text-gray-700 dark:text-gray-300 cursor-pointer">
|
||
<input
|
||
type="checkbox"
|
||
checked={stroke}
|
||
onChange={(e) => setStroke(e.target.checked)}
|
||
className="accent-blue-500 w-4 h-4"
|
||
/>
|
||
启用黑色描边
|
||
</label>
|
||
</Field>
|
||
</div>
|
||
</>
|
||
) : (
|
||
<>
|
||
<Field label="水印区域(占图片宽高的百分比)" hint="批量去水印按统一区域处理,请选择水印所在的固定位置">
|
||
<div className="flex flex-wrap gap-2 mb-3">
|
||
{REGION_PRESETS.map((p) => (
|
||
<button
|
||
key={p.key}
|
||
onClick={() => {
|
||
setPresetKey(p.key);
|
||
if (p.region) setRegion(p.region);
|
||
}}
|
||
className={`px-3 py-1.5 rounded-lg text-xs border transition-colors ${presetKey === p.key
|
||
? 'border-emerald-500 bg-emerald-50 dark:bg-emerald-900/40 text-emerald-600 dark:text-emerald-300 font-medium'
|
||
: 'border-gray-300 dark:border-gray-600 text-gray-600 dark:text-gray-300 hover:border-gray-400'}`}
|
||
>
|
||
{p.label}
|
||
</button>
|
||
))}
|
||
</div>
|
||
|
||
<div className="flex items-center gap-4">
|
||
{/* 区域示意 */}
|
||
<div className="relative w-32 h-20 rounded border border-gray-300 dark:border-gray-600 bg-gray-100 dark:bg-gray-900 shrink-0 overflow-hidden">
|
||
<div
|
||
className="absolute bg-emerald-400/50 border border-emerald-500"
|
||
style={{
|
||
left: `${clampPct(region.x)}%`,
|
||
top: `${clampPct(region.y)}%`,
|
||
width: `${Math.max(1, Math.min(100 - clampPct(region.x), region.w))}%`,
|
||
height: `${Math.max(1, Math.min(100 - clampPct(region.y), region.h))}%`
|
||
}}
|
||
/>
|
||
</div>
|
||
<div className="grid grid-cols-2 gap-x-4 gap-y-2 text-xs">
|
||
{[['x', '左边距'], ['y', '上边距'], ['w', '宽度'], ['h', '高度']].map(([k, lb]) => (
|
||
<label key={k} className="flex items-center gap-2">
|
||
<span className="text-gray-500 dark:text-gray-400 w-10">{lb}</span>
|
||
<input
|
||
type="number"
|
||
min={0}
|
||
max={100}
|
||
value={region[k]}
|
||
onChange={(e) => {
|
||
setPresetKey('custom');
|
||
setRegion((r) => ({ ...r, [k]: clampPct(e.target.value) }));
|
||
}}
|
||
className="w-16 px-2 py-1 rounded border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white tabular-nums focus:outline-none focus:ring-2 focus:ring-emerald-500"
|
||
/>
|
||
<span className="text-gray-400">%</span>
|
||
</label>
|
||
))}
|
||
</div>
|
||
</div>
|
||
</Field>
|
||
|
||
<div className="rounded-lg bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 px-3 py-2.5 text-xs text-amber-700 dark:text-amber-300 flex gap-2">
|
||
<AlertTriangle className="w-4 h-4 shrink-0 mt-0.5" />
|
||
<span>
|
||
修复区域内的所有内容都会被抹除重建(包括文字、logo、图案)。水印位置在整批图片中不一致时请分批处理,或用编辑器单张涂抹。
|
||
</span>
|
||
</div>
|
||
</>
|
||
)}
|
||
|
||
{/* 输出方式 */}
|
||
<Field label="处理后">
|
||
<div className="flex gap-2">
|
||
<button
|
||
onClick={() => setOutput('overwrite')}
|
||
className={`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg text-sm border transition-colors ${output === 'overwrite'
|
||
? 'border-blue-500 bg-blue-50 dark:bg-blue-900/40 text-blue-600 dark:text-blue-300'
|
||
: 'border-gray-300 dark:border-gray-600 text-gray-600 dark:text-gray-300'}`}
|
||
>
|
||
<FileEdit className="w-4 h-4" /> 覆盖原图
|
||
</button>
|
||
<button
|
||
onClick={() => setOutput('new')}
|
||
className={`flex-1 flex items-center justify-center gap-2 px-3 py-2.5 rounded-lg text-sm border transition-colors ${output === 'new'
|
||
? 'border-blue-500 bg-blue-50 dark:bg-blue-900/40 text-blue-600 dark:text-blue-300'
|
||
: 'border-gray-300 dark:border-gray-600 text-gray-600 dark:text-gray-300'}`}
|
||
>
|
||
<Save className="w-4 h-4" /> 另存为新图
|
||
</button>
|
||
</div>
|
||
<div className="text-[11px] text-gray-400 dark:text-gray-500 mt-1.5">
|
||
{output === 'overwrite'
|
||
? '原图将被替换(缩略图与索引同步更新)'
|
||
: isAdd ? '生成 新图名_wm.jpg 保留原图' : '生成 新图名_nowm.jpg 保留原图'}
|
||
</div>
|
||
</Field>
|
||
|
||
{error && (
|
||
<div className="rounded-lg bg-red-50 dark:bg-red-900/30 border border-red-200 dark:border-red-800 px-3 py-2 text-xs text-red-600 dark:text-red-300">
|
||
{error}
|
||
</div>
|
||
)}
|
||
</>
|
||
)}
|
||
|
||
{(phase === 'running' || phase === 'done') && progress && (
|
||
<div className="py-2">
|
||
{/* 状态 */}
|
||
<div className="flex items-center gap-3 mb-4">
|
||
{phase === 'running' ? (
|
||
<Loader2 className="w-6 h-6 text-blue-500 animate-spin shrink-0" />
|
||
) : progress.failed > 0 ? (
|
||
<AlertTriangle className="w-6 h-6 text-amber-500 shrink-0" />
|
||
) : (
|
||
<CheckCircle2 className="w-6 h-6 text-emerald-500 shrink-0" />
|
||
)}
|
||
<div className="flex-1 min-w-0">
|
||
<div className="text-sm font-medium text-gray-900 dark:text-white">
|
||
{phase === 'running'
|
||
? (isAdd ? '正在加水印…' : '正在去水印…(AI 修复较慢,请耐心等待)')
|
||
: progress.status === 'cancelled'
|
||
? '已取消'
|
||
: progress.status === 'error'
|
||
? '任务异常终止'
|
||
: '处理完成'}
|
||
</div>
|
||
<div className="text-xs text-gray-500 dark:text-gray-400 truncate">
|
||
{phase === 'running' && progress.current
|
||
? progress.current
|
||
: `成功 ${progress.done} · 失败 ${progress.failed}${progress.skipped ? ` · 跳过 ${progress.skipped}` : ''} / 共 ${progress.total}`}
|
||
</div>
|
||
</div>
|
||
<div className="text-sm tabular-nums text-gray-600 dark:text-gray-300 shrink-0">
|
||
{progress.done + progress.failed + progress.skipped}/{progress.total}
|
||
</div>
|
||
</div>
|
||
|
||
{/* 进度条 */}
|
||
<div className="h-2.5 rounded-full bg-gray-200 dark:bg-gray-700 overflow-hidden mb-4">
|
||
<div
|
||
className={`h-full transition-all duration-300 ${progress.failed > 0 && phase === 'done' ? 'bg-amber-500' : isAdd ? 'bg-blue-500' : 'bg-emerald-500'}`}
|
||
style={{ width: `${pct}%` }}
|
||
/>
|
||
</div>
|
||
|
||
{/* 统计 */}
|
||
<div className="grid grid-cols-3 gap-2 mb-4">
|
||
{[
|
||
['成功', progress.done, 'text-emerald-600 dark:text-emerald-400'],
|
||
['失败', progress.failed, progress.failed ? 'text-red-500' : 'text-gray-500'],
|
||
['跳过', progress.skipped, 'text-gray-500']
|
||
].map(([lb, v, cls]) => (
|
||
<div key={lb} className="rounded-lg bg-gray-50 dark:bg-gray-900 px-3 py-2 text-center">
|
||
<div className={`text-lg font-semibold tabular-nums ${cls}`}>{v}</div>
|
||
<div className="text-[11px] text-gray-400">{lb}</div>
|
||
</div>
|
||
))}
|
||
</div>
|
||
|
||
{/* 错误明细 */}
|
||
{progress.errors && progress.errors.length > 0 && (
|
||
<div className="rounded-lg border border-red-200 dark:border-red-800 bg-red-50/50 dark:bg-red-900/20 p-3 mb-2">
|
||
<div className="text-xs font-medium text-red-600 dark:text-red-300 mb-1.5">
|
||
失败明细(最多记录 20 条)
|
||
</div>
|
||
<div className="space-y-1 max-h-40 overflow-y-auto">
|
||
{progress.errors.map((e, i) => (
|
||
<div key={i} className="text-[11px] text-red-500 dark:text-red-400 font-mono break-all">
|
||
{e.path || '(全局)'} — {e.error}
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
)}
|
||
</div>
|
||
)}
|
||
</div>
|
||
|
||
{/* 底部按钮 */}
|
||
<div className="px-5 py-4 border-t border-gray-200 dark:border-gray-700 flex justify-end gap-3">
|
||
{phase === 'config' && (
|
||
<>
|
||
<button
|
||
onClick={handleClose}
|
||
className="px-4 py-2.5 rounded-lg border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 text-sm"
|
||
>
|
||
取消
|
||
</button>
|
||
<button
|
||
onClick={handleStart}
|
||
disabled={starting || imageCount === 0}
|
||
className={`flex items-center gap-2 px-5 py-2.5 rounded-lg text-white text-sm disabled:opacity-50 disabled:cursor-not-allowed transition-colors ${accentBtn}`}
|
||
>
|
||
{starting ? <Loader2 className="w-4 h-4 animate-spin" /> : <Play className="w-4 h-4" />}
|
||
{imageCount === 0 ? '该文件夹没有可处理的文件' : `开始处理 ${imageCount} 个文件`}
|
||
</button>
|
||
</>
|
||
)}
|
||
|
||
{phase === 'running' && (
|
||
<button
|
||
onClick={handleCancel}
|
||
className="flex items-center gap-2 px-4 py-2.5 rounded-lg border border-red-300 text-red-600 hover:bg-red-50 dark:hover:bg-red-900/30 text-sm"
|
||
>
|
||
<Square className="w-4 h-4" /> 停止任务
|
||
</button>
|
||
)}
|
||
|
||
{phase === 'done' && (
|
||
<>
|
||
<button
|
||
onClick={() => setPhase('config')}
|
||
className="px-4 py-2.5 rounded-lg border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700 text-sm"
|
||
>
|
||
再跑一批
|
||
</button>
|
||
<button
|
||
onClick={handleClose}
|
||
className={`flex items-center gap-2 px-5 py-2.5 rounded-lg text-white text-sm transition-colors ${accentBtn}`}
|
||
>
|
||
<Eye className="w-4 h-4" /> 完成,查看图片
|
||
</button>
|
||
</>
|
||
)}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
export default BatchWatermarkModal;
|