fix judge.
This commit is contained in:
@@ -1,24 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue"
|
||||
import { useData } from "vitepress"
|
||||
import { Codemirror } from "vue-codemirror"
|
||||
import { VPButton } from "vitepress/theme"
|
||||
import CodeMirror from "vue-codemirror6"
|
||||
import { cpp } from "@codemirror/lang-cpp"
|
||||
import { python } from "@codemirror/lang-python"
|
||||
import { EditorView } from "@codemirror/view"
|
||||
import { VPButton } from "vitepress/theme"
|
||||
import { oneDark } from "../codemirror/oneDark"
|
||||
import { smoothy } from "../codemirror/smoothy"
|
||||
import { asyncRun } from "./py"
|
||||
import { createSubmission } from "../../api"
|
||||
import { smoothy } from "../cm-themes/smoothy"
|
||||
import { oneDark } from "../cm-themes/oneDark"
|
||||
|
||||
interface Props {
|
||||
modelValue: string
|
||||
readonly: boolean
|
||||
code: string
|
||||
readonly?: boolean
|
||||
lang?: "python" | "c"
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
lang: "python",
|
||||
readonly: false
|
||||
readonly: false,
|
||||
})
|
||||
|
||||
const { isDark } = useData()
|
||||
@@ -40,45 +40,44 @@ const styleTheme = EditorView.baseTheme({
|
||||
})
|
||||
|
||||
const input = ref("")
|
||||
const output = ref<string[]>([])
|
||||
const error = ref("")
|
||||
const code = ref(props.modelValue.trim())
|
||||
const output = ref("")
|
||||
const code = ref(props.code.trim())
|
||||
|
||||
async function run() {
|
||||
const ev = await asyncRun(code.value, input.value)
|
||||
output.value = ev.results
|
||||
error.value = ev.error
|
||||
const result = await createSubmission(
|
||||
{ value: code.value, language: props.lang === "python" ? "Python3" : "C" },
|
||||
input.value,
|
||||
)
|
||||
output.value = result.output
|
||||
}
|
||||
|
||||
function reset() {
|
||||
code.value = props.modelValue.trim()
|
||||
error.value = ""
|
||||
output.value = []
|
||||
code.value = props.code.trim()
|
||||
output.value = ""
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<p>代码编辑区</p>
|
||||
<Codemirror
|
||||
:disabled="props.readonly"
|
||||
v-model="code"
|
||||
indentWithTab
|
||||
:extensions="[styleTheme, lang, isDark ? oneDark : smoothy]"
|
||||
:tabSize="4"
|
||||
/>
|
||||
<p>输入框</p>
|
||||
<Codemirror
|
||||
v-model="input"
|
||||
indentWithTab
|
||||
:extensions="[styleTheme, isDark ? oneDark : smoothy]"
|
||||
:tabSize="4"
|
||||
/>
|
||||
<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 || error">运行结果</p>
|
||||
<pre v-for="(it, index) in output" :key="index">{{ it }}</pre>
|
||||
<pre>{{ error }}</pre>
|
||||
<ClientOnly>
|
||||
<p>代码编辑区</p>
|
||||
<CodeMirror
|
||||
v-model="code"
|
||||
:lang="lang"
|
||||
:tab-size="4"
|
||||
:readonly="props.readonly"
|
||||
:extensions="[styleTheme, isDark ? oneDark : smoothy]"
|
||||
wrap
|
||||
basic
|
||||
tab
|
||||
/>
|
||||
<p>输入框</p>
|
||||
<CodeMirror v-model="input" :extensions="[styleTheme]" />
|
||||
<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>{{ output }}</pre>
|
||||
</ClientOnly>
|
||||
</template>
|
||||
<style module>
|
||||
.actions {
|
||||
|
||||
Reference in New Issue
Block a user