refactor(admin): 按 aislop 质量门禁修复两个代码质量警告
- RoleTour: buildSteps 拆分为各角色的声明式步骤常量,函数从 91 行降至组装逻辑 - ImportWizardModal: 抽取 uploadRun 共享 helper,消除 handleUpload/handleReupload 之间重复的上传进度与 loading 状态处理 aislop scan --changes: 99/100 → 100/100 (5 引擎 0 issues)
This commit is contained in:
@@ -40,6 +40,7 @@ import {
|
||||
type ImportPreviewResult,
|
||||
type ImportReceipt,
|
||||
type ImportRunDetail,
|
||||
type ImportStageRequest,
|
||||
type ImportStepKey,
|
||||
} from './types';
|
||||
|
||||
@@ -187,25 +188,41 @@ export const ImportWizardModal: React.FC<ImportWizardModalProps> = ({
|
||||
return [...headers];
|
||||
}, [run, activeStepKey, sheetSelection]);
|
||||
|
||||
const handleUpload: UploadProps['customRequest'] = async (options) => {
|
||||
const file = options.file as File;
|
||||
/** 创建导入任务并加载详情:统一处理上传进度与 loading 状态。成功返回 run 详情,失败返回 null */
|
||||
const uploadRun = async (
|
||||
file: File,
|
||||
options: {
|
||||
source: 'ai' | 'manual';
|
||||
conversationId?: number;
|
||||
stages?: ImportStageRequest[];
|
||||
mapping?: Record<string, Record<string, string>>;
|
||||
},
|
||||
errorMessage: string,
|
||||
): Promise<ImportRunDetail | null> => {
|
||||
setUploading(true);
|
||||
setUploadPercent(0);
|
||||
try {
|
||||
const detail = await createImportRun(file, {
|
||||
source: 'manual',
|
||||
...options,
|
||||
onProgress: (percent) => setUploadPercent(percent),
|
||||
});
|
||||
await loadRun(detail.id);
|
||||
message.success(`已识别 ${detail.sheets.length} 个工作表`);
|
||||
return detail;
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '文件上传失败');
|
||||
message.error(error instanceof Error ? error.message : errorMessage);
|
||||
return null;
|
||||
} finally {
|
||||
setUploading(false);
|
||||
setUploadPercent(0);
|
||||
}
|
||||
};
|
||||
|
||||
const handleUpload: UploadProps['customRequest'] = async (options) => {
|
||||
const file = options.file as File;
|
||||
const detail = await uploadRun(file, { source: 'manual' }, '文件上传失败');
|
||||
if (detail) message.success(`已识别 ${detail.sheets.length} 个工作表`);
|
||||
};
|
||||
|
||||
const handlePreview = async () => {
|
||||
if (!run || !activeStepKey || !activeStep) return;
|
||||
const mapping = mappingDraft[activeStepKey] ?? {};
|
||||
@@ -262,23 +279,16 @@ export const ImportWizardModal: React.FC<ImportWizardModalProps> = ({
|
||||
|
||||
const handleReupload = async (file: File) => {
|
||||
if (!run || !activeStepKey) return;
|
||||
setUploading(true);
|
||||
setUploadPercent(0);
|
||||
try {
|
||||
const detail = await createImportRun(file, {
|
||||
const detail = await uploadRun(
|
||||
file,
|
||||
{
|
||||
source: 'manual',
|
||||
stages: [{ stepKey: activeStepKey, sheets: sheetSelection[activeStepKey] ?? [] }],
|
||||
mapping: { [activeStepKey]: mappingDraft[activeStepKey] ?? {} },
|
||||
onProgress: (percent) => setUploadPercent(percent),
|
||||
});
|
||||
await loadRun(detail.id);
|
||||
message.success('已重新上传,并保留原列映射');
|
||||
} catch (error) {
|
||||
message.error(error instanceof Error ? error.message : '重新上传失败');
|
||||
} finally {
|
||||
setUploading(false);
|
||||
setUploadPercent(0);
|
||||
}
|
||||
},
|
||||
'重新上传失败',
|
||||
);
|
||||
if (detail) message.success('已重新上传,并保留原列映射');
|
||||
};
|
||||
|
||||
const previewRows = useMemo(() => {
|
||||
|
||||
Reference in New Issue
Block a user