testcat.
This commit is contained in:
@@ -5,6 +5,7 @@ import { problem } from "oj/composables/problem"
|
|||||||
import { isDesktop, isMobile } from "~/shared/composables/breakpoints"
|
import { isDesktop, isMobile } from "~/shared/composables/breakpoints"
|
||||||
import { useUserStore } from "~/shared/store/user"
|
import { useUserStore } from "~/shared/store/user"
|
||||||
import Submit from "./Submit.vue"
|
import Submit from "./Submit.vue"
|
||||||
|
import TestCat from "./TestCat.vue"
|
||||||
import storage from "~/utils/storage"
|
import storage from "~/utils/storage"
|
||||||
import { STORAGE_KEY } from "utils/constants"
|
import { STORAGE_KEY } from "utils/constants"
|
||||||
import { LANGUAGE } from "~/utils/types"
|
import { LANGUAGE } from "~/utils/types"
|
||||||
@@ -24,20 +25,14 @@ function goSubmissions() {
|
|||||||
router.push({ name, query: { problem: problem.value!._id } })
|
router.push({ name, query: { problem: problem.value!._id } })
|
||||||
}
|
}
|
||||||
|
|
||||||
function goTestCat() {
|
function goTestCat() {}
|
||||||
const data = router.resolve({ name: "play" })
|
|
||||||
window.open(data.href, "_blank")
|
|
||||||
}
|
|
||||||
|
|
||||||
function goEdit() {
|
function goEdit() {
|
||||||
const data = router.resolve("/admin/problem/edit/" + problem.value!.id)
|
const data = router.resolve("/admin/problem/edit/" + problem.value!.id)
|
||||||
window.open(data.href, "_blank")
|
window.open(data.href, "_blank")
|
||||||
}
|
}
|
||||||
|
|
||||||
const menu: DropdownOption[] = [
|
const menu: DropdownOption[] = [{ label: "提交信息", key: "submissions" }]
|
||||||
{ label: "提交信息", key: "submissions" },
|
|
||||||
{ label: "自测猫", key: "testcat" },
|
|
||||||
]
|
|
||||||
|
|
||||||
const options: DropdownOption[] = problem.value!.languages.map((it) => ({
|
const options: DropdownOption[] = problem.value!.languages.map((it) => ({
|
||||||
label: () => [
|
label: () => [
|
||||||
@@ -60,9 +55,6 @@ function select(key: string) {
|
|||||||
case "submissions":
|
case "submissions":
|
||||||
goSubmissions()
|
goSubmissions()
|
||||||
break
|
break
|
||||||
case "testcat":
|
|
||||||
goTestCat()
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +65,7 @@ function changeLanguage(v: LANGUAGE) {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<n-space>
|
<n-space align="center">
|
||||||
<n-select
|
<n-select
|
||||||
class="language"
|
class="language"
|
||||||
v-model:value="code.language"
|
v-model:value="code.language"
|
||||||
@@ -99,17 +91,11 @@ function changeLanguage(v: LANGUAGE) {
|
|||||||
</template>
|
</template>
|
||||||
</n-button>
|
</n-button>
|
||||||
</n-dropdown>
|
</n-dropdown>
|
||||||
|
<n-button v-if="isDesktop" @click="goSubmissions">提交信息</n-button>
|
||||||
|
<TestCat />
|
||||||
<n-button
|
<n-button
|
||||||
:size="isDesktop ? 'medium' : 'small'"
|
|
||||||
v-if="isDesktop"
|
|
||||||
@click="goSubmissions"
|
|
||||||
>
|
|
||||||
提交信息
|
|
||||||
</n-button>
|
|
||||||
<n-button
|
|
||||||
type="warning"
|
|
||||||
:size="isDesktop ? 'medium' : 'small'"
|
|
||||||
v-if="isDesktop && userStore.isSuperAdmin"
|
v-if="isDesktop && userStore.isSuperAdmin"
|
||||||
|
type="warning"
|
||||||
@click="goEdit"
|
@click="goEdit"
|
||||||
>
|
>
|
||||||
编辑
|
编辑
|
||||||
|
|||||||
46
src/oj/problem/components/TestCat.vue
Normal file
46
src/oj/problem/components/TestCat.vue
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { code } from "oj/composables/code"
|
||||||
|
import { createTestSubmission } from "~/utils/judge"
|
||||||
|
|
||||||
|
const input = ref("")
|
||||||
|
const output = ref("")
|
||||||
|
|
||||||
|
async function test() {
|
||||||
|
output.value = "运行中..."
|
||||||
|
const res = await createTestSubmission(code, input.value)
|
||||||
|
output.value = res.output
|
||||||
|
}
|
||||||
|
function clear() {
|
||||||
|
const id = setTimeout(() => {
|
||||||
|
clearTimeout(id)
|
||||||
|
output.value = ""
|
||||||
|
}, 200)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<n-popover
|
||||||
|
trigger="click"
|
||||||
|
placement="bottom-end"
|
||||||
|
scrollable
|
||||||
|
:show-arrow="false"
|
||||||
|
style="max-height: 600px; max-width: 800px"
|
||||||
|
@clickoutside="clear"
|
||||||
|
>
|
||||||
|
<template #trigger>
|
||||||
|
<n-button>输入输出</n-button>
|
||||||
|
</template>
|
||||||
|
<n-space vertical>
|
||||||
|
<n-input type="textarea" v-model:value="input" />
|
||||||
|
<n-space justify="end">
|
||||||
|
<n-button @click="test">运行</n-button>
|
||||||
|
</n-space>
|
||||||
|
<div class="testcase">{{ output }}</div>
|
||||||
|
</n-space>
|
||||||
|
</n-popover>
|
||||||
|
</template>
|
||||||
|
<style scoped>
|
||||||
|
.testcase {
|
||||||
|
white-space: pre;
|
||||||
|
font-size: 16px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
<script lang="ts" setup>
|
|
||||||
import CodeEditor from "~/shared/CodeEditor.vue"
|
|
||||||
import { LANGUAGE_SHOW_VALUE } from "~/utils/constants"
|
|
||||||
import { LANGUAGE } from "~/utils/types"
|
|
||||||
const code = ref("")
|
|
||||||
const input = ref("输入信息")
|
|
||||||
const output = ref("运行结果")
|
|
||||||
const language = ref<LANGUAGE>("C")
|
|
||||||
|
|
||||||
const languages: LANGUAGE[] = ["C", "Python3"]
|
|
||||||
const options: DropdownOption[] = languages.map((it) => ({
|
|
||||||
label: () => [
|
|
||||||
h("img", {
|
|
||||||
src: `/${it}.svg`,
|
|
||||||
style: {
|
|
||||||
width: "16px",
|
|
||||||
height: "16px",
|
|
||||||
marginRight: "8px",
|
|
||||||
transform: "translateY(3px)",
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
LANGUAGE_SHOW_VALUE[it],
|
|
||||||
],
|
|
||||||
value: it,
|
|
||||||
}))
|
|
||||||
</script>
|
|
||||||
<template>
|
|
||||||
<n-layout>
|
|
||||||
<n-layout-header bordered class="header">
|
|
||||||
<n-space align="center" justify="space-between" class="header">
|
|
||||||
<div class="title">徐越的自测猫</div>
|
|
||||||
<n-space>
|
|
||||||
<n-select class="language" v-model="language" :options="options" />
|
|
||||||
<n-button type="primary">运行 F5</n-button>
|
|
||||||
</n-space>
|
|
||||||
</n-space>
|
|
||||||
</n-layout-header>
|
|
||||||
<n-layout-content>
|
|
||||||
<n-grid :cols="2" class="content">
|
|
||||||
<n-gi>
|
|
||||||
<CodeEditor v-model="code" :language="language" />
|
|
||||||
</n-gi>
|
|
||||||
<n-gi>
|
|
||||||
<n-grid :cols="1" class="content">
|
|
||||||
<n-gi>
|
|
||||||
<CodeEditor v-model="input" :language="language" />
|
|
||||||
</n-gi>
|
|
||||||
<n-gi>
|
|
||||||
<CodeEditor v-model="output" :language="language" readonly />
|
|
||||||
</n-gi>
|
|
||||||
</n-grid>
|
|
||||||
</n-gi>
|
|
||||||
</n-grid>
|
|
||||||
</n-layout-content>
|
|
||||||
</n-layout>
|
|
||||||
</template>
|
|
||||||
<style scoped>
|
|
||||||
.header {
|
|
||||||
height: 60px;
|
|
||||||
padding: 0 8px;
|
|
||||||
}
|
|
||||||
.title {
|
|
||||||
font-size: 18px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.content {
|
|
||||||
height: calc(100vh - 60px);
|
|
||||||
}
|
|
||||||
|
|
||||||
.language {
|
|
||||||
width: 120px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -92,11 +92,6 @@ export const routes: RouteRecordRaw[] = [
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: "/play",
|
|
||||||
component: () => import("~/play/index.vue"),
|
|
||||||
name: "play",
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "/admin",
|
path: "/admin",
|
||||||
component: () => import("~/shared/layout/admin.vue"),
|
component: () => import("~/shared/layout/admin.vue"),
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ interface Props {
|
|||||||
fontSize?: number
|
fontSize?: number
|
||||||
height?: string
|
height?: string
|
||||||
readonly?: boolean
|
readonly?: boolean
|
||||||
|
placeholder?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
@@ -30,6 +31,7 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
height: "100%",
|
height: "100%",
|
||||||
readonly: false,
|
readonly: false,
|
||||||
|
placeholder: "",
|
||||||
})
|
})
|
||||||
|
|
||||||
const code = ref(props.modelValue)
|
const code = ref(props.modelValue)
|
||||||
@@ -55,11 +57,12 @@ function onChange(v: string) {
|
|||||||
<template>
|
<template>
|
||||||
<Codemirror
|
<Codemirror
|
||||||
v-model="code"
|
v-model="code"
|
||||||
:extensions="[styleTheme, lang, isDark ? oneDark : smoothy]"
|
|
||||||
indentWithTab
|
indentWithTab
|
||||||
|
:extensions="[styleTheme, lang, isDark ? oneDark : smoothy]"
|
||||||
:disabled="props.readonly"
|
:disabled="props.readonly"
|
||||||
:tabSize="4"
|
:tabSize="4"
|
||||||
@change="onChange"
|
:placeholder="props.placeholder"
|
||||||
:style="{ height: props.height, fontSize: props.fontSize + 'px' }"
|
:style="{ height: props.height, fontSize: props.fontSize + 'px' }"
|
||||||
|
@change="onChange"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -59,15 +59,6 @@ const menus = computed<MenuOption[]>(() => [
|
|||||||
show: userStore.isAdminRole,
|
show: userStore.isAdminRole,
|
||||||
key: "admin",
|
key: "admin",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: () =>
|
|
||||||
h(
|
|
||||||
RouterLink,
|
|
||||||
{ to: "/play", target: "_blank" },
|
|
||||||
{ default: () => "自测" }
|
|
||||||
),
|
|
||||||
key: "play",
|
|
||||||
},
|
|
||||||
])
|
])
|
||||||
|
|
||||||
const options: Array<DropdownOption | DropdownDividerOption> = [
|
const options: Array<DropdownOption | DropdownDividerOption> = [
|
||||||
|
|||||||
Reference in New Issue
Block a user