diff --git a/src/composables/analyse.ts b/src/composables/analyse.ts index 849e93f..a7b864a 100644 --- a/src/composables/analyse.ts +++ b/src/composables/analyse.ts @@ -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,17 +40,12 @@ function findError(line: string) { return message } -export function showAnalyse() { - if (code.language === "python") { - const line = output.value.match(/File "script.py", line (\d+)/) - if (line) { - analyse.line = parseInt(line[1]) - } - const lines = output.value.split("\n") - const lastLine = lines[lines.length - 1] - analyse.message = findError(lastLine) - } - if (code.language === "c") { - analyse.message = "C语言的正在制作中..." +export function analyzeError() { + const line = output.value.match(/File "script.py", line (\d+)/) + if (line) { + analyse.line = parseInt(line[1]) } + const lines = output.value.split("\n") + const lastLine = lines[lines.length - 1] + analyse.message = findError(lastLine) } diff --git a/src/composables/code.ts b/src/composables/code.ts index 4dd3cf1..590ba17 100644 --- a/src/composables/code.ts +++ b/src/composables/code.ts @@ -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({ }) 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 diff --git a/src/desktop/Content.vue b/src/desktop/Content.vue index 3aa32fa..0372895 100644 --- a/src/desktop/Content.vue +++ b/src/desktop/Content.vue @@ -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" > - 运行 (F5) + 运行 diff --git a/src/desktop/TestPanel.vue b/src/desktop/TestPanel.vue new file mode 100644 index 0000000..10b88fc --- /dev/null +++ b/src/desktop/TestPanel.vue @@ -0,0 +1,24 @@ + + diff --git a/src/desktop/index.vue b/src/desktop/index.vue index a5a8828..8c4c33d 100644 --- a/src/desktop/index.vue +++ b/src/desktop/index.vue @@ -1,8 +1,34 @@ diff --git a/src/main.ts b/src/main.ts index 4fdc193..4d76ce6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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, ], })