diff --git a/e2e/artifacts/f2-13/type1-00551ef5-title.png b/e2e/artifacts/f2-13/type1-00551ef5-title.png new file mode 100644 index 0000000..7269928 Binary files /dev/null and b/e2e/artifacts/f2-13/type1-00551ef5-title.png differ diff --git a/e2e/artifacts/f2-13/type200-03ec5566-data.png b/e2e/artifacts/f2-13/type200-03ec5566-data.png new file mode 100644 index 0000000..af316ed Binary files /dev/null and b/e2e/artifacts/f2-13/type200-03ec5566-data.png differ diff --git a/src/pages/PageRenderPage.tsx b/src/pages/PageRenderPage.tsx index deb2578..c4e02d3 100644 --- a/src/pages/PageRenderPage.tsx +++ b/src/pages/PageRenderPage.tsx @@ -6,6 +6,7 @@ import { useParams } from 'react-router-dom'; import { fetchSchema } from '../api/schema'; import { AmisRenderer } from '../components/AmisRenderer'; import { recordRecentPage } from '../utils/recentPages'; +import { useTabTitle } from '../shell/TabTitleContext'; // ---- amis 渲染层错误边界(class component,捕获子树抛错)---- interface ErrorBoundaryState { @@ -73,6 +74,7 @@ export function PageRenderPage() { const { templateId = '' } = useParams(); const [schema, setSchema] = useState | null>(null); const [error, setError] = useState(''); + const { updateTabTitle } = useTabTitle(); useEffect(() => { let alive = true; @@ -90,6 +92,8 @@ export function PageRenderPage() { // 渲染成功后写入最近打开(title 取 schema.title 或 templateId) const title = (s['title'] as string) || templateId; recordRecentPage({ templateId, name: title, path: title }); + // F2-13:回填 Tab 标题为 schema title + updateTabTitle(`/page/${templateId}`, title); }) .catch((e: Error) => { if (alive) setError(e.message ?? '未知错误'); diff --git a/src/shell/AppShell.tsx b/src/shell/AppShell.tsx index ca20493..7a6ed4d 100644 --- a/src/shell/AppShell.tsx +++ b/src/shell/AppShell.tsx @@ -19,6 +19,7 @@ import { SideMenu } from './SideMenu'; import { TabBar } from './TabBar'; import type { Tab } from './TabBar'; import { SettingsDrawer, initTheme } from './SettingsDrawer'; +import { TabTitleContext } from './TabTitleContext'; const TABS_KEY = 'eip4-tabs'; const ACTIVE_KEY = 'eip4-active-tab'; @@ -71,11 +72,19 @@ export function AppShell() { const profile = getProfile(); // 同步 activeKey 跟随浏览器地址(直接输入 URL / 后退前进) + // F2-13:直开 /page/:id 深链接时,若 Tab 不存在则自动新增并激活;title 先用 id 占位, + // PageRenderPage 拉到 schema 后通过 updateTabTitle 回填真实标题。 useEffect(() => { const path = location.pathname; - // 若当前路径不在 tab 列表中则不自动新增(由菜单点击触发) if (tabs.some((t) => t.key === path)) { setActiveKey(path); + } else if (path.startsWith('/page/')) { + const templateId = path.slice('/page/'.length); + setTabs((prev) => { + if (prev.some((t) => t.key === path)) return prev; + return [...prev, { key: path, title: templateId }]; + }); + setActiveKey(path); } }, [location.pathname, tabs]); @@ -136,6 +145,13 @@ export function AppShell() { }; }, []); + // F2-13:回填 Tab 标题(PageRenderPage 拿到 schema title 后调用) + const updateTabTitle = useCallback((path: string, title: string) => { + setTabs((prev) => + prev.map((t) => (t.key === path && t.title !== title ? { ...t, title } : t)), + ); + }, []); + // 打开/激活一个 Tab const openTab = useCallback( (key: string, title: string) => { @@ -232,7 +248,9 @@ export function AppShell() { />
{/* react-router Outlet 渲染当前路由内容 */} - + + +
diff --git a/src/shell/TabTitleContext.ts b/src/shell/TabTitleContext.ts new file mode 100644 index 0000000..a7dc613 --- /dev/null +++ b/src/shell/TabTitleContext.ts @@ -0,0 +1,16 @@ +// F2-13:Tab 标题回填 Context +// PageRenderPage 拉到 schema 后调 updateTabTitle 把真实标题写回 TabBar。 +import { createContext, useContext } from 'react'; + +export interface TabTitleContextValue { + /** 将指定路由路径对应的 Tab 标题更新为 title */ + updateTabTitle: (path: string, title: string) => void; +} + +export const TabTitleContext = createContext({ + updateTabTitle: () => undefined, +}); + +export function useTabTitle() { + return useContext(TabTitleContext); +}