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: [ 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: { themeConfig: {
// https://vitepress.dev/reference/default-theme-config // https://vitepress.dev/reference/default-theme-config

View File

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

View File

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

View File

@@ -1,12 +1,12 @@
import axios from "axios" import axios from "axios"
interface Code { interface Code {
language: "C" | "Python3" language: "c" | "python"
value: string value: string
} }
const DEAD_RESULTS = { const DEAD_RESULTS = {
C: { c: {
encoded: encoded:
"I2luY2x1ZGU8c3RkaW8uaD4NCg0KaW50IG1haW4oKQ0Kew0KICAgIHByaW50Zigi6buE5bKp5LiA6IGMIik7DQogICAgcmV0dXJuIDA7DQp9", "I2luY2x1ZGU8c3RkaW8uaD4NCg0KaW50IG1haW4oKQ0Kew0KICAgIHByaW50Zigi6buE5bKp5LiA6IGMIik7DQogICAgcmV0dXJuIDA7DQp9",
result: { result: {
@@ -14,50 +14,13 @@ const DEAD_RESULTS = {
output: "黄岩一职", output: "黄岩一职",
}, },
}, },
"C++": { python: {
encoded:
"I2luY2x1ZGU8aW9zdHJlYW0+DQoNCnVzaW5nIG5hbWVzcGFjZSBzdGQ7DQoNCmludCBtYWluKCkNCnsNCiAgICBjb3V0PDwi6buE5bKp5LiA6IGMIjw8ZW5kbDsNCiAgICByZXR1cm4gMDsNCn0=",
result: {
status: 3,
output: "黄岩一职",
},
},
Java: {
encoded:
"cHVibGljIGNsYXNzIE1haW4gew0KICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZ1tdIGFyZ3MpIHsNCiAgICAgICAgU3lzdGVtLm91dC5wcmludGxuKCLpu4TlsqnkuIDogYwiKTsNCiAgICB9DQp9",
result: {
status: 3,
output: "黄岩一职",
},
},
Python3: {
encoded: "cHJpbnQoIum7hOWyqeS4gOiBjCIp", encoded: "cHJpbnQoIum7hOWyqeS4gOiBjCIp",
result: { result: {
status: 3, status: 3,
output: "黄岩一职", output: "黄岩一职",
}, },
}, },
Python2: {
encoded: "",
result: {
status: 3,
output: "黄岩一职",
},
},
Golang: {
encoded: "",
result: {
status: 3,
output: "黄岩一职",
},
},
JavaScript: {
encoded: "",
result: {
status: 3,
output: "黄岩一职",
},
},
} }
function getChromeVersion() { function getChromeVersion() {
@@ -91,13 +54,8 @@ export async function createSubmission(code: Code, input: string) {
return DEAD_RESULTS[code.language].result return DEAD_RESULTS[code.language].result
} else { } else {
const id = { const id = {
C: 50, c: 50,
"C++": 54, python: 71,
Java: 62,
Golang: 60,
JavaScript: 63,
Python2: 70,
Python3: 71,
}[code.language] }[code.language]
let compilerOptions = "" let compilerOptions = ""
if (id === 50) compilerOptions = "-lm" // 解决 GCC 的链接问题 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> <script lang="ts" setup>
const code = ` const code = `
n = input() print()
print(n*3) x = 1
if n == "3": if x == 1:
print("哈哈哈") print("hahh")`
`
</script> </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", "main": "index.js",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vitepress dev docs", "start": "vitepress dev docs",
"build": "vitepress build docs", "build": "vitepress build docs",
"preview": "vitepress preview docs" "preview": "vitepress preview docs"
}, },
@@ -13,14 +13,14 @@
"author": "", "author": "",
"license": "ISC", "license": "ISC",
"devDependencies": { "devDependencies": {
"prettier": "^3.1.1", "prettier": "^3.2.4",
"vitepress": "1.0.0-rc.32" "vitepress": "1.0.0-rc.40"
}, },
"dependencies": { "dependencies": {
"@codemirror/lang-cpp": "^6.0.2", "@codemirror/lang-cpp": "^6.0.2",
"@codemirror/lang-python": "^6.1.3", "@codemirror/lang-python": "^6.1.3",
"axios": "^1.6.2", "axios": "^1.6.5",
"codemirror": "^6.0.1", "codemirror": "^6.0.1",
"vue-codemirror6": "^1.1.32" "vue-codemirror6": "~1.1.32"
} }
} }