feat: 添加路由支持,重构应用结构,新增导航栏和页面占位符

This commit is contained in:
xiaozhou233 committed 2026-08-09 21:56:20 +08:00
1 parent bd87fc0db8
commit 7bafbf9e64
17 files changed
+516 -123

No files matched your search

+59 -1
View File
@@ -9,7 +9,8 @@
"version": "0.0.0",
"dependencies": {
"react": "^19.2.8",
"react-dom": "^19.2.8"
"react-dom": "^19.2.8",
"react-router-dom": "^7.18.2"
},
"devDependencies": {
"@eslint/js": "^10.0.1",
@@ -1241,6 +1242,19 @@
"dev": true,
"license": "MIT"
},
"node_modules/cookie": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-1.1.1.tgz",
"integrity": "sha512-ei8Aos7ja0weRpFzJnEA9UHJ/7XQmqglbRwnf2ATjcB9Wq874VKH9kfjjirM6UhU2/E5fFYadylyhFldcqSidQ==",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/express"
}
},
"node_modules/cross-spawn": {
"version": "7.0.6",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
@@ -2317,6 +2331,44 @@
"react": "^19.2.8"
}
},
"node_modules/react-router": {
"version": "7.18.2",
"resolved": "https://registry.npmjs.org/react-router/-/react-router-7.18.2.tgz",
"integrity": "sha512-aUVMjFm3GAPTTZL7oYr5E7ETiqfQCHRLH+B+5afnICvf0r7kkK4eR6SMuwbSTJw/7t+12khT/Kahij49fqOCIg==",
"license": "MIT",
"dependencies": {
"cookie": "^1.0.1",
"set-cookie-parser": "^2.6.0"
},
"engines": {
"node": ">=20.0.0"
},
"peerDependencies": {
"react": ">=18",
"react-dom": ">=18"
},
"peerDependenciesMeta": {
"react-dom": {
"optional": true
}
}
},
"node_modules/react-router-dom": {
"version": "7.18.2",
"resolved": "https://registry.npmjs.org/react-router-dom/-/react-router-dom-7.18.2.tgz",
"integrity": "sha512-AIKJ/jgGlFb3EbfCXk5Gzshiwt+l3mqbCrNjmEWMMjqQxNJ3svBa6bgzFyCC2Sw3RA0VWF1kg3uQf2OFhxb8hw==",
"license": "MIT",
"dependencies": {
"react-router": "7.18.2"
},
"engines": {
"node": ">=20.0.0"
},
"peerDependencies": {
"react": ">=18",
"react-dom": ">=18"
}
},
"node_modules/rolldown": {
"version": "1.2.3",
"resolved": "https://registry.npmjs.org/rolldown/-/rolldown-1.2.3.tgz",
@@ -2366,6 +2418,12 @@
"semver": "bin/semver.js"
}
},
"node_modules/set-cookie-parser": {
"version": "2.7.2",
"resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.7.2.tgz",
"integrity": "sha512-oeM1lpU/UvhTxw+g3cIfxXHyJRc/uidd3yK1P242gzHds0udQBYzs3y8j4gCCW+ZJ7ad0yctld8RYO+bdurlvw==",
"license": "MIT"
},
"node_modules/shebang-command": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
+2 -1
View File
@@ -11,7 +11,8 @@
},
"dependencies": {
"react": "^19.2.8",
"react-dom": "^19.2.8"
"react-dom": "^19.2.8",
"react-router-dom": "^7.18.2"
},
"devDependencies": {
"@eslint/js": "^10.0.1",
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

+6
View File
@@ -0,0 +1,6 @@
{
"buildNumber": "Unknown",
"commit": "Unknown",
"branch": "Unknown",
"time": "Unknown"
}
+26 -115
View File
@@ -1,121 +1,32 @@
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from './assets/vite.svg'
import heroImg from './assets/hero.png'
import './App.css'
import { Route, Routes } from 'react-router-dom'
import Navbar from './components/Navbar'
import Banner from './components/Banner'
import Footer from './components/Footer'
import DashboardLayout from './layouts/DashboardLayout'
import Placeholder from './pages/Placeholder'
function App() {
const [count, setCount] = useState(0)
return (
<>
<section id="center">
<div className="hero">
<img src={heroImg} className="base" width="170" height="179" alt="" />
<img src={reactLogo} className="framework" alt="React logo" />
<img src={viteLogo} className="vite" alt="Vite logo" />
</div>
<div>
<h1>Get started</h1>
<p>
Edit <code>src/App.tsx</code> and save to test <code>HMR</code>
</p>
</div>
<button
type="button"
className="counter"
onClick={() => setCount((count) => count + 1)}
>
Count is {count}
</button>
</section>
<div className="ticks"></div>
<section id="next-steps">
<div id="docs">
<svg className="icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#documentation-icon"></use>
</svg>
<h2>Documentation</h2>
<p>Your questions, answered</p>
<ul>
<li>
<a href="https://vite.dev/" target="_blank">
<img className="logo" src={viteLogo} alt="" />
Explore Vite
</a>
</li>
<li>
<a href="https://react.dev/" target="_blank">
<img className="button-icon" src={reactLogo} alt="" />
Learn more
</a>
</li>
</ul>
</div>
<div id="social">
<svg className="icon" role="presentation" aria-hidden="true">
<use href="/icons.svg#social-icon"></use>
</svg>
<h2>Connect with us</h2>
<p>Join the Vite community</p>
<ul>
<li>
<a href="https://github.com/vitejs/vite" target="_blank">
<svg
className="button-icon"
role="presentation"
aria-hidden="true"
>
<use href="/icons.svg#github-icon"></use>
</svg>
GitHub
</a>
</li>
<li>
<a href="https://chat.vite.dev/" target="_blank">
<svg
className="button-icon"
role="presentation"
aria-hidden="true"
>
<use href="/icons.svg#discord-icon"></use>
</svg>
Discord
</a>
</li>
<li>
<a href="https://x.com/vite_js" target="_blank">
<svg
className="button-icon"
role="presentation"
aria-hidden="true"
>
<use href="/icons.svg#x-icon"></use>
</svg>
X.com
</a>
</li>
<li>
<a href="https://bsky.app/profile/vite.dev" target="_blank">
<svg
className="button-icon"
role="presentation"
aria-hidden="true"
>
<use href="/icons.svg#bluesky-icon"></use>
</svg>
Bluesky
</a>
</li>
</ul>
</div>
</section>
<div className="ticks"></div>
<section id="spacer"></section>
</>
<Routes>
<Route
path="/"
element={
<>
<Navbar />
<main>
<Banner />
</main>
<Footer />
</>
}
/>
<Route path="/dashboard" element={<DashboardLayout />}>
<Route index element={<Placeholder title="概览" />} />
<Route path="tasks" element={<Placeholder title="任务" />} />
<Route path="monitor" element={<Placeholder title="监控" />} />
<Route path="settings" element={<Placeholder title="设置" />} />
</Route>
</Routes>
)
}
+76
View File
@@ -0,0 +1,76 @@
.banner {
position: relative;
min-height: 100svh;
display: flex;
align-items: center;
justify-content: center;
background-image: url('/banner.jpg');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.banner::before {
content: '';
position: absolute;
inset: 0;
background: rgba(0, 0, 0, 0.45);
}
.banner-overlay {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
gap: 32px;
padding: 120px 24px 64px;
text-align: center;
}
.banner-title {
margin: 0;
font-size: 64px;
font-weight: 700;
letter-spacing: -1px;
color: #fff;
text-shadow: 0 2px 16px rgba(0, 0, 0, 0.5);
}
.banner-button {
display: inline-block;
padding: 14px 40px;
font-size: 18px;
font-weight: 600;
color: #fff;
background: rgba(17, 18, 23, 0.65);
border: 1px solid rgba(255, 255, 255, 0.5);
border-radius: 999px;
text-decoration: none;
backdrop-filter: blur(6px);
transition:
background 0.25s,
transform 0.25s;
&:hover {
background: #c084fc;
border-color: #c084fc;
transform: translateY(-2px);
}
}
@media (max-width: 1024px) {
.banner-title {
font-size: 40px;
}
}
@media (max-width: 640px) {
.banner-title {
font-size: 32px;
}
.banner-button {
padding: 12px 32px;
font-size: 16px;
}
}
+16
View File
@@ -0,0 +1,16 @@
import './Banner.css'
function Banner() {
return (
<section className="banner">
<div className="banner-overlay">
<h1 className="banner-title">JuiceWorkStation</h1>
<a className="banner-button" href="/dashboard">
进入控制面板
</a>
</div>
</section>
)
}
export default Banner
+26
View File
@@ -0,0 +1,26 @@
.footer {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 8px;
padding: 24px;
background: rgba(22, 23, 29, 0.85);
border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.footer-text {
margin: 0;
font-size: 14px;
color: rgba(255, 255, 255, 0.6);
}
.footer-version {
display: flex;
flex-direction: column;
align-items: center;
gap: 2px;
font-family: ui-monospace, Consolas, monospace;
font-size: 12px;
color: rgba(255, 255, 255, 0.4);
}
+39
View File
@@ -0,0 +1,39 @@
import { useEffect, useState } from 'react'
import './Footer.css'
interface VersionInfo {
buildNumber: string
commit: string
branch: string
time: string
}
function Footer() {
const [version, setVersion] = useState<VersionInfo | null>(null)
useEffect(() => {
fetch('/version.json')
.then((res) => res.json())
.then(setVersion)
.catch(() => setVersion(null))
}, [])
return (
<footer className="footer">
<p className="footer-text">
© {new Date().getFullYear()} JuiceWorkStation. All rights reserved.
</p>
{version && (
<div className="footer-version">
<span>Build {version.buildNumber}</span>
<span>
{version.branch}-{version.commit}
</span>
<span>{version.time}</span>
</div>
)}
</footer>
)
}
export default Footer
+51
View File
@@ -0,0 +1,51 @@
.navbar {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 100;
display: flex;
align-items: center;
justify-content: space-between;
padding: 16px 32px;
background: rgba(22, 23, 29, 0.85);
backdrop-filter: blur(8px);
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.navbar-brand {
font-size: 20px;
font-weight: 700;
color: #fff;
text-decoration: none;
letter-spacing: 0.2px;
}
.navbar-links {
list-style: none;
display: flex;
gap: 24px;
margin: 0;
padding: 0;
a {
color: rgba(255, 255, 255, 0.8);
text-decoration: none;
font-size: 15px;
transition: color 0.2s;
&:hover {
color: #c084fc;
}
}
}
@media (max-width: 640px) {
.navbar {
padding: 12px 16px;
}
.navbar-links {
gap: 16px;
}
}
+25
View File
@@ -0,0 +1,25 @@
import './Navbar.css'
const links = [
{ label: '首页', href: '/' },
{ label: '控制面板', href: '/dashboard' },
]
function Navbar() {
return (
<nav className="navbar">
<a href="/" className="navbar-brand">
JuiceWorkStation
</a>
<ul className="navbar-links">
{links.map((link) => (
<li key={link.href}>
<a href={link.href}>{link.label}</a>
</li>
))}
</ul>
</nav>
)
}
export default Navbar
+1 -5
View File
@@ -51,11 +51,6 @@
}
#root {
width: 1126px;
max-width: 100%;
margin: 0 auto;
text-align: center;
border-inline: 1px solid var(--border);
min-height: 100svh;
display: flex;
flex-direction: column;
@@ -64,6 +59,7 @@
body {
margin: 0;
background: #16171d;
}
h1,
+101
View File
@@ -0,0 +1,101 @@
.dashboard {
min-height: 100svh;
display: flex;
flex-direction: column;
background: #0f1014;
}
.dashboard-topbar {
display: flex;
align-items: center;
justify-content: space-between;
padding: 14px 24px;
background: #1a1c22;
border-bottom: 1px solid #2a2d35;
}
.dashboard-brand {
font-size: 18px;
font-weight: 700;
color: #fff;
text-decoration: none;
}
.dashboard-user {
font-size: 14px;
color: #9ca3af;
}
.dashboard-body {
display: flex;
flex: 1;
}
.dashboard-sidebar {
width: 200px;
flex-shrink: 0;
padding: 16px 0;
background: #16171d;
border-right: 1px solid #2a2d35;
nav {
display: flex;
flex-direction: column;
}
}
.dashboard-nav-link {
display: block;
padding: 12px 24px;
font-size: 14px;
color: #9ca3af;
text-decoration: none;
border-left: 3px solid transparent;
transition:
color 0.2s,
background 0.2s;
&:hover {
color: #fff;
background: rgba(255, 255, 255, 0.05);
}
&.active {
color: #c084fc;
background: rgba(192, 132, 252, 0.1);
border-left-color: #c084fc;
}
}
.dashboard-content {
flex: 1;
padding: 32px;
overflow: auto;
}
@media (max-width: 768px) {
.dashboard-body {
flex-direction: column;
}
.dashboard-sidebar {
width: 100%;
border-right: none;
border-bottom: 1px solid #2a2d35;
nav {
flex-direction: row;
overflow-x: auto;
}
}
.dashboard-nav-link {
border-left: none;
border-bottom: 3px solid transparent;
white-space: nowrap;
}
.dashboard-content {
padding: 20px;
}
}
+45
View File
@@ -0,0 +1,45 @@
import { NavLink, Outlet } from 'react-router-dom'
import './DashboardLayout.css'
const items = [
{ label: '概览', href: '/dashboard' },
{ label: '任务', href: '/dashboard/tasks' },
{ label: '监控', href: '/dashboard/monitor' },
{ label: '设置', href: '/dashboard/settings' },
]
function DashboardLayout() {
return (
<div className="dashboard">
<header className="dashboard-topbar">
<NavLink to="/" className="dashboard-brand">
JuiceWorkStation
</NavLink>
<div className="dashboard-user">管理员</div>
</header>
<div className="dashboard-body">
<aside className="dashboard-sidebar">
<nav>
{items.map((item) => (
<NavLink
key={item.href}
to={item.href}
end={item.href === '/dashboard'}
className={({ isActive }) =>
isActive ? 'dashboard-nav-link active' : 'dashboard-nav-link'
}
>
{item.label}
</NavLink>
))}
</nav>
</aside>
<main className="dashboard-content">
<Outlet />
</main>
</div>
</div>
)
}
export default DashboardLayout
+4 -1
View File
@@ -1,10 +1,13 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { BrowserRouter } from 'react-router-dom'
import './index.css'
import App from './App.tsx'
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
<BrowserRouter>
<App />
</BrowserRouter>
</StrictMode>,
)
+21
View File
@@ -0,0 +1,21 @@
.placeholder-title {
margin: 0 0 24px;
font-size: 28px;
font-weight: 600;
color: #f3f4f6;
}
.placeholder-box {
display: flex;
align-items: center;
justify-content: center;
min-height: 320px;
border: 1px dashed #2a2d35;
border-radius: 12px;
background: #1a1c22;
color: #9ca3af;
p {
font-size: 15px;
}
}
+18
View File
@@ -0,0 +1,18 @@
import './Placeholder.css'
interface PlaceholderProps {
title: string
}
function Placeholder({ title }: PlaceholderProps) {
return (
<section className="placeholder">
<h1 className="placeholder-title">{title}</h1>
<div className="placeholder-box">
<p>该页面正在建设中,敬请期待。</p>
</div>
</section>
)
}
export default Placeholder