fix slow zip progress display rounding

This commit is contained in:
2026-05-03 02:38:37 +08:00
parent d46f320a74
commit 49b797e7dc

View File

@@ -99,11 +99,16 @@ const API_BASE = typeof window === 'undefined'
function progressFromJob(job: BackendJob, fallback = 0) {
if (job.status === 'completed') return 100;
if (typeof job.progress === 'number') {
return Math.max(0, Math.min(100, Math.round(job.progress)));
return Math.max(0, Math.min(100, job.progress));
}
return Math.max(0, Math.min(95, fallback));
}
function formatProgress(value: number) {
const bounded = Math.max(0, Math.min(100, value));
return Number.isInteger(bounded) ? `${bounded}` : bounded.toFixed(1);
}
function readStoredDeformationJob(): StoredDeformationJob | null {
if (typeof window === 'undefined') return null;
try {
@@ -948,7 +953,7 @@ export default function App() {
>
<Download size={14} />
{zipJobs.all?.status === 'running'
? `四状态 ZIP 打包中 ${progressFromJob(zipJobs.all, 0)}%`
? `四状态 ZIP 打包中 ${formatProgress(progressFromJob(zipJobs.all, 0))}%`
: '下载四状态 ZIP'}
</button>
)}
@@ -1057,7 +1062,7 @@ export default function App() {
>
<Download size={13} />
{zipJob?.status === 'running'
? `打包中 ${progressFromJob(zipJob, 0)}%`
? `打包中 ${formatProgress(progressFromJob(zipJob, 0))}%`
: '下载本状态 DICOM ZIP'}
</button>
)}