update
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref} from "vue"
|
||||
import { computed, ref } from "vue"
|
||||
import { useData } from "vitepress"
|
||||
import { VPButton } from "vitepress/theme"
|
||||
import Codemirror from "vue-codemirror6"
|
||||
import { cpp } from "@codemirror/lang-cpp"
|
||||
import { python } from "@codemirror/lang-python"
|
||||
import { indentUnit } from '@codemirror/language'
|
||||
import { indentUnit } from "@codemirror/language"
|
||||
import { EditorView } from "@codemirror/view"
|
||||
import { createSubmission } from "../judge"
|
||||
import { smoothy } from "../cm-themes/smoothy"
|
||||
@@ -34,6 +34,7 @@ const lang = computed(() => {
|
||||
const styleTheme = EditorView.baseTheme({
|
||||
"& .cm-scroller": {
|
||||
"font-family": "Monaco",
|
||||
border: "2px solid var(--vp-c-divider)",
|
||||
},
|
||||
"&.cm-editor.cm-focused": {
|
||||
outline: "none",
|
||||
@@ -48,6 +49,7 @@ const input = ref("")
|
||||
const output = ref("")
|
||||
|
||||
async function run() {
|
||||
output.value = ""
|
||||
const result = await createSubmission(
|
||||
{ value: code.value, language: props.lang },
|
||||
input.value,
|
||||
@@ -62,36 +64,52 @@ function reset() {
|
||||
</script>
|
||||
<template>
|
||||
<ClientOnly>
|
||||
<p>代码区</p>
|
||||
<Codemirror
|
||||
v-model="code"
|
||||
:lang="lang"
|
||||
basic
|
||||
tab
|
||||
:tab-size="4"
|
||||
:readonly="props.readonly"
|
||||
:extensions="[styleTheme, isDark ? oneDark : smoothy, indentUnit.of(' ')]"
|
||||
/>
|
||||
<p>输入框</p>
|
||||
<Codemirror
|
||||
v-model="input"
|
||||
basic
|
||||
:extensions="[styleTheme, isDark ? oneDark : smoothy]"
|
||||
/>
|
||||
<div :class="$style.actions">
|
||||
<VPButton :class="$style.run" @click="run" text="运行"></VPButton>
|
||||
<VPButton @click="reset" theme="alt" text="重置"></VPButton>
|
||||
<div :class="$style.container">
|
||||
<p :class="$style.title">代码区</p>
|
||||
<Codemirror
|
||||
v-model="code"
|
||||
:lang="lang"
|
||||
basic
|
||||
tab
|
||||
:tab-size="4"
|
||||
:readonly="props.readonly"
|
||||
:extensions="[
|
||||
styleTheme,
|
||||
isDark ? oneDark : smoothy,
|
||||
indentUnit.of(' '),
|
||||
]"
|
||||
/>
|
||||
<p :class="$style.title">输入框</p>
|
||||
<Codemirror
|
||||
v-model="input"
|
||||
minimal
|
||||
:extensions="[styleTheme, isDark ? oneDark : smoothy]"
|
||||
/>
|
||||
<div :class="$style.actions">
|
||||
<VPButton :class="$style.run" @click="run" text="运行"></VPButton>
|
||||
<VPButton @click="reset" theme="alt" text="重置"></VPButton>
|
||||
</div>
|
||||
<p v-if="output.length">运行结果</p>
|
||||
<pre :class="$style.output">{{ output }}</pre>
|
||||
</div>
|
||||
<p v-if="output.length">运行结果</p>
|
||||
<pre>{{ output }}</pre>
|
||||
</ClientOnly>
|
||||
</template>
|
||||
<style module>
|
||||
.container {
|
||||
background-color: var(--vp-code-block-bg);
|
||||
padding: 8px 16px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.title {
|
||||
font-weight: bold;
|
||||
}
|
||||
.actions {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.run {
|
||||
margin-right: 20px;
|
||||
}
|
||||
.output {
|
||||
font-family: Monaco;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user