Files
monkey-ai-web/src/components/console/consoleRoutes.js
T

151 lines
5.1 KiB
JavaScript

/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
For commercial licensing, please contact support@quantumnous.com
*/
// Presentation metadata only. Route guards and feature visibility remain in App/SiderBar.
export const consolePages = [
{
key: 'analytics',
menuKey: 'detail',
title: '数据看板',
description: 'analytics',
},
{ key: 'monitor', title: '监控中心', description: 'monitor' },
{ key: 'channel', title: '渠道管理', description: 'channel' },
{
key: 'token',
menuKey: 'admin-token',
title: '密钥管理',
description: 'token',
},
{ key: 'models', title: '模型管理', description: 'models' },
{ key: 'user', title: '用户管理', description: 'user' },
{ key: 'redemption', title: '兑换码管理', description: 'redemption' },
{ key: 'topup', title: '钱包管理', description: 'topup' },
{ key: 'log', title: '使用日志', description: 'log' },
{ key: 'midjourney', title: '绘图日志', description: 'midjourney' },
{ key: 'task', title: '任务日志', description: 'task' },
{ key: 'organizations', title: '企业管理', description: 'organizations' },
{ key: 'order', title: '订单管理', description: 'order' },
{ key: 'invoice', title: '发票管理', description: 'invoice' },
{ key: 'subscription', title: '会员卡管理', description: 'subscription' },
{ key: 'setting', title: '系统设置', description: 'setting' },
{ key: 'website-setting', title: '官网设置', description: 'website-setting' },
{
key: 'demo-reservations',
title: '预约演示',
description: 'demo-reservations',
},
{ key: 'personal', title: '个人设置', description: 'personal' },
{ key: 'my-commission', title: '我的提成', description: 'my-commission' },
{ key: 'partner', title: '合作伙伴', description: 'partner' },
{
key: 'skill-platform',
title: '平台 Skill 中心',
description: 'skill-platform',
},
{
key: 'expert-platform',
title: '专家与模型能力',
description: 'expert-platform',
},
{
key: 'playground',
title: '在线调试',
description: 'playground',
canvas: true,
},
{
key: 'chat',
title: '聊天',
description: 'chat',
canvas: true,
dynamicChildTitle: '详情',
},
].map((page) => ({ ...page, path: `/console/${page.key}` }));
export function isNavigationPathActive(pathname, prefix) {
if (!prefix) return false;
if (prefix === '/') return pathname === '/';
const normalized = prefix.replace(/\/+$/, '');
return pathname === normalized || pathname.startsWith(`${normalized}/`);
}
const normalizePath = (pathname) =>
(pathname || '/console').split(/[?#]/)[0].replace(/\/+$/, '') || '/';
function segmentTitle(segment) {
const actions = { edit: '编辑', new: '新建', create: '新建', detail: '详情' };
if (actions[segment]) return actions[segment];
if (/^\d+$/.test(segment)) return '详情';
try {
return decodeURIComponent(segment).replace(/[-_]/g, ' ');
} catch {
return segment;
}
}
export function resolveConsolePage(pathname, pages = consolePages) {
const path = normalizePath(pathname);
const page = [...pages]
.sort((a, b) => b.path.length - a.path.length)
.find((item) => isNavigationPathActive(path, item.path));
const root = { path: '/console', title: '控制台' };
const matched = pages
.filter((item) => isNavigationPathActive(path, item.path))
.sort((a, b) => a.path.length - b.path.length);
const breadcrumbs = [
root,
...matched.map(({ path, title }) => ({ path, title })),
];
const basePath = page?.path || root.path;
const segments = path.slice(basePath.length).split('/').filter(Boolean);
let currentPath = basePath;
for (const [index, segment] of segments.entries()) {
currentPath += `/${segment}`;
breadcrumbs.push({
path: currentPath,
title:
index === 0 && page?.dynamicChildTitle
? page.dynamicChildTitle
: segmentTitle(segment),
});
}
return {
...(page || { key: 'fallback', description: 'fallback' }),
title: breadcrumbs.at(-1).title,
path,
breadcrumbs,
};
}
export const consoleMenuPaths = Object.fromEntries(
consolePages.flatMap((page) =>
[...new Set([page.menuKey || page.key, page.key])].map((key) => [
key,
page.path,
]),
),
);
export function getConsoleMenuKeys(pathname, paths = consoleMenuPaths) {
if (!pathname) return [];
const path = normalizePath(pathname);
return Object.keys(paths).filter((key) => paths[key] === path);
}