import {AppBar, Button, Grid, Toolbar, Typography} from "@mui/material"; import {InputField} from "./InputField.tsx"; import {CSSProperties, useEffect, useState} from "react"; import {OutputField} from "./OutputField.tsx"; import createClient from "openapi-fetch"; import * as openapi from '../openapi'; import {enqueueSnackbar} from "notistack"; import {useNavigate} from "react-router-dom"; import {HistoryPage} from "./HistoryPage.tsx"; import {OutputIntf} from "../Interfaces/OutputIntf.ts"; const client = createClient(); export function Index() { const [inputValue, setInputValue] = useState(''); const [outputValue, setOutputValue] = useState({ compiledCode: "", sourceCode: "", id: "", imageAddress: "", compileTime: "" }); const [historyPageState,setHistoryPageState] = useState(false); const navigate = useNavigate(); // 跳转hook useEffect(() => { // 进入页面的初始化 const path = location.pathname.substring(1); if (path === "") { setInputValue(""); setOutputValue({ compiledCode: "", sourceCode: "", id: "", imageAddress: "pic/uncompiled.png", compileTime: "" }) return; } const getCompileInstance = async () => { const {data} = await client.GET("/api/Compiler/{compileId}", { params: { path: { compileId: path } } }) if (data !== undefined) { setInputValue(data.sourceCode); setOutputValue({ compiledCode: data.compiledCode, sourceCode: data.sourceCode, id: data.id, imageAddress: data.imageAddress, compileTime: data.compileTime }) } } getCompileInstance(); }, [location.pathname]); const handleValueChange = (value: string) => { setInputValue(value); }; async function compilerButtonClick() { const {data} = await client.POST("/api/Compiler", { body: { code: inputValue } }) if (data !== undefined) { setOutputValue({ compiledCode: data.compiledCode, sourceCode: data.sourceCode, id: data.id, imageAddress: data.imageAddress, compileTime: data.compileTime }) enqueueSnackbar("编译成功", {variant: "success", anchorOrigin: {vertical: 'bottom', horizontal: 'right'}}); navigate(`/${data.id}`, {}) } else { // error enqueueSnackbar("编译失败", {variant: "error", anchorOrigin: {vertical: 'bottom', horizontal: 'right'}}); } } function historyButtonClick() { setHistoryPageState(true); } return <>
Canon
} const titleClassCss: CSSProperties = { position: "absolute", height: "max-content", width: "100%", } const contentClassCss: CSSProperties = { position: "relative", height: "88%", top: "12%", width: "100%", }