This commit is contained in:
2024-01-24 21:50:02 +08:00
parent b58d4c881b
commit 0c403f1e10
9 changed files with 376 additions and 738 deletions

View File

@@ -14,7 +14,8 @@ export default defineConfig({
},
},
head: [
['link', { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
["link", { rel: "icon", type: "image/x-icon", href: "/favicon.ico" }],
["link", { rel: "stylesheet", href: "/style.css" }],
],
themeConfig: {
// https://vitepress.dev/reference/default-theme-config

View File

@@ -2,9 +2,10 @@
import { computed, ref} from "vue"
import { useData } from "vitepress"
import { VPButton } from "vitepress/theme"
import CodeMirror from "vue-codemirror6"
import Codemirror from "vue-codemirror6"
import { cpp } from "@codemirror/lang-cpp"
import { python } from "@codemirror/lang-python"
import { indentUnit } from '@codemirror/language'
import { EditorView } from "@codemirror/view"
import { createSubmission } from "../judge"
import { smoothy } from "../cm-themes/smoothy"
@@ -32,20 +33,23 @@ const lang = computed(() => {
const styleTheme = EditorView.baseTheme({
"& .cm-scroller": {
"font-family": "Consolas",
"font-family": "Monaco",
},
"&.cm-editor.cm-focused": {
outline: "none",
},
"&.cm-editor .cm-tooltip.cm-tooltip-autocomplete ul": {
"font-family": "Monaco",
},
})
const code = ref(props.code.trim())
const input = ref("")
const output = ref("")
const code = ref(props.code.trim())
async function run() {
const result = await createSubmission(
{ value: code.value, language: props.lang === "python" ? "Python3" : "C" },
{ value: code.value, language: props.lang },
input.value,
)
output.value = result.output
@@ -58,19 +62,22 @@ function reset() {
</script>
<template>
<ClientOnly>
<p>代码编辑</p>
<CodeMirror
<p>代码区</p>
<Codemirror
v-model="code"
:lang="lang"
:tab-size="4"
:readonly="props.readonly"
:extensions="[styleTheme, isDark ? oneDark : smoothy]"
wrap
basic
tab
:tab-size="4"
:readonly="props.readonly"
:extensions="[styleTheme, isDark ? oneDark : smoothy, indentUnit.of(' ')]"
/>
<p>输入框</p>
<CodeMirror v-model="input" :extensions="[styleTheme]" />
<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>

View File

@@ -9,6 +9,6 @@ export default {
async enhanceApp({ app }) {
app.component("bvideo", BVideo)
app.component("author", Author)
app.component("code-editor", CodeEditor)
app.component("editor", CodeEditor)
},
} satisfies Theme

View File

@@ -1,12 +1,12 @@
import axios from "axios"
interface Code {
language: "C" | "Python3"
language: "c" | "python"
value: string
}
const DEAD_RESULTS = {
C: {
c: {
encoded:
"I2luY2x1ZGU8c3RkaW8uaD4NCg0KaW50IG1haW4oKQ0Kew0KICAgIHByaW50Zigi6buE5bKp5LiA6IGMIik7DQogICAgcmV0dXJuIDA7DQp9",
result: {
@@ -14,50 +14,13 @@ const DEAD_RESULTS = {
output: "黄岩一职",
},
},
"C++": {
encoded:
"I2luY2x1ZGU8aW9zdHJlYW0+DQoNCnVzaW5nIG5hbWVzcGFjZSBzdGQ7DQoNCmludCBtYWluKCkNCnsNCiAgICBjb3V0PDwi6buE5bKp5LiA6IGMIjw8ZW5kbDsNCiAgICByZXR1cm4gMDsNCn0=",
result: {
status: 3,
output: "黄岩一职",
},
},
Java: {
encoded:
"cHVibGljIGNsYXNzIE1haW4gew0KICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsNCiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCLpu4TlsqnkuIDogYwiKTsNCiAgICB9DQp9",
result: {
status: 3,
output: "黄岩一职",
},
},
Python3: {
python: {
encoded: "cHJpbnQoIum7hOWyqeS4gOiBjCIp",
result: {
status: 3,
output: "黄岩一职",
},
},
Python2: {
encoded: "",
result: {
status: 3,
output: "黄岩一职",
},
},
Golang: {
encoded: "",
result: {
status: 3,
output: "黄岩一职",
},
},
JavaScript: {
encoded: "",
result: {
status: 3,
output: "黄岩一职",
},
},
}
function getChromeVersion() {
@@ -91,13 +54,8 @@ export async function createSubmission(code: Code, input: string) {
return DEAD_RESULTS[code.language].result
} else {
const id = {
C: 50,
"C++": 54,
Java: 62,
Golang: 60,
JavaScript: 63,
Python2: 70,
Python3: 71,
c: 50,
python: 71,
}[code.language]
let compilerOptions = ""
if (id === 50) compilerOptions = "-lm" // 解决 GCC 的链接问题

BIN
docs/public/Monaco.ttf Normal file

Binary file not shown.

4
docs/public/style.css Normal file
View File

@@ -0,0 +1,4 @@
@font-face {
font-family: "Monaco";
src: url(/Monaco.ttf);
}

View File

@@ -3,13 +3,11 @@
本站是用于
<script lang="ts" setup>
const code = `
n = input()
print(n*3)
if n == "3":
print("哈哈哈")
`
print()
x = 1
if x == 1:
print("hahh")`
</script>
<code-editor :code="code"></code-editor>
<editor :code="code" />

1000
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,7 @@
"main": "index.js",
"type": "module",
"scripts": {
"dev": "vitepress dev docs",
"start": "vitepress dev docs",
"build": "vitepress build docs",
"preview": "vitepress preview docs"
},
@@ -13,14 +13,14 @@
"author": "",
"license": "ISC",
"devDependencies": {
"prettier": "^3.1.1",
"vitepress": "1.0.0-rc.32"
"prettier": "^3.2.4",
"vitepress": "1.0.0-rc.40"
},
"dependencies": {
"@codemirror/lang-cpp": "^6.0.2",
"@codemirror/lang-python": "^6.1.3",
"axios": "^1.6.2",
"axios": "^1.6.5",
"codemirror": "^6.0.1",
"vue-codemirror6": "^1.1.32"
"vue-codemirror6": "~1.1.32"
}
}