From e7e270b928ae35b0a7aa3483e6405ac8bdfd9b4b Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Tue, 19 May 2026 04:25:00 -0600 Subject: [PATCH] fix: ensure at least 5 rows in generator even when samples exist --- src/admin/problem/components/TestcaseGenerator.vue | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/admin/problem/components/TestcaseGenerator.vue b/src/admin/problem/components/TestcaseGenerator.vue index 3893b4e..544a8b6 100644 --- a/src/admin/problem/components/TestcaseGenerator.vue +++ b/src/admin/problem/components/TestcaseGenerator.vue @@ -26,10 +26,9 @@ const message = useMessage() let nextId = 0 function makeInitialFiles(): FileEntry[] { - if (props.samples?.length) { - return props.samples.map((s) => ({ id: nextId++, in: s.input, out: s.output, error: false })) - } - return Array.from({ length: 5 }, () => ({ id: nextId++, in: "", out: "", error: false })) + const fromSamples = (props.samples ?? []).map((s) => ({ id: nextId++, in: s.input, out: s.output, error: false })) + const extra = Math.max(0, 5 - fromSamples.length) + return [...fromSamples, ...Array.from({ length: extra }, () => ({ id: nextId++, in: "", out: "", error: false }))] } const files = ref(makeInitialFiles())