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,45 +599,47 @@ 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="输出的描述"
/> />
<div class="box" v-for="(sample, index) in problem.samples" :key="index"> <template v-if="!isSQLProblem">
<n-flex justify="space-between" align="center"> <div class="box" v-for="(sample, index) in problem.samples" :key="index">
<strong>测试样例 {{ index + 1 }}</strong> <n-flex justify="space-between" align="center">
<n-button <strong>测试样例 {{ index + 1 }}</strong>
tertiary <n-button
type="warning" tertiary
size="small" type="warning"
@click="removeSample(index)" size="small"
> @click="removeSample(index)"
删除 {{ index + 1 }} >
</n-button> 删除 {{ index + 1 }}
</n-flex> </n-button>
<n-grid x-gap="20" cols="2"> </n-flex>
<n-gi span="1"> <n-grid x-gap="20" cols="2">
<n-flex vertical> <n-gi span="1">
<span>输入样例</span> <n-flex vertical>
<n-input type="textarea" v-model:value="sample.input" /> <span>输入样例</span>
</n-flex> <n-input type="textarea" v-model:value="sample.input" />
</n-gi> </n-flex>
<n-gi span="1"> </n-gi>
<n-flex vertical> <n-gi span="1">
<span>输出样例</span> <n-flex vertical>
<n-input type="textarea" v-model:value="sample.output" /> <span>输出样例</span>
</n-flex> <n-input type="textarea" v-model:value="sample.output" />
</n-gi> </n-flex>
</n-grid> </n-gi>
</div> </n-grid>
<n-button class="addSamples box" tertiary type="primary" @click="addSample"> </div>
添加用例 <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="题目的来源(选填)">