From bc13976a7833addfe14be0332bc679227988c5c7 Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Mon, 6 Oct 2025 11:56:25 +0800 Subject: [PATCH] fix editor --- .../{EditorWithTest.vue => EditorForTest.vue} | 76 ++++++++--- src/oj/problem/components/Form.vue | 129 +++++++----------- src/oj/problem/detail.vue | 6 +- 3 files changed, 112 insertions(+), 99 deletions(-) rename src/oj/problem/components/{EditorWithTest.vue => EditorForTest.vue} (55%) diff --git a/src/oj/problem/components/EditorWithTest.vue b/src/oj/problem/components/EditorForTest.vue similarity index 55% rename from src/oj/problem/components/EditorWithTest.vue rename to src/oj/problem/components/EditorForTest.vue index 4a2f6a4..bb99cff 100644 --- a/src/oj/problem/components/EditorWithTest.vue +++ b/src/oj/problem/components/EditorForTest.vue @@ -3,10 +3,13 @@ import { code, input, output } from "oj/composables/code" import { problem } from "oj/composables/problem" import { SOURCES } from "utils/constants" import CodeEditor from "shared/components/CodeEditor.vue" -import { isDesktop } from "shared/composables/breakpoints" import storage from "utils/storage" -import Form from "./Form.vue" +import { createTestSubmission } from "utils/judge" +import { LANGUAGE_SHOW_VALUE } from "utils/constants" +import type { DropdownOption } from "naive-ui" +import { copyToClipboard } from "utils/functions" +const message = useMessage() const route = useRoute() const contestID = !!route.params.contestID ? route.params.contestID : null @@ -24,10 +27,6 @@ onMounted(() => { } }) -const editorHeight = computed(() => - isDesktop.value ? "calc(100vh - 133px)" : "calc(100vh - 172px)", -) - function changeCode(v: string) { storage.set(storageKey.value, v) } @@ -43,23 +42,64 @@ function changeLanguage(v: string) { problem.value!.template[code.language] || SOURCES[code.language] } } + +const copy = async () => { + const success = await copyToClipboard(code.value) + message[success ? "success" : "error"](`代码复制${success ? "成功" : "失败"}`) +} + +const reset = () => { + code.value = problem.value!.template[code.language] || SOURCES[code.language] + storage.remove(storageKey.value) + message.success("代码重置成功") +} + +const runCode = async () => { + const res = await createTestSubmission(code, input.value) + output.value = res.output +} + +const languageOptions: DropdownOption[] = problem.value!.languages.map( + (it) => ({ + label: () => + h("div", { style: "display: flex; align-items: center;" }, [ + h("img", { + src: `/${it}.svg`, + style: { width: "16px", height: "16px", marginRight: "8px" }, + }), + LANGUAGE_SHOW_VALUE[it], + ]), + value: it, + }), +)