feat: 恢复服务监控菜单入口

This commit is contained in:
zhanjunhao
2026-11-19 10:59:02 +08:00
parent 001fbac538
commit daf20157ce
6 changed files with 219 additions and 54 deletions
+6
View File
@@ -29,6 +29,12 @@ export const isGroupAllowed = (groups, userGroup) => {
return allowedGroups.includes(getEffectiveUserGroup(userGroup));
};
export const isSidebarModuleVisible = (config, key, userGroup) =>
config?.enabled !== false &&
config?.[key] !== false &&
isGroupAllowed(config?.groups, userGroup) &&
isGroupAllowed(config?.moduleGroups?.[key], userGroup);
export const isHeaderActionButtonVisible = (config, key, userGroup) => {
let buttons = config;
+9 -47
View File
@@ -41,7 +41,8 @@ import {
} from 'lucide-react';
import { StatusContext } from '../../context/Status';
import { UserContext } from '../../context/User';
import { isGroupAllowed } from '../../helpers/navigationVisibility';
import { isSidebarModuleVisible } from '../../helpers/navigationVisibility';
import { normalizeSidebarModulesAdmin } from '../../constants/sidebarModules';
import { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed';
import { useWeyAiDownloadEntry } from '../../hooks/common/useWeyAiWebEntry';
@@ -57,47 +58,12 @@ const UserCenterSidebar = () => {
const { visible: weyaiDownloadEnabled } = useWeyAiDownloadEntry();
// 获取侧边栏配置
const sidebarConfig = useMemo(() => {
const defaultConfig = {
enabled: true,
groups: [],
moduleGroups: {},
dashboard: true,
usageRecord: true,
serviceDashboard: true,
topup: true,
invoice: true,
invite: true,
settings: true,
};
try {
const configStr = statusState?.status?.SidebarModulesAdmin;
if (configStr) {
const config = JSON.parse(configStr);
const uc = config.userCenter || {};
// 向后兼容:只有旧配置同时隐藏了 usageLog 和 taskLog,才隐藏合并后的 usageRecord;
// 只隐藏其中之一时保持显示,避免用户意外失去本应可见的日志入口
if (
uc.usageRecord === undefined &&
uc.usageLog === false &&
uc.taskLog === false
) {
uc.usageRecord = false;
}
const merged = { ...defaultConfig, ...uc };
return {
...merged,
enabled:
merged.enabled !== false &&
isGroupAllowed(merged.groups, userGroup),
};
}
} catch (error) {
// 使用默认配置
}
return defaultConfig;
}, [statusState?.status?.SidebarModulesAdmin, userGroup]);
const sidebarConfig = useMemo(
() =>
normalizeSidebarModulesAdmin(statusState?.status?.SidebarModulesAdmin)
.userCenter,
[statusState?.status?.SidebarModulesAdmin],
);
// 统一单一品牌色高亮(云平台风格):菜单项不再各用一种颜色,
// 激活态统一走 brand(azure),非激活中性灰,靠图标本身区分功能。
@@ -175,11 +141,7 @@ const UserCenterSidebar = () => {
const inMiniProgram = isMiniProgramWebView();
return allItems.filter(
(item) =>
sidebarConfig[item.configKey] !== false &&
isGroupAllowed(
sidebarConfig.moduleGroups?.[item.configKey],
userGroup,
) &&
isSidebarModuleVisible(sidebarConfig, item.configKey, userGroup) &&
!(inMiniProgram && isMiniProgramPaymentPath(item.itemKey)),
);
}, [allItems, sidebarConfig, userGroup]);
+9 -4
View File
@@ -37,6 +37,8 @@ import {
Receipt,
} from 'lucide-react';
import { StatusContext } from '../../context/Status';
import { UserContext } from '../../context/User';
import { isSidebarModuleVisible } from '../../helpers/navigationVisibility';
import { useMarquee } from '../../hooks/common/useMarquee';
import PageBackground from '../../components/common/PageBackground';
import UserCenterSidebar from './UserCenterSidebar';
@@ -61,6 +63,8 @@ const MobileBottomNav = ({ sidebarConfig }) => {
const { t } = useTranslation();
const location = useLocation();
const navigate = useNavigate();
const [userState] = useContext(UserContext);
const userGroup = userState?.user?.group;
const navItems = [
{
@@ -116,8 +120,7 @@ const MobileBottomNav = ({ sidebarConfig }) => {
const inMiniProgram = isMiniProgramWebView();
const visibleNavItems = navItems.filter(
(item) =>
sidebarConfig?.enabled !== false &&
sidebarConfig?.[item.key] !== false &&
isSidebarModuleVisible(sidebarConfig, item.key, userGroup) &&
!(inMiniProgram && isMiniProgramPaymentPath(item.path)),
);
@@ -155,6 +158,8 @@ const MobileBottomNav = ({ sidebarConfig }) => {
const UserCenter = ({ keyManagementMode = false }) => {
const [statusState] = useContext(StatusContext);
const [userState] = useContext(UserContext);
const userGroup = userState?.user?.group;
// 仅用于页面外壳的样式标识(看板与子页面底色不同),不参与路由判断
const ucRoute = useLocation().pathname.split('/')[2] || 'dashboard';
@@ -192,7 +197,7 @@ const UserCenter = ({ keyManagementMode = false }) => {
: routePathMap[
userCenterRoutes.find(
(key) =>
userCenterConfig[key] !== false &&
isSidebarModuleVisible(userCenterConfig, key, userGroup) &&
!(
inMiniProgram &&
isMiniProgramPaymentPath(`/user-center/${routePathMap[key]}`)
@@ -203,7 +208,7 @@ const UserCenter = ({ keyManagementMode = false }) => {
? `/user-center/${firstVisiblePath}`
: '/';
const guardUserCenterRoute = (key, element) => {
if (userCenterConfig.enabled === false || userCenterConfig[key] === false) {
if (!isSidebarModuleVisible(userCenterConfig, key, userGroup)) {
return <Navigate to={firstVisibleRoute} replace />;
}
return element;