diff --git a/frontend/src/views/Exercise/ExerciseDetail.vue b/frontend/src/views/Exercise/ExerciseDetail.vue index 2da13ea..f1957f6 100644 --- a/frontend/src/views/Exercise/ExerciseDetail.vue +++ b/frontend/src/views/Exercise/ExerciseDetail.vue @@ -12,7 +12,7 @@
{{ exercise.description }}
- +示例 {{ i + 1 }}:
输入:{{ tc.input }}
@@ -54,7 +54,7 @@
-
+
{
}
})
-watch(selectedLanguage, (lang) => {
- code.value = exercise.value.initialCode?.[lang] || DEFAULT_TEMPLATES[lang] || ''
+watch(selectedLanguage, (lang, oldLang) => {
+ saveDraft(oldLang, code.value)
+ skipNextCodeSave.value = true
+ code.value = loadDraft(lang) ?? loadInitialCode(lang)
runResult.value = null
submitResult.value = null
activeResultType.value = null
resultTab.value = 'cases'
})
+watch(code, (value) => {
+ if (skipNextCodeSave.value) {
+ skipNextCodeSave.value = false
+ return
+ }
+ saveDraft(selectedLanguage.value, value)
+})
+
const monacoLanguage = computed(() =>
({ 'c++': 'cpp', 'c': 'c', 'python': 'python' }[selectedLanguage.value] || 'cpp')
)