出题表单:修复 SQL 题崩溃并隐藏流程图区域

流程图区域的"AI 生成"按钮读取 problem.answers 里 language==='Python3' 的
第一项 .code,SQL 题(languages=["SQL"])没有 Python3 答案,[0] 为
undefined,导致模板抛 TypeError 崩溃整个出题页。

流程图功能本身依赖 Python 答案生成 Mermaid 代码,对 SQL 题没有意义,
和已隐藏的"代码规则检查"一样直接整块隐藏(切到 SQL 时顺带重置
allow_flowchart/show_flowchart,避免脏数据)。顺手给禁用态判断加了
可选链,修掉未选 Python3 时同样会崩的潜在问题(如仅选 C/C++ 的题目)。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-02 17:45:44 -06:00
parent c227c1d506
commit b4ac42b736

View File

@@ -202,6 +202,9 @@ watch(
if (problem.value.ast_rules) { if (problem.value.ast_rules) {
problem.value.ast_rules = null problem.value.ast_rules = null
} }
// 流程图依赖 Python 答案生成,对 SQL 没有意义
problem.value.allow_flowchart = false
problem.value.show_flowchart = false
} else if (problem.value.sql_config) { } else if (problem.value.sql_config) {
problem.value.sql_config = null problem.value.sql_config = null
} }
@@ -844,48 +847,50 @@ watch(
/> />
</n-modal> </n-modal>
<n-divider /> <template v-if="!isSQLProblem">
<n-divider />
<h2 class="title">流程图区域</h2> <h2 class="title">流程图区域</h2>
<!-- 流程图相关设置 --> <!-- 流程图相关设置 -->
<n-form inline label-placement="left" :show-feedback="false"> <n-form inline label-placement="left" :show-feedback="false">
<n-form-item label="根据上面的【Python答案】智能生成 Mermaid 代码"> <n-form-item label="根据上面的【Python答案】智能生成 Mermaid 代码">
<n-button <n-button
type="primary" type="primary"
size="small" size="small"
:disabled=" :disabled="
!problem.answers.filter((a) => a.language === 'Python3')[0].code !problem.answers.filter((a) => a.language === 'Python3')[0]?.code
.length .length
" "
:loading="isAIGenerating" :loading="isAIGenerating"
@click="generateMermaid" @click="generateMermaid"
> >
AI 生成 AI 生成
</n-button> </n-button>
</n-form-item> </n-form-item>
<n-form-item label="允许提交流程图"> <n-form-item label="允许提交流程图">
<n-switch v-model:value="problem.allow_flowchart" /> <n-switch v-model:value="problem.allow_flowchart" />
</n-form-item> </n-form-item>
<n-form-item label="显示标准流程图"> <n-form-item label="显示标准流程图">
<n-switch v-model:value="problem.show_flowchart" /> <n-switch v-model:value="problem.show_flowchart" />
</n-form-item> </n-form-item>
</n-form> </n-form>
<n-form> <n-form>
<n-form-item> <n-form-item>
<MermaidEditor <MermaidEditor
v-model="problem.mermaid_code" v-model="problem.mermaid_code"
@render-success="onMermaidRenderSuccess" @render-success="onMermaidRenderSuccess"
/> />
</n-form-item> </n-form-item>
<n-form-item label="流程图提示信息(选填)"> <n-form-item label="流程图提示信息(选填)">
<n-input <n-input
v-model:value="problem.flowchart_hint" v-model:value="problem.flowchart_hint"
placeholder="请输入流程图相关的提示信息,帮助学生理解题目要求" placeholder="请输入流程图相关的提示信息,帮助学生理解题目要求"
/> />
</n-form-item> </n-form-item>
</n-form> </n-form>
</template>
<n-flex style="margin-bottom: 120px" align="center" justify="end"> <n-flex style="margin-bottom: 120px" align="center" justify="end">
<n-button type="primary" @click="submit">提交</n-button> <n-button type="primary" @click="submit">提交</n-button>
</n-flex> </n-flex>