From 874a6fbe90c91b2c8c9ce70bfa18a8ad4babb084 Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Tue, 19 May 2026 04:22:23 -0600 Subject: [PATCH] feat: pre-populate generator with problem samples on open --- src/admin/problem/components/TestcaseGenerator.vue | 13 ++++++++++--- src/admin/problem/detail.vue | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/admin/problem/components/TestcaseGenerator.vue b/src/admin/problem/components/TestcaseGenerator.vue index 2d556cd..3893b4e 100644 --- a/src/admin/problem/components/TestcaseGenerator.vue +++ b/src/admin/problem/components/TestcaseGenerator.vue @@ -13,6 +13,7 @@ interface FileEntry { interface Props { answers: { language: LANGUAGE; code: string }[] + samples?: { input: string; output: string }[] } const props = defineProps() @@ -23,9 +24,15 @@ const emit = defineEmits<{ const message = useMessage() let nextId = 0 -const files = ref( - Array.from({ length: 5 }, () => ({ id: nextId++, in: "", out: "", error: false })), -) + +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 files = ref(makeInitialFiles()) const selectedLanguage = ref("Python3") diff --git a/src/admin/problem/detail.vue b/src/admin/problem/detail.vue index 6ba0b4f..cb2499e 100644 --- a/src/admin/problem/detail.vue +++ b/src/admin/problem/detail.vue @@ -706,6 +706,7 @@ watch( >