This commit is contained in:
2023-04-17 20:39:41 +08:00
parent 9274326ac5
commit d0a5de3720
2 changed files with 17 additions and 10 deletions

View File

@@ -13,7 +13,8 @@ const route = useRoute()
const contestID = !!route.params.contestID ? route.params.contestID : null
const storageKey = computed(
() => `problem_${problem.value!._id}_contest_${contestID}`
() =>
`problem_${problem.value!._id}_contest_${contestID}_lang_${code.language}`
)
onMounted(() => {
@@ -29,18 +30,26 @@ const editorHeight = computed(() =>
isDesktop.value ? "calc(100vh - 133px)" : "calc(100vh - 172px)"
)
function reset() {
storage.remove(storageKey.value)
}
function changeCode(v: string) {
storage.set(storageKey.value, v)
}
function changeLanguage(v: string) {
if (
storage.get(storageKey.value) &&
storageKey.value.split("_").pop() === v
) {
code.value = storage.get(storageKey.value)
} else {
code.value =
problem.value!.template[code.language] || SOURCES[code.language]
}
}
</script>
<template>
<n-space vertical>
<Form @reset="reset" />
<Form @change-language="changeLanguage" />
<CodeEditor
v-model="code.value"
@update:model-value="changeCode"