feat: 管理端 SQL 题隐藏输入输出描述与样例表单

- 隐藏 SQL 题的输入/输出描述编辑器
- 隐藏 SQL 题的样例编辑区域
- 跳过 SQL 题的输入输出和样例验证
- SQL 题提交时清空样例数组

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-03 01:31:08 -06:00
parent aa212427ba
commit 0b627b5157

View File

@@ -344,19 +344,20 @@ async function validateProblem() {
// 题目 // 题目
else if ( else if (
!problem.value.description || !problem.value.description ||
!problem.value.input_description || (!isSQLProblem.value &&
!problem.value.output_description (!problem.value.input_description || !problem.value.output_description))
) { ) {
message.error("题目或输入或输出没有填写") message.error("题目或输入或输出没有填写")
hasErrors = true hasErrors = true
} }
// 样例 // 样例
else if (problem.value.samples.length == 0) { else if (!isSQLProblem.value && problem.value.samples.length == 0) {
message.error("样例没有填写") message.error("样例没有填写")
hasErrors = true hasErrors = true
} }
// 样例是空的 // 样例是空的
else if ( else if (
!isSQLProblem.value &&
problem.value.samples.some( problem.value.samples.some(
(sample) => sample.output === "" || sample.input === "", (sample) => sample.output === "" || sample.input === "",
) )
@@ -432,12 +433,18 @@ function filterAnswers() {
) )
} }
function filterSamplesForSQL() {
// SQL 题不展示样例;后端 CreateSampleSerializer 也不接受空字符串样例
if (isSQLProblem.value) problem.value.samples = []
}
async function submit() { async function submit() {
const hasValidationErrors = await validateProblem() const hasValidationErrors = await validateProblem()
if (hasValidationErrors) return if (hasValidationErrors) return
filterHint() filterHint()
getTemplate() getTemplate()
filterAnswers() filterAnswers()
filterSamplesForSQL()
syncProblemTags() syncProblemTags()
const api = { const api = {
"admin problem create": createProblem, "admin problem create": createProblem,
@@ -592,15 +599,16 @@ watch(
:min-height="300" :min-height="300"
/> />
<TextEditor <TextEditor
v-if="ready" v-if="ready && !isSQLProblem"
v-model:value="problem.input_description" v-model:value="problem.input_description"
title="输入的描述" title="输入的描述"
/> />
<TextEditor <TextEditor
v-if="ready" v-if="ready && !isSQLProblem"
v-model:value="problem.output_description" v-model:value="problem.output_description"
title="输出的描述" title="输出的描述"
/> />
<template v-if="!isSQLProblem">
<div class="box" v-for="(sample, index) in problem.samples" :key="index"> <div class="box" v-for="(sample, index) in problem.samples" :key="index">
<n-flex justify="space-between" align="center"> <n-flex justify="space-between" align="center">
<strong>测试样例 {{ index + 1 }}</strong> <strong>测试样例 {{ index + 1 }}</strong>
@@ -631,6 +639,7 @@ watch(
<n-button class="addSamples box" tertiary type="primary" @click="addSample"> <n-button class="addSamples box" tertiary type="primary" @click="addSample">
添加用例 添加用例
</n-button> </n-button>
</template>
<TextEditor v-if="ready" v-model:value="problem.hint" title="提示(选填)" /> <TextEditor v-if="ready" v-model:value="problem.hint" title="提示(选填)" />
<n-form> <n-form>
<n-form-item label="题目的来源(选填)"> <n-form-item label="题目的来源(选填)">