Compare commits
4 Commits
d3dfca2fe5
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| d798d56dbe | |||
| 504af39ff6 | |||
| dde90adb46 | |||
| 1fd2025fe1 |
@@ -1,6 +1,6 @@
|
|||||||
import axios from "axios"
|
import axios from "axios"
|
||||||
import { languageToId } from "./templates"
|
import { languageToId } from "./templates"
|
||||||
import { Code, Submission } from "./types"
|
import { Code, LANGUAGE, Submission } from "./types"
|
||||||
|
|
||||||
function encode(string?: string) {
|
function encode(string?: string) {
|
||||||
return btoa(String.fromCharCode(...new TextEncoder().encode(string ?? "")))
|
return btoa(String.fromCharCode(...new TextEncoder().encode(string ?? "")))
|
||||||
@@ -133,3 +133,8 @@ export async function debug(code: string, inputs: string[]) {
|
|||||||
})
|
})
|
||||||
return res.data
|
return res.data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function formatCode(code: string, language: LANGUAGE) {
|
||||||
|
const res = await api.post("/format", { code, language })
|
||||||
|
return res.data.code as string
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { useStorage } from "@vueuse/core"
|
|||||||
import copyTextToClipboard from "copy-text-to-clipboard"
|
import copyTextToClipboard from "copy-text-to-clipboard"
|
||||||
import qs from "query-string"
|
import qs from "query-string"
|
||||||
import { reactive, ref, watch } from "vue"
|
import { reactive, ref, watch } from "vue"
|
||||||
import { getCodeByQuery, submit } from "../api"
|
import { formatCode, getCodeByQuery, submit } from "../api"
|
||||||
import { sources } from "../templates"
|
import { sources } from "../templates"
|
||||||
import { Cache, Code, LANGUAGE, Status } from "../types"
|
import { Cache, Code, LANGUAGE, Status } from "../types"
|
||||||
import { atou, utoa } from "../utils"
|
import { atou, utoa } from "../utils"
|
||||||
@@ -136,3 +136,7 @@ export function share() {
|
|||||||
qs.stringifyUrl({ url: location.href, query: { share: base64 } }),
|
qs.stringifyUrl({ url: location.href, query: { share: base64 } }),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function format() {
|
||||||
|
code.value = await formatCode(code.value, code.language)
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import copyTextToClipboard from "copy-text-to-clipboard"
|
|||||||
import { useMessage } from "naive-ui"
|
import { useMessage } from "naive-ui"
|
||||||
import CodeEditor from "../components/CodeEditor.vue"
|
import CodeEditor from "../components/CodeEditor.vue"
|
||||||
import DebugPanel from "../components/DebugPanel.vue"
|
import DebugPanel from "../components/DebugPanel.vue"
|
||||||
import { code, input, reset, size } from "../composables/code"
|
import { code, format, input, reset, size } from "../composables/code"
|
||||||
import { debug } from "../api"
|
import { debug } from "../api"
|
||||||
|
|
||||||
const message = useMessage()
|
const message = useMessage()
|
||||||
@@ -22,6 +22,17 @@ function copy() {
|
|||||||
message.success("已经复制好了")
|
message.success("已经复制好了")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleFormat() {
|
||||||
|
try {
|
||||||
|
await format()
|
||||||
|
message.success("代码已整理")
|
||||||
|
} catch (err: any) {
|
||||||
|
message.error(
|
||||||
|
`整理失败: ${err?.response?.data?.detail ?? err?.message ?? "未知错误"}`,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* trace 末尾停在 raw_input 即说明输入不足
|
* trace 末尾停在 raw_input 即说明输入不足
|
||||||
* (pg_logger 在缺输入时会立刻 done=True,trace 中至多只有 1 个 raw_input 事件,
|
* (pg_logger 在缺输入时会立刻 done=True,trace 中至多只有 1 个 raw_input 事件,
|
||||||
@@ -67,6 +78,7 @@ async function handleDebug() {
|
|||||||
>
|
>
|
||||||
<template #actions>
|
<template #actions>
|
||||||
<n-button quaternary type="primary" @click="copy">复制</n-button>
|
<n-button quaternary type="primary" @click="copy">复制</n-button>
|
||||||
|
<n-button quaternary @click="handleFormat">整理</n-button>
|
||||||
<n-button quaternary @click="reset">清空</n-button>
|
<n-button quaternary @click="reset">清空</n-button>
|
||||||
<n-button
|
<n-button
|
||||||
v-if="code.language === 'python'"
|
v-if="code.language === 'python'"
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
const cSource =
|
const cSource =
|
||||||
"#include<stdio.h>\r\n\r\nint main()\r\n{\r\n \r\n return 0;\r\n}"
|
"#include <stdio.h>\r\n\r\nint main() {\r\n \r\n return 0;\r\n}"
|
||||||
const cppSource =
|
const cppSource =
|
||||||
"#include<iostream>\r\n\r\nusing namespace std;\r\n\r\nint main()\r\n{\r\n \r\n return 0;\r\n}"
|
"#include <iostream>\r\n\r\nusing namespace std;\r\n\r\nint main() {\r\n \r\n return 0;\r\n}"
|
||||||
const pythonSource = ""
|
const pythonSource = ""
|
||||||
const javaSource =
|
const javaSource =
|
||||||
"public class Main {\r\n public static void main(String[] args) {\r\n \r\n }\r\n}"
|
"public class Main {\r\n public static void main(String[] args) {\r\n \r\n }\r\n}"
|
||||||
|
|||||||
Reference in New Issue
Block a user