Commit b76008f4 by 李伟康

fix(template-import): 完善重新上传流程并移除冗余的校验层级列

修改handleReUpload逻辑,清空已选文件与校验结果,改为触发文件选择框让用户重新选择文件
移除失败详情卡片中的校验层级列及对应的标签UI
为UploadCard新增上传实例引用,实现编程式触发文件选择
1 parent 786e6861
Pipeline #339 for b76008f4 failed in 0 seconds
...@@ -13,7 +13,6 @@ const FAIL_COL_LABELS = [ ...@@ -13,7 +13,6 @@ const FAIL_COL_LABELS = [
{ key: 'rowIndex' as const, label: '行号', width: 92 }, { key: 'rowIndex' as const, label: '行号', width: 92 },
{ key: 'storeName' as const, label: '门店名称', width: 300 }, { key: 'storeName' as const, label: '门店名称', width: 300 },
{ key: 'merchantNo' as const, label: '门店商户号', width: 160 }, { key: 'merchantNo' as const, label: '门店商户号', width: 160 },
{ key: 'levelLabel' as const, label: '校验层级', width: 130 },
{ key: 'reason' as const, label: '失败原因', width: undefined }, { key: 'reason' as const, label: '失败原因', width: undefined },
] as const; ] as const;
...@@ -208,29 +207,6 @@ export function FailDetailCard({ checkResult, onReUpload }: FailDetailCardProps) ...@@ -208,29 +207,6 @@ export function FailDetailCard({ checkResult, onReUpload }: FailDetailCardProps)
> >
{f.merchantNo ?? '-'} {f.merchantNo ?? '-'}
</td> </td>
{/* 校验层级(浅黄 Tag,与截图 L4 业务级 一致) */}
<td
style={{
padding: '14px 8px',
borderBottom: '1px solid #F3F4F6',
whiteSpace: 'nowrap',
}}
>
<UTag
color="default"
bordered={false}
style={{
background: '#FEF3C7',
color: '#92400E',
padding: '3px 10px',
borderRadius: 6,
fontSize: 13,
lineHeight: 1.4,
}}
>
{f.levelLabel ?? `L${f.levelCode ?? '?'} 校验级`}
</UTag>
</td>
{/* 失败原因(红 #991B1B) */} {/* 失败原因(红 #991B1B) */}
<td <td
style={{ style={{
......
import { useState, useCallback, useEffect } from 'react'; import { useState, useCallback, useEffect, useRef } from 'react';
import { App } from 'antd'; import { App } from 'antd';
import { import {
InfoCircleFilled, InfoCircleFilled,
...@@ -40,6 +40,10 @@ export function UploadCard({ ...@@ -40,6 +40,10 @@ export function UploadCard({
const [uploading, setUploading] = useState(false); const [uploading, setUploading] = useState(false);
const [downloading, setDownloading] = useState(false); const [downloading, setDownloading] = useState(false);
const [fileList, setFileList] = useState<UploadFile[]>([]); const [fileList, setFileList] = useState<UploadFile[]>([]);
// antd Upload 实例,用于编程式打开文件选择框
const uploadRef = useRef<any>(null);
// 记录上一次已处理的 reUploadTrigger,防止 effect 因其它依赖变化而重复触发
const processedTriggerRef = useRef(0);
/** 从 checkResult + 文件名推导要显示的统计文案:共 N 行(X 家门店 × Y 场景 × Z 分类)· 模板版本 vX.X.X */ /** 从 checkResult + 文件名推导要显示的统计文案:共 N 行(X 家门店 × Y 场景 × Z 分类)· 模板版本 vX.X.X */
const statLineText = (() => { const statLineText = (() => {
...@@ -100,18 +104,6 @@ export function UploadCard({ ...@@ -100,18 +104,6 @@ export function UploadCard({
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [file]); }, [file]);
/**
* Step 2 → 点击失败明细里的【重新上传】:
* 父组件 handleReUpload = 切 Step0 + 清空 checkResult + reUploadCounter++
* 本 useEffect 监听 reUploadTrigger(>0 表示被触发过)+ 有 file + 非 uploading → 自动 runUpload
*/
useEffect(() => {
if (reUploadTrigger > 0 && file && !uploading) {
void runUpload(file);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [reUploadTrigger]);
const clearFileState = useCallback(() => { const clearFileState = useCallback(() => {
setFileList([]); setFileList([]);
onFileChange?.(null); onFileChange?.(null);
...@@ -191,6 +183,38 @@ export function UploadCard({ ...@@ -191,6 +183,38 @@ export function UploadCard({
fileList, fileList,
}; };
/**
* Step 2 → 点击失败明细里的【重新上传】:
* 父组件 handleReUpload = 切 Step0 + 清空 checkResult + reUploadCounter++
* 本 effect 监听 reUploadTrigger 变化,清空已选文件并编程式打开文件选择对话框,
* 让用户重新选择文件(选完文件后走正常 customRequest → runUpload → check 接口链路)。
* 注意:不再自动用原文件调用 check 接口,必须由用户重新选文件。
*/
useEffect(() => {
if (reUploadTrigger <= 0) return;
if (reUploadTrigger === processedTriggerRef.current) return;
processedTriggerRef.current = reUploadTrigger;
// 清空文件状态
setFileList([]);
onFileChange?.(null);
// 等 DOM 更新后再打开文件选择框:兼容 antd Upload ref 可能不暴露 upload() 的情况,
// 优先用 ref.upload(),兜底通过 DOM 查找隐藏的 input[type=file] 触发 click
setTimeout(() => {
const inst = uploadRef.current;
if (inst && typeof inst.upload === 'function') {
inst.upload();
return;
}
const input = document.querySelector<HTMLInputElement>(
'.uj-upload-dragger input[type="file"], .ant-upload input[type="file"]',
);
if (input) {
input.value = '';
input.click();
}
}, 0);
}, [reUploadTrigger, onFileChange]);
return ( return (
<UCard <UCard
styles={{ body: { padding: 20 } }} styles={{ body: { padding: 20 } }}
...@@ -209,7 +233,7 @@ export function UploadCard({ ...@@ -209,7 +233,7 @@ export function UploadCard({
} }
> >
<div style={{ position: 'relative' }}> <div style={{ position: 'relative' }}>
<UUpload.Dragger {...uploadProps}> <UUpload.Dragger ref={uploadRef} {...uploadProps}>
<div style={{ padding: '30px 0' }}> <div style={{ padding: '30px 0' }}>
<div <div
style={{ style={{
......
...@@ -76,7 +76,9 @@ export default function TemplateImport() { ...@@ -76,7 +76,9 @@ export default function TemplateImport() {
}; };
const handleReUpload = () => { const handleReUpload = () => {
// Step 2 重新上传:不清空文件,回到 Step0 后由 UploadCard.useEffect 监听 trigger 自动重跑上传 // Step 2 重新上传:清空文件 + checkResult,回到 Step0 后由 UploadCard 打开文件选择对话框,
// 用户重新选择文件后走正常 customRequest → runUpload → check 接口链路
setSelectedFile(null);
setCheckResult(null); setCheckResult(null);
setSubmitChecked(true); setSubmitChecked(true);
setCurrentStep(0); setCurrentStep(0);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!