update: fix-02
This commit is contained in:
@@ -31,9 +31,10 @@ import {
|
||||
CloseCircleOutlined,
|
||||
ZoomInOutlined,
|
||||
PlayCircleOutlined,
|
||||
DeleteOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import type { EvidenceImage, SourceApp, PageType } from '../../types';
|
||||
import { fetchImageDetail, fetchImages, startCaseOcr } from '../../services/api';
|
||||
import { deleteCaseImages, fetchImageDetail, fetchImages, startCaseOcr } from '../../services/api';
|
||||
|
||||
const appLabel: Record<SourceApp, { label: string; color: string }> = {
|
||||
wechat: { label: '微信', color: 'green' },
|
||||
@@ -182,11 +183,49 @@ const Screenshots: React.FC = () => {
|
||||
const [selectedIds, setSelectedIds] = useState<string[]>([]);
|
||||
const [rerunTracking, setRerunTracking] = useState<Record<string, { sawProcessing: boolean }>>({});
|
||||
const [editableTxs, setEditableTxs] = useState<EditableTx[]>([]);
|
||||
const [lastProcessingCount, setLastProcessingCount] = useState(0);
|
||||
|
||||
const { data: allImages = [] } = useQuery({
|
||||
queryKey: ['images', id],
|
||||
queryFn: () => fetchImages(id),
|
||||
refetchInterval: Object.keys(rerunTracking).length > 0 ? 2000 : false,
|
||||
refetchInterval: (query) => {
|
||||
const images = (query.state.data as EvidenceImage[] | undefined) ?? [];
|
||||
const hasBackendProcessing = images.some((img) => img.ocrStatus === 'processing');
|
||||
return hasBackendProcessing || Object.keys(rerunTracking).length > 0 ? 2000 : false;
|
||||
},
|
||||
});
|
||||
const deleteMutation = useMutation({
|
||||
mutationFn: (targetIds: string[]) => deleteCaseImages(id, targetIds),
|
||||
onMutate: () => {
|
||||
message.open({
|
||||
key: 'screenshots-delete',
|
||||
type: 'loading',
|
||||
content: `正在删除选中截图(${selectedIds.length})...`,
|
||||
duration: 0,
|
||||
});
|
||||
},
|
||||
onSuccess: (res, targetIds) => {
|
||||
message.open({
|
||||
key: 'screenshots-delete',
|
||||
type: 'success',
|
||||
content: res.message,
|
||||
});
|
||||
setSelectedIds((prev) => prev.filter((x) => !targetIds.includes(x)));
|
||||
if (selectedImage && targetIds.includes(selectedImage.id)) {
|
||||
setDrawerOpen(false);
|
||||
setSelectedImage(null);
|
||||
}
|
||||
queryClient.invalidateQueries({ queryKey: ['images', id] });
|
||||
queryClient.invalidateQueries({ queryKey: ['transactions', id] });
|
||||
queryClient.invalidateQueries({ queryKey: ['case', id] });
|
||||
},
|
||||
onError: () => {
|
||||
message.open({
|
||||
key: 'screenshots-delete',
|
||||
type: 'error',
|
||||
content: '删除截图失败',
|
||||
});
|
||||
},
|
||||
});
|
||||
const triggerOcrMutation = useMutation({
|
||||
mutationFn: (targetIds: string[]) =>
|
||||
@@ -276,6 +315,15 @@ const Screenshots: React.FC = () => {
|
||||
if (backendStatus === 'done' && tracking.sawProcessing) return 'done';
|
||||
return 'processing';
|
||||
};
|
||||
React.useEffect(() => {
|
||||
const processingCount = allImages.filter(
|
||||
(img) => resolveOcrStatus(img.id, img.ocrStatus) === 'processing',
|
||||
).length;
|
||||
if (lastProcessingCount > 0 && processingCount === 0) {
|
||||
message.success('OCR识别已完成');
|
||||
}
|
||||
setLastProcessingCount(processingCount);
|
||||
}, [allImages, rerunTracking, lastProcessingCount, message]);
|
||||
React.useEffect(() => {
|
||||
if (Object.keys(rerunTracking).length === 0) return;
|
||||
const statusById = new Map(allImages.map((img) => [img.id, img.ocrStatus] as const));
|
||||
@@ -408,7 +456,16 @@ const Screenshots: React.FC = () => {
|
||||
disabled={selectedIds.length === 0}
|
||||
onClick={() => triggerOcrMutation.mutate(selectedIds)}
|
||||
>
|
||||
{selectedIds.length > 0 ? `对选中图片重新OCR(${selectedIds.length})` : '开始 OCR 识别'}
|
||||
OCR 识别
|
||||
</Button>
|
||||
<Button
|
||||
danger
|
||||
icon={<DeleteOutlined />}
|
||||
loading={deleteMutation.isPending}
|
||||
disabled={selectedIds.length === 0}
|
||||
onClick={() => deleteMutation.mutate(selectedIds)}
|
||||
>
|
||||
删除选中截图
|
||||
</Button>
|
||||
<Button onClick={selectAllFiltered}>全选当前筛选</Button>
|
||||
<Button onClick={clearSelection} disabled={selectedIds.length === 0}>清空选择</Button>
|
||||
|
||||
Reference in New Issue
Block a user