|
|
@@ -1,6 +1,6 @@
|
|
|
-import { Button, Layout, Space } from "antd";
|
|
|
+import { Button, Layout, Space, theme } from "antd";
|
|
|
import { Navigate, Outlet } from "react-router";
|
|
|
-import { useState } from "react";
|
|
|
+import { useCallback, useState } from "react";
|
|
|
import { MenuFoldOutlined, MenuUnfoldOutlined } from "@ant-design/icons";
|
|
|
import MainMenu from "../../components/navigation/MainMenu";
|
|
|
import SignInAvatar from "../../components/auth/SignInAvatar";
|
|
|
@@ -13,10 +13,36 @@ import SentCart from "../../components/sentence/SentCart";
|
|
|
import NotificationIcon from "../../components/notification/NotificationIcon";
|
|
|
import TeamspaceBadge from "../../features/teamspace/TeamspaceBadge";
|
|
|
import TeamspaceGuard from "../../features/teamspace/TeamspaceGuard";
|
|
|
+import {
|
|
|
+ WORKSPACE_CONTENT_PADDING,
|
|
|
+ WORKSPACE_HEADER_HEIGHT,
|
|
|
+} from "./constants";
|
|
|
|
|
|
const { Sider, Content } = Layout;
|
|
|
+
|
|
|
+/** 主导航折叠状态的 localStorage 键 */
|
|
|
+const COLLAPSED_KEY = "workspace:main-menu-collapsed";
|
|
|
+
|
|
|
const Widget = () => {
|
|
|
- const [collapsed, setCollapsed] = useState(false);
|
|
|
+ const [collapsed, setCollapsed] = useState<boolean>(() => {
|
|
|
+ try {
|
|
|
+ return localStorage.getItem(COLLAPSED_KEY) === "true";
|
|
|
+ } catch {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ const toggleCollapsed = useCallback(() => {
|
|
|
+ setCollapsed((v) => {
|
|
|
+ const next = !v;
|
|
|
+ try {
|
|
|
+ localStorage.setItem(COLLAPSED_KEY, String(next));
|
|
|
+ } catch {
|
|
|
+ /* 静默降级 */
|
|
|
+ }
|
|
|
+ return next;
|
|
|
+ });
|
|
|
+ }, []);
|
|
|
+ const { token } = theme.useToken();
|
|
|
const { isAuthenticated } = useAuth();
|
|
|
|
|
|
if (!isAuthenticated) {
|
|
|
@@ -26,7 +52,13 @@ const Widget = () => {
|
|
|
return (
|
|
|
<Layout style={{ minHeight: "100vh" }}>
|
|
|
<Sider
|
|
|
- style={{ backgroundColor: "unset" }}
|
|
|
+ style={{
|
|
|
+ backgroundColor: "unset",
|
|
|
+ position: "sticky",
|
|
|
+ top: 0,
|
|
|
+ height: "100vh",
|
|
|
+ overflowY: "auto",
|
|
|
+ }}
|
|
|
trigger={null}
|
|
|
collapsible
|
|
|
collapsed={collapsed}
|
|
|
@@ -42,7 +74,7 @@ const Widget = () => {
|
|
|
<Button
|
|
|
type="text"
|
|
|
icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
|
|
|
- onClick={() => setCollapsed(!collapsed)}
|
|
|
+ onClick={toggleCollapsed}
|
|
|
/>
|
|
|
</div>
|
|
|
<MainMenu />
|
|
|
@@ -50,10 +82,15 @@ const Widget = () => {
|
|
|
<Layout>
|
|
|
<div
|
|
|
style={{
|
|
|
- padding: 16, // 建议保留左右内边距,否则内容会贴边
|
|
|
+ position: "sticky",
|
|
|
+ top: 0,
|
|
|
+ zIndex: 10,
|
|
|
+ background: token.colorBgLayout,
|
|
|
+ padding: "0 16px", // 保留左右内边距,否则内容会贴边
|
|
|
display: "flex",
|
|
|
alignItems: "center", // 垂直居中
|
|
|
- height: 24,
|
|
|
+ boxSizing: "border-box",
|
|
|
+ height: WORKSPACE_HEADER_HEIGHT,
|
|
|
justifyContent: "space-between", // 如果需要左右分布(如左侧面包屑,右侧头像)可开启
|
|
|
}}
|
|
|
>
|
|
|
@@ -68,7 +105,7 @@ const Widget = () => {
|
|
|
</Space>
|
|
|
</div>
|
|
|
|
|
|
- <Content style={{ padding: 12 }}>
|
|
|
+ <Content style={{ padding: WORKSPACE_CONTENT_PADDING }}>
|
|
|
<TeamspaceGuard>
|
|
|
<Outlet />
|
|
|
</TeamspaceGuard>
|