690 lines
23 KiB
React
690 lines
23 KiB
React
import { consoleMenuPaths, getConsoleMenuKeys } from '../console/consoleRoutes';
|
||
import React, { useContext, useEffect, useMemo, useState } from 'react';
|
||
import { useLocation } from 'react-router-dom';
|
||
import { useTranslation } from 'react-i18next';
|
||
import { getLucideIcon } from '../../helpers/render';
|
||
import '../../styles/center-layout.css';
|
||
import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed';
|
||
import { useSidebarNavigation } from '../../hooks/common/useTopNavigation';
|
||
import { useSidebarGroups } from '../../hooks/common/useSidebarGroups';
|
||
import { useSidebar } from '../../hooks/common/useSidebar';
|
||
import { usePartnerWorkspaceEntry } from '../../hooks/common/usePartnerWorkspaceEntry';
|
||
import { isAdmin, isRoot, showError } from '../../helpers';
|
||
import {
|
||
isMiniProgramPaymentPath,
|
||
isMiniProgramWebView,
|
||
} from '../../helpers/miniProgram';
|
||
import { StatusContext } from '../../context/Status';
|
||
import { UserContext } from '../../context/User';
|
||
import {
|
||
canAccessDelegatedAdminPage,
|
||
getDelegatedSettingTabs,
|
||
} from '../../helpers/adminDelegation';
|
||
import {
|
||
loadPersonalConsentGranted,
|
||
readPersonalConsentCache,
|
||
} from '../smart-router/api';
|
||
import {
|
||
CenterSidebar,
|
||
CenterSidebarGroup,
|
||
CenterSidebarItem,
|
||
CenterSidebarSubmenu,
|
||
} from './components/CenterSidebar';
|
||
import { CenterSidebarLoading } from './components/CenterSidebarLoading';
|
||
import { CLOUD_BRAIN_UI_ENABLED } from '../../config/cloudBrainUi';
|
||
import { useAuthzView, usePerm } from '../../authz';
|
||
|
||
const routerMap = {
|
||
home: '/',
|
||
...consoleMenuPaths,
|
||
about: '/about',
|
||
pricing: '/market',
|
||
// weiyuan 新增入口:consoleRoutes 未登记的路由在此补齐(智能路由、分佣管理子菜单)
|
||
'smart-router': '/console/smart-router',
|
||
commission: '/console/commission',
|
||
// 新版分佣使用控制台主侧栏展开子菜单,子项沿用现有 view 路由。
|
||
'commission-overview': '/console/commission?view=overview',
|
||
'commission-partners': '/console/commission?view=partners',
|
||
'commission-assignments': '/console/commission?view=assignments',
|
||
'commission-tiers': '/console/commission?view=tiers',
|
||
'commission-adjustments': '/console/commission?view=adjustments',
|
||
'commission-bills': '/console/commission?view=bills',
|
||
'commission-exceptions': '/console/commission?view=exceptions',
|
||
'commission-audit': '/console/commission?view=audit',
|
||
};
|
||
|
||
// forceExpanded:手机端抽屉态。抽屉本来就是临时全宽浮层,折叠成 60px 图标条毫无意义,
|
||
// 且不应把桌面端的折叠偏好一起改掉,所以只在本次渲染里强制展开。
|
||
const SiderBar = ({ onNavigate = () => {}, forceExpanded = false }) => {
|
||
const { t } = useTranslation();
|
||
const [persistedCollapsed, toggleCollapsed] = useSidebarCollapsed();
|
||
const collapsed = forceExpanded ? false : persistedCollapsed;
|
||
const followSidebarLink = useSidebarNavigation(onNavigate);
|
||
const {
|
||
isModuleVisible,
|
||
hasSectionVisibleModules,
|
||
loading: sidebarLoading,
|
||
} = useSidebar();
|
||
|
||
const [statusState] = useContext(StatusContext);
|
||
const showPartnerWorkspace = usePartnerWorkspaceEntry();
|
||
const [userState] = useContext(UserContext);
|
||
const delegatedPermissions = statusState?.status?.AdminDelegatedSettingTabs;
|
||
// 系统设置 tab 权限下放:普通管理员在被下放了至少一个 tab 时,才显示「系统设置」入口
|
||
const delegatedSettingTabs = useMemo(
|
||
() => getDelegatedSettingTabs(delegatedPermissions),
|
||
[delegatedPermissions],
|
||
);
|
||
const canAccessSetting =
|
||
isRoot() || (isAdmin() && delegatedSettingTabs.length > 0);
|
||
const commissionEnabled = statusState?.status?.commission_enabled !== false;
|
||
|
||
// 权限管理分组:模块切到新体系后按权限点判断,切换前只有 root 可见(legacy = isRoot())
|
||
const canAuthzMenu = usePerm('platform.authz.menu.query', isRoot());
|
||
const canAuthzRole = usePerm('platform.authz.role.query', isRoot());
|
||
const canAuthzPackage = usePerm('platform.authz.package.query', isRoot());
|
||
const canAuthzTemplate = usePerm('platform.authz.template.query', isRoot());
|
||
|
||
// 新旧双路径(与路由守卫 ConsoleRoute 同口径):菜单所属模块已切到新体系时按权限点决定是否显示,
|
||
// 返回 true / false;未切换(或权限视图未到达)返回 null,调用方沿用原判断。
|
||
// 菜单管理里把菜单设为不显示时(visible=false)同样隐藏。
|
||
const platformView = useAuthzView('platform');
|
||
const permVisible = useMemo(() => {
|
||
if (!platformView) return () => null;
|
||
const hidden = new Set(
|
||
(platformView.menus || []).filter((m) => !m.visible).map((m) => m.code),
|
||
);
|
||
return (code) => {
|
||
const mod = code ? platformView.moduleOf[code] : '';
|
||
if (!mod || !platformView.enforcedSet.has(mod)) return null;
|
||
return platformView.permSet.has(code) && !hidden.has(code);
|
||
};
|
||
}, [platformView]);
|
||
|
||
const [selectedKeys, setSelectedKeys] = useState(['home']);
|
||
// 平台关闭智能路由后,仍有生效中出境同意的普通用户保留入口以便撤回(§9.5,与企业"仅授权模式"同口径)
|
||
const [routerConsentGranted, setRouterConsentGranted] = useState(
|
||
() => readPersonalConsentCache() === '1',
|
||
);
|
||
const smartRouterEnabled = statusState?.status?.smart_router_enabled;
|
||
useEffect(() => {
|
||
if (smartRouterEnabled !== false || isAdmin()) return;
|
||
if (!localStorage.getItem('user')) return; // 未登录不请求,避免 401 跳转
|
||
if (readPersonalConsentCache() !== null) return;
|
||
let alive = true;
|
||
loadPersonalConsentGranted()
|
||
.then((granted) => {
|
||
if (alive) setRouterConsentGranted(granted);
|
||
})
|
||
.catch(() => {});
|
||
return () => {
|
||
alive = false;
|
||
};
|
||
}, [smartRouterEnabled]);
|
||
const [chatItems, setChatItems] = useState([]);
|
||
const submenus = useSidebarGroups();
|
||
const groups = useSidebarGroups();
|
||
const { setGroup: setSubmenu } = submenus;
|
||
const location = useLocation();
|
||
const [routerMapState, setRouterMapState] = useState(routerMap);
|
||
|
||
const dataExportFlag = localStorage.getItem('enable_data_export');
|
||
const drawingFlag = localStorage.getItem('enable_drawing');
|
||
const taskFlag = localStorage.getItem('enable_task');
|
||
const workspaceItems = useMemo(() => {
|
||
const items = [
|
||
{
|
||
text: t('数据看板'),
|
||
itemKey: 'detail',
|
||
to: '/detail',
|
||
className: dataExportFlag === 'true' ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('密钥管理'),
|
||
itemKey: 'token',
|
||
to: '/token',
|
||
},
|
||
{
|
||
text: t('使用日志'),
|
||
itemKey: 'log',
|
||
to: '/log',
|
||
perm: 'platform.log',
|
||
},
|
||
{
|
||
text: t('绘图日志'),
|
||
itemKey: 'midjourney',
|
||
to: '/midjourney',
|
||
perm: 'platform.drawing_log',
|
||
className: drawingFlag === 'true' ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('任务日志'),
|
||
itemKey: 'task',
|
||
to: '/task',
|
||
perm: 'platform.task_log',
|
||
className: taskFlag === 'true' ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('监控中心'),
|
||
itemKey: 'monitor',
|
||
to: '/monitor',
|
||
perm: 'platform.monitor',
|
||
},
|
||
{
|
||
// 智能路由:已登记在 sidebarModules 注册表(console.smart-router),管理员可隐藏
|
||
text: t('智能路由'),
|
||
itemKey: 'smart-router',
|
||
to: '/console/smart-router',
|
||
},
|
||
];
|
||
|
||
// 根据配置过滤项目
|
||
const filteredItems = items.filter((item) => {
|
||
// 智能路由:管理员始终可见(全局设置在该页),普通用户在平台开启后才显示,
|
||
// 避免升级后所有用户突然多出一个尚未启用的入口
|
||
if (
|
||
item.itemKey === 'smart-router' &&
|
||
!isAdmin() &&
|
||
smartRouterEnabled !== true &&
|
||
!routerConsentGranted
|
||
)
|
||
return false;
|
||
const configVisible = isModuleVisible('console', item.itemKey);
|
||
// 已切换模块:还须持有对应菜单权限点
|
||
return configVisible && permVisible(item.perm) !== false;
|
||
});
|
||
|
||
return filteredItems;
|
||
}, [
|
||
smartRouterEnabled,
|
||
routerConsentGranted,
|
||
dataExportFlag,
|
||
drawingFlag,
|
||
taskFlag,
|
||
t,
|
||
isModuleVisible,
|
||
permVisible,
|
||
]);
|
||
|
||
const financeItems = useMemo(() => {
|
||
const items = [
|
||
{
|
||
text: t('钱包管理'),
|
||
itemKey: 'topup',
|
||
to: '/topup',
|
||
perm: 'platform.topup',
|
||
},
|
||
{
|
||
text: t('个人设置'),
|
||
itemKey: 'personal',
|
||
to: '/personal',
|
||
},
|
||
];
|
||
|
||
// 根据配置过滤项目
|
||
const filteredItems = items.filter((item) => {
|
||
const configVisible = isModuleVisible('personal', item.itemKey);
|
||
// WeyAi 小程序里不出现付费入口(helpers/miniProgram.js)。
|
||
if (isMiniProgramWebView() && isMiniProgramPaymentPath(item.to)) {
|
||
return false;
|
||
}
|
||
return configVisible && permVisible(item.perm) !== false;
|
||
});
|
||
|
||
// 与顶栏和伙伴页面共用新版伙伴权限判断,避免无权限账号误入。
|
||
if (showPartnerWorkspace) {
|
||
filteredItems.push({
|
||
text: t('我的提成'),
|
||
itemKey: 'my-commission',
|
||
});
|
||
}
|
||
|
||
return filteredItems;
|
||
}, [t, isModuleVisible, showPartnerWorkspace, permVisible]);
|
||
|
||
const adminItems = useMemo(() => {
|
||
const items = [
|
||
{
|
||
text: t('运营看板'),
|
||
itemKey: 'analytics',
|
||
perm: 'platform.analytics',
|
||
className: isAdmin() ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('分佣管理'),
|
||
itemKey: 'commission',
|
||
perm: 'platform.commission',
|
||
items: [
|
||
{ text: t('分佣工作台'), itemKey: 'commission-overview' },
|
||
{ text: t('合作伙伴'), itemKey: 'commission-partners' },
|
||
{ text: t('客户归属'), itemKey: 'commission-assignments' },
|
||
{ text: t('分佣档位'), itemKey: 'commission-tiers' },
|
||
{ text: t('调整单'), itemKey: 'commission-adjustments' },
|
||
{ text: t('销售提成'), itemKey: 'commission-bills' },
|
||
{ text: t('异常中心'), itemKey: 'commission-exceptions' },
|
||
{ text: t('分佣审计日志'), itemKey: 'commission-audit' },
|
||
],
|
||
className: isRoot() ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('渠道管理'),
|
||
itemKey: 'channel',
|
||
perm: 'platform.channel',
|
||
to: '/channel',
|
||
className: isAdmin() ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('模型管理'),
|
||
itemKey: 'models',
|
||
perm: 'platform.model',
|
||
className: isAdmin() ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('兑换码管理'),
|
||
itemKey: 'redemption',
|
||
perm: 'platform.redemption',
|
||
to: '/redemption',
|
||
className: isAdmin() ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('用户管理'),
|
||
itemKey: 'user',
|
||
perm: 'platform.user',
|
||
to: '/user',
|
||
className: isAdmin() ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('会员卡管理'),
|
||
itemKey: 'subscription',
|
||
perm: 'platform.subscription',
|
||
className: isAdmin() ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('密钥管理'),
|
||
itemKey: 'admin-token',
|
||
perm: 'platform.admin_token',
|
||
className: isAdmin() ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('企业管理'),
|
||
itemKey: 'organizations',
|
||
perm: 'platform.org',
|
||
className: isAdmin() ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('平台 Skill 中心'),
|
||
itemKey: 'skill-platform',
|
||
perm: 'platform.skill',
|
||
className: isAdmin() ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('平台专家中心'),
|
||
itemKey: 'expert-platform',
|
||
perm: 'platform.expert',
|
||
className: isAdmin() ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('订单管理'),
|
||
itemKey: 'order',
|
||
perm: 'platform.order',
|
||
className: isAdmin() ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('发票管理'),
|
||
itemKey: 'invoice',
|
||
perm: 'platform.invoice',
|
||
className: isAdmin() ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('系统设置'),
|
||
itemKey: 'setting',
|
||
perm: 'platform.setting',
|
||
to: '/setting',
|
||
className: canAccessSetting ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('官网设置'),
|
||
itemKey: 'website-setting',
|
||
perm: 'platform.setting.website_setting',
|
||
className: isAdmin() ? '' : 'tableHiddle',
|
||
},
|
||
{
|
||
text: t('预约演示'),
|
||
itemKey: 'demo-reservations',
|
||
perm: 'platform.setting.demo_reservations',
|
||
className: isAdmin() ? '' : 'tableHiddle',
|
||
},
|
||
];
|
||
|
||
// 根据配置过滤项目
|
||
const filteredItems = items.filter((item) => {
|
||
// 已切换模块:只看权限点(及菜单管理的显示开关),不再看角色与侧栏模块配置——
|
||
// 持有菜单的非管理员也要能看到入口;功能总开关(云端大脑、分佣)仍然生效
|
||
const byPerm = permVisible(item.perm);
|
||
if (byPerm !== null) {
|
||
if (
|
||
!CLOUD_BRAIN_UI_ENABLED &&
|
||
(item.itemKey === 'skill-platform' ||
|
||
item.itemKey === 'expert-platform')
|
||
) {
|
||
return false;
|
||
}
|
||
if (item.itemKey === 'commission' && !commissionEnabled) return false;
|
||
return byPerm;
|
||
}
|
||
if (
|
||
(item.itemKey === 'website-setting' ||
|
||
item.itemKey === 'demo-reservations') &&
|
||
!canAccessDelegatedAdminPage(
|
||
userState?.user?.role,
|
||
delegatedPermissions,
|
||
item.itemKey,
|
||
)
|
||
) {
|
||
return false;
|
||
}
|
||
if (
|
||
!CLOUD_BRAIN_UI_ENABLED &&
|
||
(item.itemKey === 'skill-platform' ||
|
||
item.itemKey === 'expert-platform')
|
||
) {
|
||
return false;
|
||
}
|
||
// 分佣管理:新增模块不在 sidebar 配置注册表内,绕过 isModuleVisible(Root 硬门控)。
|
||
// 分佣总开关关闭时整组隐藏(接口已被后端闸门拦截);旧后端不返回该字段,视为开启。
|
||
// 合并恢复:weiyuan 原逻辑(5e67eff82),合并 SiderBar 时被 ui 过滤函数覆盖丢失
|
||
if (item.itemKey === 'commission') {
|
||
return isRoot() && commissionEnabled;
|
||
}
|
||
// 系统设置入口:被下放了至少一个 tab 的普通管理员强制可见
|
||
// (需绕过 isModuleVisible,因为 GetSelf 默认对普通管理员置 admin.setting=false)。
|
||
// root 及其它情况仍走原有 isModuleVisible 逻辑,保留 root 自行隐藏该入口的能力。
|
||
if (
|
||
item.itemKey === 'setting' &&
|
||
isAdmin() &&
|
||
!isRoot() &&
|
||
delegatedSettingTabs.length > 0
|
||
) {
|
||
return true;
|
||
}
|
||
const configVisible = isModuleVisible('admin', item.itemKey);
|
||
return configVisible;
|
||
});
|
||
|
||
// 已切换模块的菜单按权限点放行,不受原有的角色隐藏(tableHiddle)影响
|
||
return filteredItems.map((item) =>
|
||
permVisible(item.perm) === true ? { ...item, className: '' } : item,
|
||
);
|
||
}, [
|
||
t,
|
||
isModuleVisible,
|
||
permVisible,
|
||
canAccessSetting,
|
||
delegatedSettingTabs,
|
||
delegatedPermissions,
|
||
userState?.user?.role,
|
||
commissionEnabled,
|
||
]);
|
||
|
||
// 非管理员持有已切换模块的菜单时也显示管理员分组
|
||
const visibleAdminItems = adminItems.filter(
|
||
(item) => item.className !== 'tableHiddle',
|
||
);
|
||
|
||
// 权限管理分组:新模块不在 sidebar 配置注册表内,绕过 isModuleVisible,直接按权限点控制显示
|
||
const canAuthzMode = isRoot();
|
||
const authzItems = useMemo(() => {
|
||
const items = [
|
||
{ text: t('菜单管理'), itemKey: 'authz-menus', visible: canAuthzMenu },
|
||
{ text: t('平台角色'), itemKey: 'authz-roles', visible: canAuthzRole },
|
||
{
|
||
text: t('功能套餐'),
|
||
itemKey: 'authz-packages',
|
||
visible: canAuthzPackage,
|
||
},
|
||
{
|
||
text: t('角色模板'),
|
||
itemKey: 'authz-templates',
|
||
visible: canAuthzTemplate,
|
||
},
|
||
{ text: t('运行模式'), itemKey: 'authz-mode', visible: canAuthzMode },
|
||
];
|
||
return items.filter((item) => item.visible);
|
||
}, [
|
||
t,
|
||
canAuthzMenu,
|
||
canAuthzRole,
|
||
canAuthzPackage,
|
||
canAuthzTemplate,
|
||
canAuthzMode,
|
||
]);
|
||
|
||
const chatMenuItems = useMemo(() => {
|
||
const items = [
|
||
{
|
||
text: t('操练场'),
|
||
itemKey: 'playground',
|
||
to: '/playground',
|
||
perm: 'platform.playground',
|
||
},
|
||
{
|
||
text: t('聊天'),
|
||
itemKey: 'chat',
|
||
items: chatItems,
|
||
perm: 'platform.chat',
|
||
},
|
||
];
|
||
|
||
// 根据配置过滤项目
|
||
const filteredItems = items.filter((item) => {
|
||
const configVisible = isModuleVisible('chat', item.itemKey);
|
||
return configVisible && permVisible(item.perm) !== false;
|
||
});
|
||
|
||
return filteredItems;
|
||
}, [chatItems, t, isModuleVisible, permVisible]);
|
||
|
||
// 更新路由映射,添加聊天路由
|
||
const updateRouterMapWithChats = (chats) => {
|
||
const newRouterMap = { ...routerMap };
|
||
|
||
if (Array.isArray(chats) && chats.length > 0) {
|
||
for (let i = 0; i < chats.length; i++) {
|
||
newRouterMap['chat' + i] = '/console/chat/' + i;
|
||
}
|
||
}
|
||
|
||
setRouterMapState(newRouterMap);
|
||
return newRouterMap;
|
||
};
|
||
|
||
// 加载聊天项
|
||
useEffect(() => {
|
||
let chats = localStorage.getItem('chats');
|
||
if (chats) {
|
||
try {
|
||
chats = JSON.parse(chats);
|
||
if (Array.isArray(chats)) {
|
||
let chatItems = [];
|
||
for (let i = 0; i < chats.length; i++) {
|
||
let shouldSkip = false;
|
||
let chat = {};
|
||
for (let key in chats[i]) {
|
||
let link = chats[i][key];
|
||
if (typeof link !== 'string') continue; // 确保链接是字符串
|
||
if (link.startsWith('fluent')) {
|
||
shouldSkip = true;
|
||
break; // 跳过 Fluent Read
|
||
}
|
||
chat.text = key;
|
||
chat.itemKey = 'chat' + i;
|
||
chat.to = '/console/chat/' + i;
|
||
}
|
||
if (shouldSkip || !chat.text) continue; // 避免推入空项
|
||
chatItems.push(chat);
|
||
}
|
||
setChatItems(chatItems);
|
||
updateRouterMapWithChats(chats);
|
||
}
|
||
} catch (e) {
|
||
showError(t('聊天数据解析失败'));
|
||
}
|
||
}
|
||
}, [t]);
|
||
|
||
// 根据当前路径设置选中的菜单项
|
||
useEffect(() => {
|
||
const currentPath = location.pathname;
|
||
if (currentPath === '/console/commission') {
|
||
const view =
|
||
new URLSearchParams(location.search).get('view') || 'overview';
|
||
const childKey = `commission-${view}`;
|
||
const validChildKeys = [
|
||
'commission-overview',
|
||
'commission-partners',
|
||
'commission-assignments',
|
||
'commission-tiers',
|
||
'commission-adjustments',
|
||
'commission-bills',
|
||
'commission-exceptions',
|
||
'commission-audit',
|
||
];
|
||
setSelectedKeys([
|
||
validChildKeys.includes(childKey) ? childKey : 'commission-overview',
|
||
]);
|
||
setSubmenu('commission', true);
|
||
return;
|
||
}
|
||
let matchingKeys = getConsoleMenuKeys(currentPath, routerMapState);
|
||
|
||
// 处理聊天路由
|
||
if (!matchingKeys.length && currentPath.startsWith('/console/chat/')) {
|
||
const chatIndex = currentPath.split('/').pop();
|
||
if (!isNaN(chatIndex)) {
|
||
matchingKeys = ['chat' + chatIndex];
|
||
} else {
|
||
matchingKeys = ['chat'];
|
||
}
|
||
}
|
||
|
||
// 如果找到匹配的键,更新选中的键
|
||
if (matchingKeys.length) {
|
||
setSelectedKeys(matchingKeys);
|
||
}
|
||
}, [location.pathname, location.search, routerMapState, setSubmenu]);
|
||
|
||
const renderMenuIcon = (key) =>
|
||
React.cloneElement(getLucideIcon(key), {
|
||
size: 16,
|
||
strokeWidth: 1.5,
|
||
color: 'currentColor',
|
||
className: undefined,
|
||
'aria-hidden': true,
|
||
});
|
||
|
||
const renderGroup = (key, label, items) => (
|
||
<CenterSidebarGroup
|
||
key={key}
|
||
label={label}
|
||
collapsed={collapsed}
|
||
folded={groups.keys.includes(key)}
|
||
onToggle={() => groups.toggle(key)}
|
||
>
|
||
{items}
|
||
</CenterSidebarGroup>
|
||
);
|
||
|
||
const renderNavItem = (
|
||
item,
|
||
{ nested = false, forceActive = false } = {},
|
||
) => {
|
||
if (item.className === 'tableHiddle') return null;
|
||
const to = routerMapState[item.itemKey] || routerMap[item.itemKey] || '#';
|
||
return (
|
||
<CenterSidebarItem
|
||
key={item.itemKey}
|
||
to={to}
|
||
label={item.text}
|
||
active={forceActive || selectedKeys.includes(item.itemKey)}
|
||
collapsed={collapsed}
|
||
nested={nested}
|
||
icon={!nested && renderMenuIcon(item.itemKey)}
|
||
onClick={(event) => followSidebarLink(to, event)}
|
||
/>
|
||
);
|
||
};
|
||
|
||
const renderSubItem = (item) => {
|
||
if (!item.items?.length) return renderNavItem(item);
|
||
const childActive = item.items.some((child) =>
|
||
selectedKeys.includes(child.itemKey),
|
||
);
|
||
if (collapsed) return renderNavItem(item, { forceActive: childActive });
|
||
|
||
return (
|
||
<CenterSidebarSubmenu
|
||
key={item.itemKey}
|
||
label={item.text}
|
||
icon={renderMenuIcon(item.itemKey)}
|
||
open={submenus.keys.includes(item.itemKey)}
|
||
childActive={childActive}
|
||
onToggle={() => submenus.toggle(item.itemKey)}
|
||
>
|
||
{item.items.map((child) => renderNavItem(child, { nested: true }))}
|
||
</CenterSidebarSubmenu>
|
||
);
|
||
};
|
||
|
||
if (sidebarLoading)
|
||
return (
|
||
<CenterSidebarLoading variant='console' forceExpanded={forceExpanded} />
|
||
);
|
||
|
||
return (
|
||
<CenterSidebar
|
||
className='ui-console-sidebar'
|
||
collapsed={collapsed}
|
||
mobile={forceExpanded}
|
||
onToggle={toggleCollapsed}
|
||
>
|
||
{/* 聊天区域 */}
|
||
{hasSectionVisibleModules('chat') &&
|
||
renderGroup('chat-group', t('聊天'), chatMenuItems.map(renderSubItem))}
|
||
|
||
{/* 控制台区域 */}
|
||
{hasSectionVisibleModules('console') &&
|
||
renderGroup(
|
||
'console-group',
|
||
t('控制台'),
|
||
workspaceItems.map((item) => renderNavItem(item)),
|
||
)}
|
||
|
||
{/* 个人中心区域 */}
|
||
{hasSectionVisibleModules('personal') &&
|
||
renderGroup(
|
||
'personal-group',
|
||
t('个人中心'),
|
||
financeItems.map((item) => renderNavItem(item)),
|
||
)}
|
||
|
||
{/* 管理员区域:按角色、权限下放及菜单配置过滤。分佣管理为子菜单,走 renderSubItem。 */}
|
||
{(isAdmin() || visibleAdminItems.length > 0) &&
|
||
renderGroup(
|
||
'admin-group',
|
||
t('管理员'),
|
||
visibleAdminItems.map(renderSubItem),
|
||
)}
|
||
|
||
{/* 权限管理区域:至少有一项可见时显示 */}
|
||
{authzItems.length > 0 &&
|
||
renderGroup(
|
||
'authz-group',
|
||
t('权限管理'),
|
||
authzItems.map((item) => renderNavItem(item)),
|
||
)}
|
||
</CenterSidebar>
|
||
);
|
||
};
|
||
|
||
export default SiderBar;
|