fix slow zip progress display rounding
This commit is contained in:
@@ -99,11 +99,16 @@ const API_BASE = typeof window === 'undefined'
|
|||||||
function progressFromJob(job: BackendJob, fallback = 0) {
|
function progressFromJob(job: BackendJob, fallback = 0) {
|
||||||
if (job.status === 'completed') return 100;
|
if (job.status === 'completed') return 100;
|
||||||
if (typeof job.progress === 'number') {
|
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));
|
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 {
|
function readStoredDeformationJob(): StoredDeformationJob | null {
|
||||||
if (typeof window === 'undefined') return null;
|
if (typeof window === 'undefined') return null;
|
||||||
try {
|
try {
|
||||||
@@ -948,7 +953,7 @@ export default function App() {
|
|||||||
>
|
>
|
||||||
<Download size={14} />
|
<Download size={14} />
|
||||||
{zipJobs.all?.status === 'running'
|
{zipJobs.all?.status === 'running'
|
||||||
? `四状态 ZIP 打包中 ${progressFromJob(zipJobs.all, 0)}%`
|
? `四状态 ZIP 打包中 ${formatProgress(progressFromJob(zipJobs.all, 0))}%`
|
||||||
: '下载四状态 ZIP'}
|
: '下载四状态 ZIP'}
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
@@ -1057,7 +1062,7 @@ export default function App() {
|
|||||||
>
|
>
|
||||||
<Download size={13} />
|
<Download size={13} />
|
||||||
{zipJob?.status === 'running'
|
{zipJob?.status === 'running'
|
||||||
? `打包中 ${progressFromJob(zipJob, 0)}%`
|
? `打包中 ${formatProgress(progressFromJob(zipJob, 0))}%`
|
||||||
: '下载本状态 DICOM ZIP'}
|
: '下载本状态 DICOM ZIP'}
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user