cb9d836227
集中保留原版权声明,移除文件头检查和全局测试忽略规则。验证:全量单测、受影响用例复测及静态检查通过。
72 lines
2.4 KiB
React
72 lines
2.4 KiB
React
import React, { useMemo, useState } from 'react';
|
|
import { createPortal } from 'react-dom';
|
|
import { Breadcrumb } from 'antd';
|
|
import { Link, useLocation } from 'react-router-dom';
|
|
import { useTranslation } from 'react-i18next';
|
|
import {
|
|
ConsoleContext,
|
|
useConsolePage,
|
|
useConsoleThemeStyle,
|
|
} from './ConsoleContext';
|
|
import { resolveConsolePage } from './consoleRoutes';
|
|
import './console.css';
|
|
|
|
export default function ConsolePageContainer({ children }) {
|
|
const { pathname } = useLocation();
|
|
const { t } = useTranslation();
|
|
const themeStyle = useConsoleThemeStyle();
|
|
const page = useMemo(() => resolveConsolePage(pathname), [pathname]);
|
|
const [actionsTarget, setActionsTarget] = useState(null);
|
|
const context = useMemo(
|
|
() => ({ page, actionsTarget }),
|
|
[page, actionsTarget],
|
|
);
|
|
|
|
return (
|
|
<ConsoleContext.Provider value={context}>
|
|
<main
|
|
className={`console-page${page.canvas ? ' console-page--canvas' : ''}`}
|
|
data-console-page={page.key}
|
|
style={themeStyle}
|
|
>
|
|
<header
|
|
className={`console-page-header${page.hideHeading ? ' console-page-header--crumb-only' : ''}`}
|
|
>
|
|
<Breadcrumb
|
|
className='console-breadcrumb'
|
|
items={page.breadcrumbs.map((item, index) => ({
|
|
key: item.path,
|
|
title:
|
|
index === page.breadcrumbs.length - 1 ? (
|
|
<span aria-current='page'>{t(item.title)}</span>
|
|
) : (
|
|
<Link to={item.path}>{t(item.title)}</Link>
|
|
),
|
|
}))}
|
|
/>
|
|
{!page.hideHeading && (
|
|
<div className='console-page-header-main'>
|
|
<div className='console-page-heading'>
|
|
<h1 className='console-page-title'>{t(page.title)}</h1>
|
|
<p className='console-page-description'>
|
|
{t(`consoleUi.descriptions.${page.description}`)}
|
|
</p>
|
|
</div>
|
|
<div className='console-page-actions' ref={setActionsTarget} />
|
|
</div>
|
|
)}
|
|
</header>
|
|
<div className='console-page-body'>{children}</div>
|
|
</main>
|
|
</ConsoleContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function ConsolePageActions({ children }) {
|
|
const context = useConsolePage();
|
|
if (!context) return <>{children}</>;
|
|
return context.actionsTarget
|
|
? createPortal(children, context.actionsTarget)
|
|
: null;
|
|
}
|