Files
creator-hub/web/src/utils/metadata.tsx
T
rogee ebd99f91d2
douyin-release-gate / verify (push) Failing after 3m51s
fix(web): 侧栏选中精确匹配、页头标题左对齐、添加按钮移至标题行、工作台补内容区 Card
- ProLayout 默认按路径前缀高亮菜单(/accounts 与 /accounts/import 同时选中),改为受控 selectedKeys(metadata.menuSelectedKey 最长前缀精确匹配,详情页回落父级)
- 页面标题/副标题从 PageContainer extra(右上)移到 title 槽(左上),动作按钮经 PageActions Context 渲染到 extra 与标题同行
- 新增 web/src/components/PageActions.tsx;账号导入/我的账号/监控账号/运行环境/网关/网络出口 六处列表页注册各自按钮并移除卡内独占行(重复副标题的小字提示一并移除)
- 运营工作台根节点包 Card variant=outlined,operations 标签页去掉冗余内层 Card
- dashboard 移除内层 PageContainer,避免与全局页头双标题
2026-09-23 11:21:28 +08:00

91 lines
6.1 KiB
TypeScript

import type { MenuDataItem } from '@ant-design/pro-components';
import {
CloudDownloadOutlined,
UserOutlined,
EyeOutlined,
LineChartOutlined,
CommentOutlined,
SettingOutlined,
ProfileOutlined,
LaptopOutlined,
ClusterOutlined,
GatewayOutlined,
DashboardOutlined,
} from '@ant-design/icons';
// 页头标题/副标题规则:语义对齐 web.archived/src/app/Layout.jsx 的 pageMetadataRules。
const rules: Array<{ test: (path: string) => boolean; title: string; subtitle: string }> = [
{ test: (p) => p === '/' || p === '/dashboard', title: '工作台', subtitle: '运营概况与快捷入口。' },
{ test: (p) => p === '/accounts/import', title: '账号导入', subtitle: '管理分享链接解析任务,解析成功后自动加入监控账号。' },
{ test: (p) => p === '/accounts', title: '我的账号', subtitle: '创建和管理自己维护的账号。' },
{ test: (p) => p === '/accounts/monitoring', title: '监控账号', subtitle: '管理需要持续跟踪的竞品账号及采集状态。' },
{ test: (p) => p === '/accounts/new', title: '创建社媒账号', subtitle: '创建账号后,再在编辑页配置登录身份与账号策略。' },
{ test: (p) => /\/edit$/.test(p) && p.startsWith('/accounts/'), title: '编辑社媒账号', subtitle: '维护账号资料、登录核验与自动响应策略。' },
{ test: (p) => p.startsWith('/accounts/'), title: '账号详情', subtitle: '查看账号状态、登录身份与运行环境绑定。' },
{ test: (p) => p === '/creator/competitors', title: '竞品分析', subtitle: '查看竞品作品与指标,分享链接导入请前往账号导入。' },
{ test: (p) => p === '/creator/workbench', title: '运营工作台', subtitle: '评论、线索、私信与写操作均保留来源和明确结果。' },
{ test: (p) => p === '/creator/settings', title: '采集设置', subtitle: '统一配置采集窗口、指标采集和已批准的服务。' },
{ test: (p) => p === '/competitors' || p.startsWith('/competitors/'), title: '竞品分析', subtitle: '粘贴作品分享内容,自动识别作者并加入监听队列。' },
{ test: (p) => p.startsWith('/drafts/'), title: '草稿核对', subtitle: '核对版本化草稿,确认后再将操作加入队列。' },
{ test: (p) => p.startsWith('/attempts/'), title: 'Attempt 详情', subtitle: '查看执行结果、运行环境与网络出口。' },
{ test: (p) => p === '/tasks', title: '任务中心', subtitle: '逐条处理暂停、版本变化与未知执行结果。' },
{ test: (p) => p.startsWith('/tasks/'), title: '任务详情', subtitle: '查看任务状态、执行结果与允许的下一步操作。' },
{ test: (p) => p === '/browsers', title: '运行环境', subtitle: '启动、停止并回收隔离的指纹浏览器运行环境。' },
{ test: (p) => p === '/browsers/new', title: '创建运行环境', subtitle: '为已授权且暂停的账号绑定网关、指纹与网络出口。' },
{ test: (p) => p.startsWith('/browsers/'), title: '运行环境详情', subtitle: '查看环境状态、账号绑定和运行实例信息。' },
{ test: (p) => p === '/network-exits', title: '网络出口', subtitle: '维护固定出口、健康观测与账号绑定。' },
{ test: (p) => p.startsWith('/network-exits/'), title: '网络出口详情', subtitle: '查看出口配置、健康状态和绑定关系。' },
{ test: (p) => p === '/gateways', title: '网关管理', subtitle: '注册并检查宿主机 native browser gateway。' },
{ test: (p) => p.startsWith('/gateways/'), title: '网关详情', subtitle: '查看网关连接信息和运行状态。' },
];
// 菜单结构:工作台置顶(对标 pro 官方 workplace 预览),其余与 web.archived/src/app/Layout.jsx 一致(运营 / 资源 两组);
// icon 选用 antd 图标库里语义常见、用户一眼可识别的隐喻。
export const menu: MenuDataItem[] = [
{ path: '/dashboard', name: '工作台', icon: <DashboardOutlined /> },
{
name: '运营',
children: [
{ path: '/accounts/import', name: '账号导入', icon: <CloudDownloadOutlined /> },
{ path: '/accounts', name: '我的账号', icon: <UserOutlined /> },
{ path: '/accounts/monitoring', name: '监控账号', icon: <EyeOutlined /> },
{ path: '/creator/competitors', name: '竞品分析', icon: <LineChartOutlined /> },
{ path: '/creator/workbench', name: '运营工作台', icon: <CommentOutlined /> },
{ path: '/creator/settings', name: '采集设置', icon: <SettingOutlined /> },
{ path: '/tasks', name: '任务中心', icon: <ProfileOutlined /> },
],
},
{
name: '资源',
children: [
{ path: '/browsers', name: '运行环境', icon: <LaptopOutlined /> },
{ path: '/network-exits', name: '网络出口', icon: <ClusterOutlined /> },
{ path: '/gateways', name: '网关管理', icon: <GatewayOutlined /> },
],
},
];
export function pageMetadata(pathname: string): { title: string; subtitle: string } {
const matched = rules.find((item) => item.test(pathname));
if (matched) return { title: matched.title, subtitle: matched.subtitle };
for (const group of menu) {
const hit = (group.children ?? []).find((item) => item.path && (pathname === item.path || pathname.startsWith(`${item.path}/`)));
if (hit) return { title: hit.name ?? '', subtitle: 'CreatorHub 运营控制台' };
}
return { title: 'CreatorHub', subtitle: '运营控制台' };
}
export function menuSelectedKey(pathname: string): string {
const leafPaths = menu.flatMap((group) => (group.children ?? []).map((item) => item.path ?? ''));
const segments = pathname.split('/').filter(Boolean);
for (let i = segments.length; i >= 1; i--) {
const candidate = `/${segments.slice(0, i).join('/')}`;
if (leafPaths.includes(candidate)) return candidate;
}
return pathname;
}
// 侧栏选中态:ProLayout 默认按路径前缀高亮(/accounts 是 /accounts/import 的前缀,两项会同时高亮)。
// 这里改为受控 selectedKeys:从完整路径逐段向前回退,仅精确命中菜单叶路径;
// 详情页(如 /accounts/123、/accounts/new)回落到父级菜单项。