fix(phase2): 修复 PR#75 代码审计 P1 问题
P1-1: DuplicationUpload 使用 navigate 替代 window.location.href,避免整页刷新 P1-2: DuplicationResults 批量删除使用 Promise.allSettled,部分失败时正确反馈结果 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -118,16 +118,18 @@ const DuplicationResults: React.FC = () => {
|
||||
|
||||
/** 批量删除 */
|
||||
const handleBatchDelete = async () => {
|
||||
try {
|
||||
await Promise.all(
|
||||
selectedRowKeys.map((key) => deleteDuplicationRecord(String(key)))
|
||||
);
|
||||
message.success(`已删除 ${selectedRowKeys.length} 条记录`);
|
||||
setSelectedRowKeys([]);
|
||||
queryClient.invalidateQueries({ queryKey: ['duplication-records'] });
|
||||
} catch {
|
||||
message.error('批量删除失败');
|
||||
const results = await Promise.allSettled(
|
||||
selectedRowKeys.map((key) => deleteDuplicationRecord(String(key)))
|
||||
);
|
||||
const succeeded = results.filter((r) => r.status === 'fulfilled').length;
|
||||
const failed = results.length - succeeded;
|
||||
if (failed === 0) {
|
||||
message.success(`已删除 ${succeeded} 条记录`);
|
||||
} else {
|
||||
message.warning(`删除完成:${succeeded} 条成功,${failed} 条失败`);
|
||||
}
|
||||
setSelectedRowKeys([]);
|
||||
queryClient.invalidateQueries({ queryKey: ['duplication-records'] });
|
||||
};
|
||||
|
||||
const columns: ColumnsType<DuplicationRecord> = [
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
LoadingOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { uploadForDuplication } from '@/api/duplication';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import type { UploadFile } from 'antd/es/upload';
|
||||
|
||||
const { Title, Text, Paragraph } = Typography;
|
||||
@@ -33,6 +34,7 @@ const ACCEPT_FORMATS = '.mp4,.avi,.mov,.mkv,.wmv,.flv,.webm';
|
||||
const MAX_FILE_SIZE = 2 * 1024 * 1024 * 1024;
|
||||
|
||||
const DuplicationUpload: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
const [fileList, setFileList] = useState<UploadFile[]>([]);
|
||||
const [uploadResult, setUploadResult] = useState<{
|
||||
id: string;
|
||||
@@ -150,9 +152,7 @@ const DuplicationUpload: React.FC = () => {
|
||||
type="primary"
|
||||
key="view"
|
||||
icon={<CheckCircleOutlined />}
|
||||
onClick={() =>
|
||||
(window.location.href = `/duplication/results`)
|
||||
}
|
||||
onClick={() => navigate('/duplication/results')}
|
||||
>
|
||||
查看结果
|
||||
</Button>,
|
||||
|
||||
Reference in New Issue
Block a user