tcjs/ui/src/App.tsx

80 lines
2.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { useState } from "react";
import { App as AntApp, ConfigProvider, Tabs } from "antd";
import zhCN from "antd/locale/zh_CN";
import { CalculatorPanel } from "./CalculatorPanel";
import { HistoryTab } from "./HistoryTab";
import { UpdateButton } from "./UpdateButton";
import type { SampleInput } from "./types";
function Brand() {
return (
<div className="brand">
<img className="brand-logo" src="/logo.png" alt="" />
<span className="brand-name"></span>
</div>
);
}
function App() {
const [activeTab, setActiveTab] = useState("calc");
const [reloadSignal, setReloadSignal] = useState(0);
// 复算:带入历史 input 并强制重挂 CalculatorPanelkey 递增)。
const [loadedInput, setLoadedInput] = useState<SampleInput | undefined>(undefined);
const [calcKey, setCalcKey] = useState(0);
const recompute = (input: SampleInput) => {
setLoadedInput(input);
setCalcKey((k) => k + 1);
setActiveTab("calc");
};
return (
<ConfigProvider
locale={zhCN}
theme={{
token: {
colorPrimary: "#243150",
colorInfo: "#243150",
colorLink: "#243150",
colorLinkHover: "#3a4d78",
borderRadius: 8,
fontSize: 14
}
}}
>
<AntApp>
<main className="app-shell">
<Tabs
activeKey={activeTab}
onChange={setActiveTab}
className="main-tabs"
tabBarExtraContent={{ left: <Brand />, right: <UpdateButton /> }}
items={[
{
key: "calc",
label: "计算",
children: (
<CalculatorPanel
key={calcKey}
initialInput={loadedInput}
onSaved={() => setReloadSignal((s) => s + 1)}
/>
)
},
{
key: "history",
label: "历史记录",
children: (
<HistoryTab active={activeTab === "history"} reloadSignal={reloadSignal} onRecompute={recompute} />
)
}
]}
/>
</main>
</AntApp>
</ConfigProvider>
);
}
export { App };