From 01ffba8bb299b45368061cefb9073ab5b68dd6de Mon Sep 17 00:00:00 2001 From: undefined Date: Wed, 29 Apr 2026 03:07:48 +0800 Subject: [PATCH] ui: objective: add dropdown component --- packages/hydrooj/src/handler/problem.ts | 2 +- .../components/problemconfig/ProblemType.tsx | 2 +- .../ui-default/pages/problem_detail.page.tsx | 18 ++++++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/hydrooj/src/handler/problem.ts b/packages/hydrooj/src/handler/problem.ts index 6f247de37..e9d283d95 100644 --- a/packages/hydrooj/src/handler/problem.ts +++ b/packages/hydrooj/src/handler/problem.ts @@ -307,7 +307,7 @@ export class ProblemDetailHandler extends ContestDetailBaseHandler { if (contest.isNotStarted(this.tdoc)) throw new ContestNotLiveError(tid); if (!contest.isDone(this.tdoc, this.tsdoc) && (!this.tsdoc?.attend || !this.tsdoc.startAt)) throw new ContestNotAttendedError(tid); // Delete problem-related info in contest mode - this.pdoc.tag.length = 0; + if (this.pdoc.tag) this.pdoc.tag.length = 0; delete this.pdoc.nAccept; delete this.pdoc.nSubmit; delete this.pdoc.difficulty; diff --git a/packages/ui-default/components/problemconfig/ProblemType.tsx b/packages/ui-default/components/problemconfig/ProblemType.tsx index bbf69575d..cd53144a4 100644 --- a/packages/ui-default/components/problemconfig/ProblemType.tsx +++ b/packages/ui-default/components/problemconfig/ProblemType.tsx @@ -40,7 +40,7 @@ export default function ProblemType() { /> - {Type === 'default' && ( + {['default', 'submit_answer'].includes(Type) && ( <>
{i18n('CheckerType')}
diff --git a/packages/ui-default/pages/problem_detail.page.tsx b/packages/ui-default/pages/problem_detail.page.tsx index c08a03424..d1053e5b6 100644 --- a/packages/ui-default/pages/problem_detail.page.tsx +++ b/packages/ui-default/pages/problem_detail.page.tsx @@ -194,15 +194,15 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor const ans = {}; const pids = []; let cnt = 0; - const reg = /\{\{ (input|select|multiselect|textarea)\(\d+(-\d+)?\) \}\}/g; + const reg = /\{\{ (input|select|multiselect|textarea|dropdown)\(\d+(-\d+)?\)(?:\[([^\]]*)\])? \}\}/g; $('.problem-content .typo').children().each((i, e) => { if (e.tagName === 'PRE' && !e.children[0].className.includes('#input')) return; const questions = []; let q; while (q = reg.exec(e.textContent)) questions.push(q); // eslint-disable-line no-cond-assign - for (const [info, type] of questions) { + for (const [info, type, , options] of questions) { cnt++; - const id = info.replace(/\{\{ (input|select|multiselect|textarea)\((\d+(-\d+)?)\) \}\}/, '$2'); + const id = info.replace(/\{\{ (input|select|multiselect|textarea|dropdown)\((\d+(-\d+)?)\)(?:\[([^\]]*)\])? \}\}/, '$2'); pids.push(id); if (type === 'input') { $(e).html($(e).html().replace(info, tpl` @@ -216,6 +216,16 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
`)); + } else if (type === 'dropdown') { + const opts = (options || '').split(',').map((s) => s.trim()).filter(Boolean); + $(e).html($(e).html().replace(info, tpl` +
+ +
+ `)); } else { if ($(e).next()[0]?.tagName !== 'UL') { cnt--; @@ -288,7 +298,7 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor if (isValidOption(v)) $(`.objective_${id} input[value="${v}"]`).prop('checked', true); } } else if (val) { - $(`.objective_${id} input[type=text], .objective_${id} textarea`).val(val.toString()); + $(`.objective_${id} input[type=text], .objective_${id} textarea, .objective_${id} select`).val(val.toString()); if (isValidOption(val)) $(`.objective_${id}.radiobox [value="${val}"]`).prop('checked', true); } }