update
This commit is contained in:
@@ -1,13 +1,18 @@
|
|||||||
import { reactive } from "vue"
|
import { computed, reactive } from "vue"
|
||||||
import { code, output } from "./code"
|
import { output, status } from "./code"
|
||||||
|
import { Status } from "../types"
|
||||||
|
|
||||||
export const analyse = reactive({
|
export const analyse = reactive({
|
||||||
line: -1,
|
line: -1,
|
||||||
message: "",
|
message: "",
|
||||||
})
|
})
|
||||||
|
|
||||||
function findError(line: string) {
|
export const showAnalyse = computed(
|
||||||
const regex: any = {
|
() => ![Status.Accepted, Status.NotStarted].includes(status.value),
|
||||||
|
)
|
||||||
|
|
||||||
|
function findError(line: string, language = "python") {
|
||||||
|
const python: any = {
|
||||||
"EOFError: EOF when reading a line": "需要在输入框填写输入信息",
|
"EOFError: EOF when reading a line": "需要在输入框填写输入信息",
|
||||||
"SyntaxError: invalid character in identifier":
|
"SyntaxError: invalid character in identifier":
|
||||||
"可能是单词拼写错误,可能是括号、引号写成中文的了",
|
"可能是单词拼写错误,可能是括号、引号写成中文的了",
|
||||||
@@ -18,6 +23,8 @@ function findError(line: string) {
|
|||||||
`命名错误,${name} 不知道是什么东西`,
|
`命名错误,${name} 不知道是什么东西`,
|
||||||
"IndentationError: expected an indented block": "缩进错误:这一行需要缩进",
|
"IndentationError: expected an indented block": "缩进错误:这一行需要缩进",
|
||||||
}
|
}
|
||||||
|
const c: any = {}
|
||||||
|
const regex = { c, python }[language]
|
||||||
let message = ""
|
let message = ""
|
||||||
for (let r in regex) {
|
for (let r in regex) {
|
||||||
const err = line.match(r)
|
const err = line.match(r)
|
||||||
@@ -33,8 +40,7 @@ function findError(line: string) {
|
|||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
|
|
||||||
export function showAnalyse() {
|
export function analyzeError() {
|
||||||
if (code.language === "python") {
|
|
||||||
const line = output.value.match(/File "script.py", line (\d+)/)
|
const line = output.value.match(/File "script.py", line (\d+)/)
|
||||||
if (line) {
|
if (line) {
|
||||||
analyse.line = parseInt(line[1])
|
analyse.line = parseInt(line[1])
|
||||||
@@ -43,7 +49,3 @@ export function showAnalyse() {
|
|||||||
const lastLine = lines[lines.length - 1]
|
const lastLine = lines[lines.length - 1]
|
||||||
analyse.message = findError(lastLine)
|
analyse.message = findError(lastLine)
|
||||||
}
|
}
|
||||||
if (code.language === "c") {
|
|
||||||
analyse.message = "C语言的正在制作中..."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { computed, reactive, ref, watch } from "vue"
|
import { reactive, ref, watch } from "vue"
|
||||||
import { Code, LANGUAGE, Cache, Status } from "../types"
|
import { Code, LANGUAGE, Cache, Status } from "../types"
|
||||||
import { sources } from "../templates"
|
import { sources } from "../templates"
|
||||||
import { submit } from "../api"
|
import { submit } from "../api"
|
||||||
@@ -22,13 +22,9 @@ export const code = reactive<Code>({
|
|||||||
})
|
})
|
||||||
export const input = ref(cache.input.value)
|
export const input = ref(cache.input.value)
|
||||||
export const output = ref("")
|
export const output = ref("")
|
||||||
|
export const status = ref(Status.NotStarted)
|
||||||
export const loading = ref(false)
|
export const loading = ref(false)
|
||||||
export const size = ref(24)
|
export const size = ref(24)
|
||||||
export const status = ref(Status.NotStarted)
|
|
||||||
|
|
||||||
export const showStatus = computed(
|
|
||||||
() => ![Status.Accepted, Status.NotStarted].includes(status.value),
|
|
||||||
)
|
|
||||||
|
|
||||||
watch(size, (value: number) => {
|
watch(size, (value: number) => {
|
||||||
cache.fontsize.value = value
|
cache.fontsize.value = value
|
||||||
|
|||||||
@@ -3,17 +3,18 @@ import copyTextToClipboard from "copy-text-to-clipboard"
|
|||||||
import {
|
import {
|
||||||
code,
|
code,
|
||||||
size,
|
size,
|
||||||
init,
|
|
||||||
input,
|
input,
|
||||||
output,
|
output,
|
||||||
|
status,
|
||||||
|
init,
|
||||||
reset,
|
reset,
|
||||||
clearInput,
|
clearInput,
|
||||||
showStatus,
|
|
||||||
} from "../composables/code"
|
} from "../composables/code"
|
||||||
import { showAnalyse, analyse } from "../composables/analyse"
|
import { showAnalyse, analyzeError, analyse } from "../composables/analyse"
|
||||||
import CodeEditor from "../components/CodeEditor.vue"
|
import CodeEditor from "../components/CodeEditor.vue"
|
||||||
import { computed, onMounted } from "vue"
|
import { computed, onMounted } from "vue"
|
||||||
import { useMessage } from "naive-ui"
|
import { useMessage } from "naive-ui"
|
||||||
|
import { Status } from "../types"
|
||||||
|
|
||||||
onMounted(init)
|
onMounted(init)
|
||||||
|
|
||||||
@@ -71,9 +72,16 @@ function copy() {
|
|||||||
:font-size="size"
|
:font-size="size"
|
||||||
>
|
>
|
||||||
<template #actions>
|
<template #actions>
|
||||||
<n-popover v-if="showStatus" trigger="click">
|
<n-tag v-if="status === Status.Accepted" type="success">
|
||||||
|
运行成功
|
||||||
|
</n-tag>
|
||||||
|
<n-tag v-if="showAnalyse" type="warning">运行失败</n-tag>
|
||||||
|
<n-popover
|
||||||
|
v-if="showAnalyse && code.language === 'python'"
|
||||||
|
trigger="click"
|
||||||
|
>
|
||||||
<template #trigger>
|
<template #trigger>
|
||||||
<n-button quaternary type="error" @click="showAnalyse">
|
<n-button quaternary type="error" @click="analyzeError">
|
||||||
推测原因
|
推测原因
|
||||||
</n-button>
|
</n-button>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ const languages: SelectOption[] = [
|
|||||||
<Play />
|
<Play />
|
||||||
</n-icon>
|
</n-icon>
|
||||||
</template>
|
</template>
|
||||||
运行 (F5)
|
运行
|
||||||
</n-button>
|
</n-button>
|
||||||
</n-flex>
|
</n-flex>
|
||||||
</n-flex>
|
</n-flex>
|
||||||
|
|||||||
24
src/desktop/TestPanel.vue
Normal file
24
src/desktop/TestPanel.vue
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<script lang="ts" setup>
|
||||||
|
const count = 5
|
||||||
|
</script>
|
||||||
|
<template>
|
||||||
|
<n-flex vertical>
|
||||||
|
<n-flex>
|
||||||
|
<n-button>增加5个</n-button>
|
||||||
|
<n-button>运行看看</n-button>
|
||||||
|
<n-button type="primary">生成并下载</n-button>
|
||||||
|
</n-flex>
|
||||||
|
<n-flex vertical>
|
||||||
|
<n-flex v-for="it in count" :key="it">
|
||||||
|
<n-flex vertical>
|
||||||
|
<span>{{ it }}.in</span>
|
||||||
|
<n-input type="textarea" />
|
||||||
|
</n-flex>
|
||||||
|
<n-flex vertical>
|
||||||
|
<span>{{ it }}.out</span>
|
||||||
|
<n-input type="textarea" />
|
||||||
|
</n-flex>
|
||||||
|
</n-flex>
|
||||||
|
</n-flex>
|
||||||
|
</n-flex>
|
||||||
|
</template>
|
||||||
@@ -1,8 +1,34 @@
|
|||||||
<template>
|
<template>
|
||||||
<Header />
|
<Header />
|
||||||
<Content />
|
<Content />
|
||||||
|
<n-modal
|
||||||
|
v-model:show="show"
|
||||||
|
preset="card"
|
||||||
|
style="width: 600px"
|
||||||
|
:mask-closable="false"
|
||||||
|
title="测试用例文件生成器"
|
||||||
|
>
|
||||||
|
<TestPanel />
|
||||||
|
</n-modal>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import Header from "./Header.vue"
|
import Header from "./Header.vue"
|
||||||
import Content from "./Content.vue"
|
import Content from "./Content.vue"
|
||||||
|
import TestPanel from "./TestPanel.vue"
|
||||||
|
import { useMagicKeys, whenever } from "@vueuse/core"
|
||||||
|
import { ref } from "vue"
|
||||||
|
|
||||||
|
const { alt_shift_p, ctrl_shift_p, ctrl_shift_z } = useMagicKeys()
|
||||||
|
|
||||||
|
const show = ref(false)
|
||||||
|
|
||||||
|
whenever(alt_shift_p, () => {
|
||||||
|
show.value = true
|
||||||
|
})
|
||||||
|
whenever(ctrl_shift_p, () => {
|
||||||
|
show.value = true
|
||||||
|
})
|
||||||
|
whenever(ctrl_shift_z, () => {
|
||||||
|
show.value = true
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
NInputNumber,
|
NInputNumber,
|
||||||
NPopover,
|
NPopover,
|
||||||
NTag,
|
NTag,
|
||||||
|
NModal,
|
||||||
} from "naive-ui"
|
} from "naive-ui"
|
||||||
import App from "./App.vue"
|
import App from "./App.vue"
|
||||||
import "normalize.css"
|
import "normalize.css"
|
||||||
@@ -37,6 +38,8 @@ const naive = create({
|
|||||||
NInputNumber,
|
NInputNumber,
|
||||||
NPopover,
|
NPopover,
|
||||||
NTag,
|
NTag,
|
||||||
|
NModal,
|
||||||
|
NInput,
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user