update
This commit is contained in:
@@ -1,13 +1,18 @@
|
||||
import { reactive } from "vue"
|
||||
import { code, output } from "./code"
|
||||
import { computed, reactive } from "vue"
|
||||
import { output, status } from "./code"
|
||||
import { Status } from "../types"
|
||||
|
||||
export const analyse = reactive({
|
||||
line: -1,
|
||||
message: "",
|
||||
})
|
||||
|
||||
function findError(line: string) {
|
||||
const regex: any = {
|
||||
export const showAnalyse = computed(
|
||||
() => ![Status.Accepted, Status.NotStarted].includes(status.value),
|
||||
)
|
||||
|
||||
function findError(line: string, language = "python") {
|
||||
const python: any = {
|
||||
"EOFError: EOF when reading a line": "需要在输入框填写输入信息",
|
||||
"SyntaxError: invalid character in identifier":
|
||||
"可能是单词拼写错误,可能是括号、引号写成中文的了",
|
||||
@@ -18,6 +23,8 @@ function findError(line: string) {
|
||||
`命名错误,${name} 不知道是什么东西`,
|
||||
"IndentationError: expected an indented block": "缩进错误:这一行需要缩进",
|
||||
}
|
||||
const c: any = {}
|
||||
const regex = { c, python }[language]
|
||||
let message = ""
|
||||
for (let r in regex) {
|
||||
const err = line.match(r)
|
||||
@@ -33,8 +40,7 @@ function findError(line: string) {
|
||||
return message
|
||||
}
|
||||
|
||||
export function showAnalyse() {
|
||||
if (code.language === "python") {
|
||||
export function analyzeError() {
|
||||
const line = output.value.match(/File "script.py", line (\d+)/)
|
||||
if (line) {
|
||||
analyse.line = parseInt(line[1])
|
||||
@@ -42,8 +48,4 @@ export function showAnalyse() {
|
||||
const lines = output.value.split("\n")
|
||||
const lastLine = lines[lines.length - 1]
|
||||
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 { sources } from "../templates"
|
||||
import { submit } from "../api"
|
||||
@@ -22,13 +22,9 @@ export const code = reactive<Code>({
|
||||
})
|
||||
export const input = ref(cache.input.value)
|
||||
export const output = ref("")
|
||||
export const status = ref(Status.NotStarted)
|
||||
export const loading = ref(false)
|
||||
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) => {
|
||||
cache.fontsize.value = value
|
||||
|
||||
@@ -3,17 +3,18 @@ import copyTextToClipboard from "copy-text-to-clipboard"
|
||||
import {
|
||||
code,
|
||||
size,
|
||||
init,
|
||||
input,
|
||||
output,
|
||||
status,
|
||||
init,
|
||||
reset,
|
||||
clearInput,
|
||||
showStatus,
|
||||
} from "../composables/code"
|
||||
import { showAnalyse, analyse } from "../composables/analyse"
|
||||
import { showAnalyse, analyzeError, analyse } from "../composables/analyse"
|
||||
import CodeEditor from "../components/CodeEditor.vue"
|
||||
import { computed, onMounted } from "vue"
|
||||
import { useMessage } from "naive-ui"
|
||||
import { Status } from "../types"
|
||||
|
||||
onMounted(init)
|
||||
|
||||
@@ -71,9 +72,16 @@ function copy() {
|
||||
:font-size="size"
|
||||
>
|
||||
<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>
|
||||
<n-button quaternary type="error" @click="showAnalyse">
|
||||
<n-button quaternary type="error" @click="analyzeError">
|
||||
推测原因
|
||||
</n-button>
|
||||
</template>
|
||||
|
||||
@@ -43,7 +43,7 @@ const languages: SelectOption[] = [
|
||||
<Play />
|
||||
</n-icon>
|
||||
</template>
|
||||
运行 (F5)
|
||||
运行
|
||||
</n-button>
|
||||
</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>
|
||||
<Header />
|
||||
<Content />
|
||||
<n-modal
|
||||
v-model:show="show"
|
||||
preset="card"
|
||||
style="width: 600px"
|
||||
:mask-closable="false"
|
||||
title="测试用例文件生成器"
|
||||
>
|
||||
<TestPanel />
|
||||
</n-modal>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import Header from "./Header.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>
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
NInputNumber,
|
||||
NPopover,
|
||||
NTag,
|
||||
NModal,
|
||||
} from "naive-ui"
|
||||
import App from "./App.vue"
|
||||
import "normalize.css"
|
||||
@@ -37,6 +38,8 @@ const naive = create({
|
||||
NInputNumber,
|
||||
NPopover,
|
||||
NTag,
|
||||
NModal,
|
||||
NInput,
|
||||
],
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user