fix(题目): 在题目页里直接换题(下一题、题号直达)后,例子和语言还停在上一道题
Deploy / deploy (push) Canceled after 0s

题目页换题是同一个组件复用、只换路由参数,几处只在创建时读一次的状态就停在了上一道题:

- 例子:新题下面摆着旧题的例子,「测试」也拿旧例子比对
- 语言:下拉选项不跟着变,也不回退——从 Python 题跳到 SQL 题,语言停在 Python,提交必被拒
- 比赛 / 题单的编辑器只在挂载时载入一次代码
- 流程图:分数按钮、评分弹框、「我的流程图」还是上一道题的,上一道题还没评完的那次会挂到新题上

语言回退挪进 problem store 的 supportedLanguage(),两个编辑器在载入草稿之前调用,
保证先定语言再读这门语言的草稿。没有用给整块加 key 强制重新挂载的办法:课堂协作的
绑定依赖组件复用,重挂载会让协作中切题的老师语言恢复不了。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xuyueandClaude Opus 5.5 committed 2026-09-28 09:15:50 +08:00
1 parent 71670e609b
commit 1b149a4f3f
7 files changed
+101 -32

No files matched your search

+10
View File
@@ -32,6 +32,15 @@ export const useProblemStore = defineStore("problem", () => {
return problem.value?.languages ?? []
})
/**
* 这道题收不收当前语言,不收就退到它支持的第一种(SQL 题只有 "SQL",硬编码的
* Python 会被后端拒绝)。编辑器每次载入代码之前都要过一遍:草稿的键里带着语言,
* 先载入再改语言,编辑器里摆的就是另一种语言的模板。
*/
function supportedLanguage(current: LANGUAGE): LANGUAGE {
return languages.value.includes(current) ? current : (languages.value[0] ?? "Python")
}
function incrementFailCount() {
sessionFailCount.value++
}
@@ -47,6 +56,7 @@ export const useProblemStore = defineStore("problem", () => {
problem,
failCount,
languages,
supportedLanguage,
incrementFailCount,
}
})