Selaa lähdekoodia

💄 (dashboard-v6): 主导航与顶部工具栏吸顶,折叠状态记入 localStorage

- 主导航 Sider 吸顶、内部滚动;折叠状态存 workspace:main-menu-collapsed
- 顶部工具栏吸顶,固定高度 56px、背景随主题
- SplitLayout 新增 stickyTop,右边栏吸顶位置与初始位置一致(工具栏 + 内容区内边距),面板高度相应扣除

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
visuddhinanda 6 tuntia sitten
vanhempi
sitoutus
42ec0fcd7a

+ 2 - 0
dashboard-v6/src/components/editor/Editor.tsx

@@ -18,6 +18,7 @@ import type { IChannel } from "../../api/channel";
 import { useAppSelector } from "../../hooks";
 import { useAppSelector } from "../../hooks";
 import { openPanel, rightPanel } from "../../reducers/right-panel";
 import { openPanel, rightPanel } from "../../reducers/right-panel";
 import store from "../../store";
 import store from "../../store";
+import { WORKSPACE_STICKY_TOP } from "../../layouts/workspace/constants";
 
 
 /**
 /**
  * redux openPanel 面板名 → 右边栏 tab key。
  * redux openPanel 面板名 → 右边栏 tab key。
@@ -174,6 +175,7 @@ export default function Editor({
       sidebar={sidebar}
       sidebar={sidebar}
       rightTabs={rightTabs}
       rightTabs={rightTabs}
       openRequest={openRequest}
       openRequest={openRequest}
+      stickyTop={WORKSPACE_STICKY_TOP}
     >
     >
       {({ expandButton }) => children({ expandButton })}
       {({ expandButton }) => children({ expandButton })}
     </SplitLayout>
     </SplitLayout>

+ 4 - 3
dashboard-v6/src/components/general/SplitLayout/RightToolbar.module.css

@@ -7,7 +7,8 @@
 .container {
 .container {
   display: flex;
   display: flex;
   flex-direction: row;
   flex-direction: row;
-  height: 100vh;
+  /* 吸顶时让出外层顶部工具栏的高度(由 RightToolbar 的 stickyTop 设置) */
+  height: calc(100vh - var(--right-toolbar-top, 0px));
   overflow: hidden;
   overflow: hidden;
 }
 }
 
 
@@ -53,7 +54,7 @@
 .panelBody {
 .panelBody {
   overflow-y: scroll;
   overflow-y: scroll;
   overflow-x: hidden;
   overflow-x: hidden;
-  height: calc(100vh - 40px);
+  height: calc(100vh - var(--right-toolbar-top, 0px) - 40px);
   /* display:contents 的子项可直接撑满 */
   /* display:contents 的子项可直接撑满 */
   display: flex;
   display: flex;
   flex-direction: column;
   flex-direction: column;
@@ -61,7 +62,7 @@
 
 
 /* 面板自带顶栏(hideHeader)时占满整个高度 */
 /* 面板自带顶栏(hideHeader)时占满整个高度 */
 .panelBodyFull {
 .panelBodyFull {
-  height: 100vh;
+  height: calc(100vh - var(--right-toolbar-top, 0px));
 }
 }
 
 
 /* ── 纵向图标工具栏 ── */
 /* ── 纵向图标工具栏 ── */

+ 7 - 1
dashboard-v6/src/components/general/SplitLayout/RightToolbar.tsx

@@ -29,6 +29,8 @@ interface RightToolbarProps {
   activeKey: string | null;
   activeKey: string | null;
   onTabClick: (key: string) => void;
   onTabClick: (key: string) => void;
   onClose: () => void;
   onClose: () => void;
+  /** 吸顶时距视口顶部的距离(px),面板高度相应减去它 */
+  stickyTop?: number;
 }
 }
 
 
 export default function RightToolbar({
 export default function RightToolbar({
@@ -36,6 +38,7 @@ export default function RightToolbar({
   activeKey,
   activeKey,
   onTabClick,
   onTabClick,
   onClose,
   onClose,
+  stickyTop = 0,
 }: RightToolbarProps) {
 }: RightToolbarProps) {
   // 记录哪些 tab 曾经被打开过(懒创建:首次点击后才挂载 DOM)
   // 记录哪些 tab 曾经被打开过(懒创建:首次点击后才挂载 DOM)
   // 使用模块级 WeakMap 不行,用组件内 Set ref 也可以,
   // 使用模块级 WeakMap 不行,用组件内 Set ref 也可以,
@@ -56,7 +59,10 @@ export default function RightToolbar({
   const panelOpen = activeKey !== null && !!activeTab?.content;
   const panelOpen = activeKey !== null && !!activeTab?.content;
 
 
   return (
   return (
-    <div className={styles.container}>
+    <div
+      className={styles.container}
+      style={{ "--right-toolbar-top": `${stickyTop}px` } as React.CSSProperties}
+    >
       {/* ── 面板内容区 ── */}
       {/* ── 面板内容区 ── */}
       {panelOpen && (
       {panelOpen && (
         <div className={styles.panel}>
         <div className={styles.panel}>

+ 9 - 1
dashboard-v6/src/components/general/SplitLayout/SplitLayout.tsx

@@ -84,6 +84,12 @@ export interface SplitLayoutProps {
    * 传 0 或负数表示不限制(占满可用宽度)。
    * 传 0 或负数表示不限制(占满可用宽度)。
    */
    */
   contentMaxWidth?: number;
   contentMaxWidth?: number;
+
+  /**
+   * 右边栏吸顶时距视口顶部的距离(px),默认 0。
+   * 外层布局有吸顶的顶部工具栏时传它的高度,右边栏停在工具栏下面。
+   */
+  stickyTop?: number;
 }
 }
 
 
 // ─────────────────────────────────────────────
 // ─────────────────────────────────────────────
@@ -100,6 +106,7 @@ export default function SplitLayout({
   minRightSize = 280,
   minRightSize = 280,
   maxRightSize = 800,
   maxRightSize = 800,
   contentMaxWidth = 1000,
   contentMaxWidth = 1000,
+  stickyTop = 0,
 }: SplitLayoutProps) {
 }: SplitLayoutProps) {
   // ── 左侧收起状态(持久化)──
   // ── 左侧收起状态(持久化)──
   const [collapsed, setCollapsed] = useState<boolean>(() => {
   const [collapsed, setCollapsed] = useState<boolean>(() => {
@@ -270,8 +277,9 @@ export default function SplitLayout({
                 resizable={rightOpen}
                 resizable={rightOpen}
                 className={styles.rightAreaPanel}
                 className={styles.rightAreaPanel}
               >
               >
-                <Affix offsetTop={0}>
+                <Affix offsetTop={stickyTop}>
                   <RightToolbar
                   <RightToolbar
+                    stickyTop={stickyTop}
                     tabs={rightTabs!}
                     tabs={rightTabs!}
                     activeKey={rightActiveKey}
                     activeKey={rightActiveKey}
                     onTabClick={onRightTabClick}
                     onTabClick={onRightTabClick}

+ 12 - 0
dashboard-v6/src/layouts/workspace/constants.ts

@@ -0,0 +1,12 @@
+/** 工作区顶部工具栏高度(px) */
+export const WORKSPACE_HEADER_HEIGHT = 56;
+
+/** 工作区内容区(Content)的内边距(px) */
+export const WORKSPACE_CONTENT_PADDING = 12;
+
+/**
+ * 内容区顶部到视口顶部的距离(px):工具栏 + 内容区上内边距。
+ * 吸顶元素(如右边栏)用它做偏移,吸顶位置与初始位置一致,滚动时不会跳动。
+ */
+export const WORKSPACE_STICKY_TOP =
+  WORKSPACE_HEADER_HEIGHT + WORKSPACE_CONTENT_PADDING;

+ 45 - 8
dashboard-v6/src/layouts/workspace/index.tsx

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