mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 09:36:08 +08:00
ui: objective: add dropdown component
This commit is contained in:
3 files changed
+16
-6
No files matched your search
@@ -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;
|
||||
|
||||
@@ -40,7 +40,7 @@ export default function ProblemType() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
{Type === 'default' && (
|
||||
{['default', 'submit_answer'].includes(Type) && (
|
||||
<>
|
||||
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 3 }}>
|
||||
<div>{i18n('CheckerType')}</div>
|
||||
|
||||
@@ -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
|
||||
<textarea name="${id}" class="textbox objective-input"></textarea>
|
||||
</div>
|
||||
`));
|
||||
} else if (type === 'dropdown') {
|
||||
const opts = (options || '').split(',').map((s) => s.trim()).filter(Boolean);
|
||||
$(e).html($(e).html().replace(info, tpl`
|
||||
<div class="objective_${id} medium-3 select-container" id="p${id}" style="display: inline-block;">
|
||||
<select name="${id}" class="objective-input select">
|
||||
<option value=""></option>
|
||||
${{ templateRaw: true, html: opts.map((o) => tpl`<option value="${o}">${o}</option>`).join('') }}
|
||||
</select>
|
||||
</div>
|
||||
`));
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user