feat: 恢复服务监控菜单入口
This commit is contained in:
+11
-1
@@ -1,6 +1,6 @@
|
|||||||
# 变更记录(CHANGELOG)
|
# 变更记录(CHANGELOG)
|
||||||
|
|
||||||
> 状态:有效(持续追加) · 更新:2026-11-18 · 版本:v3.5
|
> 状态:有效(持续追加) · 更新:2026-11-19 · 版本:v3.6
|
||||||
|
|
||||||
对现状仍有影响的功能与修复记录,按日期倒序。改造、迁移、优化等一次性过程不在此记录。
|
对现状仍有影响的功能与修复记录,按日期倒序。改造、迁移、优化等一次性过程不在此记录。
|
||||||
|
|
||||||
@@ -8,6 +8,16 @@
|
|||||||
|
|
||||||
**记录规则**:每条写“范围、变更、影响、回滚、关联”五项;回滚优先 `git revert <提交>`,提交含多项改动时按文件还原(`git checkout <提交>^ -- <文件>`),不整仓 reset。本文不作为规则依据。
|
**记录规则**:每条写“范围、变更、影响、回滚、关联”五项;回滚优先 `git revert <提交>`,提交含多项改动时按文件还原(`git checkout <提交>^ -- <文件>`),不整仓 reset。本文不作为规则依据。
|
||||||
|
|
||||||
|
## 2026-11-19
|
||||||
|
|
||||||
|
### 功能 · 恢复服务监控入口并接入超管开关
|
||||||
|
|
||||||
|
- **范围**:用户中心桌面侧栏、移动底栏、服务监控路由与面包屑。
|
||||||
|
- **变更**:恢复服务监控菜单和页面,复用超管运营设置中的 `SidebarModulesAdmin.userCenter.serviceDashboard` 开关;桌面、移动和路由统一判断区域开关、功能开关及可见分组。
|
||||||
|
- **影响**:未配置时默认开启;关闭或分组不允许时不挂载监控页面、不请求监控数据,直接访问新旧地址均回到首个可见页面,无可见页面时回到首页;服务监控接口与刷新逻辑保持原有行为。
|
||||||
|
- **回滚**:通过超管开关关闭入口;需要代码回滚时还原本条相关导航、路由与可见性判断。
|
||||||
|
- **关联**:`docs/ui/SERVICE_DASHBOARD_SPEC.md`、`src/helpers/navigationVisibility.js`、`src/pages/UserCenter/`。
|
||||||
|
|
||||||
## 2026-11-18
|
## 2026-11-18
|
||||||
|
|
||||||
### 调整 · 认证页表单必填标识、就地校验与间距统一
|
### 调整 · 认证页表单必填标识、就地校验与间距统一
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# 服务监控 UI 规范(/user-center/service-dashboard)
|
# 服务监控 UI 规范(/user-center/service-dashboard)
|
||||||
|
|
||||||
> 状态:有效 · 适用:antd 6.7.0 · 更新:2026-11-11 · 版本:v2.1
|
> 状态:有效 · 适用:antd 6.7.0 · 更新:2026-11-19 · 版本:v2.3
|
||||||
|
|
||||||
服务监控页的规范:分组可用性、历史条与详情弹窗。
|
服务监控页的规范:分组可用性、历史条与详情弹窗。
|
||||||
|
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
| 关注点 | 规则 |
|
| 关注点 | 规则 |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| 路由 | `/user-center/service-dashboard`,旧 `/service-dashboard` 重定向 |
|
| 路由 | `/user-center/service-dashboard`,旧 `/service-dashboard` 重定向;桌面侧栏、移动底栏和页面访问统一受超管“运营设置 → 左侧边栏模块管理 → 用户中心 → 服务监控”开关(`SidebarModulesAdmin.userCenter.serviceDashboard`)及区域 / 功能可见分组控制;关闭或无分组权限时不挂载页面,回到首个可见页面,无可用页面时回到首页;未配置时沿用默认开启 |
|
||||||
| 组件 | `Card`、`Button`、详情 `Modal` + `Statistic` + `Table`、`Tooltip`、`Spin` / `Empty` |
|
| 组件 | `Card`、`Button`、详情 `Modal` + `Statistic` + `Table`、`Tooltip`、`Spin` / `Empty` |
|
||||||
| 主题 | `theme.useToken()` 注入 `--service-*`;正常态跟随 `colorPrimary`,告警 / 异常用 `colorWarning` / `colorError` |
|
| 主题 | `theme.useToken()` 注入 `--service-*`;正常态跟随 `colorPrimary`,告警 / 异常用 `colorWarning` / `colorError` |
|
||||||
| 业务 | 60 秒自动刷新、逐秒倒计时、分组权限、模型测试与请求不变 |
|
| 业务 | 60 秒自动刷新、逐秒倒计时、分组权限、模型测试与请求不变 |
|
||||||
|
|||||||
@@ -29,6 +29,12 @@ export const isGroupAllowed = (groups, userGroup) => {
|
|||||||
return allowedGroups.includes(getEffectiveUserGroup(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) => {
|
export const isHeaderActionButtonVisible = (config, key, userGroup) => {
|
||||||
let buttons = config;
|
let buttons = config;
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ import {
|
|||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { StatusContext } from '../../context/Status';
|
import { StatusContext } from '../../context/Status';
|
||||||
import { UserContext } from '../../context/User';
|
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 { useSidebarCollapsed } from '../../hooks/common/useSidebarCollapsed';
|
||||||
import { useWeyAiDownloadEntry } from '../../hooks/common/useWeyAiWebEntry';
|
import { useWeyAiDownloadEntry } from '../../hooks/common/useWeyAiWebEntry';
|
||||||
|
|
||||||
@@ -57,47 +58,12 @@ const UserCenterSidebar = () => {
|
|||||||
const { visible: weyaiDownloadEnabled } = useWeyAiDownloadEntry();
|
const { visible: weyaiDownloadEnabled } = useWeyAiDownloadEntry();
|
||||||
|
|
||||||
// 获取侧边栏配置
|
// 获取侧边栏配置
|
||||||
const sidebarConfig = useMemo(() => {
|
const sidebarConfig = useMemo(
|
||||||
const defaultConfig = {
|
() =>
|
||||||
enabled: true,
|
normalizeSidebarModulesAdmin(statusState?.status?.SidebarModulesAdmin)
|
||||||
groups: [],
|
.userCenter,
|
||||||
moduleGroups: {},
|
[statusState?.status?.SidebarModulesAdmin],
|
||||||
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]);
|
|
||||||
|
|
||||||
// 统一单一品牌色高亮(云平台风格):菜单项不再各用一种颜色,
|
// 统一单一品牌色高亮(云平台风格):菜单项不再各用一种颜色,
|
||||||
// 激活态统一走 brand(azure),非激活中性灰,靠图标本身区分功能。
|
// 激活态统一走 brand(azure),非激活中性灰,靠图标本身区分功能。
|
||||||
@@ -175,11 +141,7 @@ const UserCenterSidebar = () => {
|
|||||||
const inMiniProgram = isMiniProgramWebView();
|
const inMiniProgram = isMiniProgramWebView();
|
||||||
return allItems.filter(
|
return allItems.filter(
|
||||||
(item) =>
|
(item) =>
|
||||||
sidebarConfig[item.configKey] !== false &&
|
isSidebarModuleVisible(sidebarConfig, item.configKey, userGroup) &&
|
||||||
isGroupAllowed(
|
|
||||||
sidebarConfig.moduleGroups?.[item.configKey],
|
|
||||||
userGroup,
|
|
||||||
) &&
|
|
||||||
!(inMiniProgram && isMiniProgramPaymentPath(item.itemKey)),
|
!(inMiniProgram && isMiniProgramPaymentPath(item.itemKey)),
|
||||||
);
|
);
|
||||||
}, [allItems, sidebarConfig, userGroup]);
|
}, [allItems, sidebarConfig, userGroup]);
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ import {
|
|||||||
Receipt,
|
Receipt,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { StatusContext } from '../../context/Status';
|
import { StatusContext } from '../../context/Status';
|
||||||
|
import { UserContext } from '../../context/User';
|
||||||
|
import { isSidebarModuleVisible } from '../../helpers/navigationVisibility';
|
||||||
import { useMarquee } from '../../hooks/common/useMarquee';
|
import { useMarquee } from '../../hooks/common/useMarquee';
|
||||||
import PageBackground from '../../components/common/PageBackground';
|
import PageBackground from '../../components/common/PageBackground';
|
||||||
import UserCenterSidebar from './UserCenterSidebar';
|
import UserCenterSidebar from './UserCenterSidebar';
|
||||||
@@ -61,6 +63,8 @@ const MobileBottomNav = ({ sidebarConfig }) => {
|
|||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
const [userState] = useContext(UserContext);
|
||||||
|
const userGroup = userState?.user?.group;
|
||||||
|
|
||||||
const navItems = [
|
const navItems = [
|
||||||
{
|
{
|
||||||
@@ -116,8 +120,7 @@ const MobileBottomNav = ({ sidebarConfig }) => {
|
|||||||
const inMiniProgram = isMiniProgramWebView();
|
const inMiniProgram = isMiniProgramWebView();
|
||||||
const visibleNavItems = navItems.filter(
|
const visibleNavItems = navItems.filter(
|
||||||
(item) =>
|
(item) =>
|
||||||
sidebarConfig?.enabled !== false &&
|
isSidebarModuleVisible(sidebarConfig, item.key, userGroup) &&
|
||||||
sidebarConfig?.[item.key] !== false &&
|
|
||||||
!(inMiniProgram && isMiniProgramPaymentPath(item.path)),
|
!(inMiniProgram && isMiniProgramPaymentPath(item.path)),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -155,6 +158,8 @@ const MobileBottomNav = ({ sidebarConfig }) => {
|
|||||||
|
|
||||||
const UserCenter = ({ keyManagementMode = false }) => {
|
const UserCenter = ({ keyManagementMode = false }) => {
|
||||||
const [statusState] = useContext(StatusContext);
|
const [statusState] = useContext(StatusContext);
|
||||||
|
const [userState] = useContext(UserContext);
|
||||||
|
const userGroup = userState?.user?.group;
|
||||||
// 仅用于页面外壳的样式标识(看板与子页面底色不同),不参与路由判断
|
// 仅用于页面外壳的样式标识(看板与子页面底色不同),不参与路由判断
|
||||||
const ucRoute = useLocation().pathname.split('/')[2] || 'dashboard';
|
const ucRoute = useLocation().pathname.split('/')[2] || 'dashboard';
|
||||||
|
|
||||||
@@ -192,7 +197,7 @@ const UserCenter = ({ keyManagementMode = false }) => {
|
|||||||
: routePathMap[
|
: routePathMap[
|
||||||
userCenterRoutes.find(
|
userCenterRoutes.find(
|
||||||
(key) =>
|
(key) =>
|
||||||
userCenterConfig[key] !== false &&
|
isSidebarModuleVisible(userCenterConfig, key, userGroup) &&
|
||||||
!(
|
!(
|
||||||
inMiniProgram &&
|
inMiniProgram &&
|
||||||
isMiniProgramPaymentPath(`/user-center/${routePathMap[key]}`)
|
isMiniProgramPaymentPath(`/user-center/${routePathMap[key]}`)
|
||||||
@@ -203,7 +208,7 @@ const UserCenter = ({ keyManagementMode = false }) => {
|
|||||||
? `/user-center/${firstVisiblePath}`
|
? `/user-center/${firstVisiblePath}`
|
||||||
: '/';
|
: '/';
|
||||||
const guardUserCenterRoute = (key, element) => {
|
const guardUserCenterRoute = (key, element) => {
|
||||||
if (userCenterConfig.enabled === false || userCenterConfig[key] === false) {
|
if (!isSidebarModuleVisible(userCenterConfig, key, userGroup)) {
|
||||||
return <Navigate to={firstVisibleRoute} replace />;
|
return <Navigate to={firstVisibleRoute} replace />;
|
||||||
}
|
}
|
||||||
return element;
|
return element;
|
||||||
|
|||||||
@@ -0,0 +1,182 @@
|
|||||||
|
/*
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
|
||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import test from 'node:test';
|
||||||
|
import React from 'react';
|
||||||
|
import * as icons from 'lucide-react';
|
||||||
|
import * as modules from '../../src/constants/sidebarModules.js';
|
||||||
|
import * as visibility from '../../src/helpers/navigationVisibility.js';
|
||||||
|
import { loadFrontendModule } from './frontend-module.js';
|
||||||
|
|
||||||
|
const StatusContext = {};
|
||||||
|
const UserContext = {};
|
||||||
|
let config;
|
||||||
|
let userGroup = 'default';
|
||||||
|
const mocks = {
|
||||||
|
react: {
|
||||||
|
...React,
|
||||||
|
useContext: (context) =>
|
||||||
|
context === StatusContext
|
||||||
|
? [{ status: { SidebarModulesAdmin: config } }]
|
||||||
|
: [{ user: { group: userGroup } }],
|
||||||
|
useMemo: (factory) => factory(),
|
||||||
|
},
|
||||||
|
'react-router-dom': {
|
||||||
|
Routes: 'routes',
|
||||||
|
Route: 'route',
|
||||||
|
Navigate: 'navigate',
|
||||||
|
Link: 'link',
|
||||||
|
useLocation: () => ({ pathname: '/user-center/service-dashboard' }),
|
||||||
|
useNavigate: () => () => {},
|
||||||
|
},
|
||||||
|
'react-i18next': { useTranslation: () => ({ t: (value) => value }) },
|
||||||
|
'lucide-react': icons,
|
||||||
|
'../../context/Status': { StatusContext },
|
||||||
|
'../../context/User': { UserContext },
|
||||||
|
'../../constants/sidebarModules': modules,
|
||||||
|
'../../helpers/navigationVisibility': visibility,
|
||||||
|
'../../helpers/miniProgram': {
|
||||||
|
isMiniProgramWebView: () => false,
|
||||||
|
isMiniProgramPaymentPath: () => false,
|
||||||
|
},
|
||||||
|
'../../hooks/common/useMarquee': { useMarquee: () => ({ visible: false }) },
|
||||||
|
'../../hooks/common/useSidebarCollapsed': {
|
||||||
|
useSidebarCollapsed: () => [false, () => {}],
|
||||||
|
},
|
||||||
|
'../../hooks/common/useWeyAiWebEntry': {
|
||||||
|
useWeyAiDownloadEntry: () => ({ visible: false }),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
for (const path of [
|
||||||
|
'../../components/common/PageBackground',
|
||||||
|
'./UserCenterSidebar',
|
||||||
|
'./UserDashboard',
|
||||||
|
'./UsageRecord',
|
||||||
|
'./Invite',
|
||||||
|
'./Invoice',
|
||||||
|
'../TopUp',
|
||||||
|
'../../components/settings/PersonalSetting',
|
||||||
|
'../WeyAiDownload',
|
||||||
|
'../KeyManagement',
|
||||||
|
])
|
||||||
|
mocks[path] = { __esModule: true, default: () => null };
|
||||||
|
const ServiceDashboard = () => null;
|
||||||
|
mocks['../ServiceDashboard'] = { __esModule: true, default: ServiceDashboard };
|
||||||
|
const UserCenter = (
|
||||||
|
await loadFrontendModule(
|
||||||
|
new URL('../../src/pages/UserCenter/index.jsx', import.meta.url),
|
||||||
|
mocks,
|
||||||
|
)
|
||||||
|
).default;
|
||||||
|
const Sidebar = (
|
||||||
|
await loadFrontendModule(
|
||||||
|
new URL(
|
||||||
|
'../../src/pages/UserCenter/UserCenterSidebar.jsx',
|
||||||
|
import.meta.url,
|
||||||
|
),
|
||||||
|
mocks,
|
||||||
|
)
|
||||||
|
).default;
|
||||||
|
|
||||||
|
function descendants(node) {
|
||||||
|
if (!React.isValidElement(node)) return [];
|
||||||
|
return [
|
||||||
|
node,
|
||||||
|
...React.Children.toArray(node.props.children).flatMap(descendants),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [name, userCenter, group, visible] of [
|
||||||
|
['defaults', {}, 'default', true],
|
||||||
|
['enabled', { serviceDashboard: true }, 'default', true],
|
||||||
|
['disabled', { serviceDashboard: false }, 'default', false],
|
||||||
|
['section disabled', { enabled: false }, 'default', false],
|
||||||
|
['allowed section group', { groups: ['vip'] }, 'vip', true],
|
||||||
|
['denied section group', { groups: ['vip'] }, 'default', false],
|
||||||
|
[
|
||||||
|
'allowed module group',
|
||||||
|
{ moduleGroups: { serviceDashboard: ['vip'] } },
|
||||||
|
'vip',
|
||||||
|
true,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'denied module group',
|
||||||
|
{ moduleGroups: { serviceDashboard: ['vip'] } },
|
||||||
|
'default',
|
||||||
|
false,
|
||||||
|
],
|
||||||
|
]) {
|
||||||
|
test(`service dashboard desktop, mobile and route agree: ${name}`, () => {
|
||||||
|
config = JSON.stringify({ userCenter });
|
||||||
|
userGroup = group;
|
||||||
|
const tree = UserCenter({});
|
||||||
|
const nodes = descendants(tree);
|
||||||
|
const route = nodes.find((node) => node.props.path === 'service-dashboard');
|
||||||
|
const mountsPage = route
|
||||||
|
? descendants(route.props.element).some(
|
||||||
|
(node) => node.type === ServiceDashboard,
|
||||||
|
)
|
||||||
|
: false;
|
||||||
|
assert.equal(mountsPage, visible);
|
||||||
|
if (route && !visible) {
|
||||||
|
assert.equal(route.props.element.type, 'navigate');
|
||||||
|
assert.notEqual(
|
||||||
|
route.props.element.props.to,
|
||||||
|
'/user-center/service-dashboard',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
const desktop = descendants(Sidebar()).some(
|
||||||
|
(node) => node.props.to === '/user-center/service-dashboard',
|
||||||
|
);
|
||||||
|
assert.equal(desktop, visible);
|
||||||
|
const mobileComponent = nodes.find(
|
||||||
|
(node) => node.props.sidebarConfig !== undefined,
|
||||||
|
);
|
||||||
|
const mobile = mobileComponent
|
||||||
|
? descendants(mobileComponent.type(mobileComponent.props)).some(
|
||||||
|
(node) => node.type === 'span' && node.props.children === '监控',
|
||||||
|
)
|
||||||
|
: false;
|
||||||
|
assert.equal(mobile, visible);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
test('service dashboard can be the only enabled default route without a redirect loop', () => {
|
||||||
|
config = JSON.stringify({
|
||||||
|
userCenter: {
|
||||||
|
...Object.fromEntries(
|
||||||
|
Object.keys(modules.getDefaultSidebarModulesAdmin().userCenter).map(
|
||||||
|
(key) => [key, false],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
enabled: true,
|
||||||
|
serviceDashboard: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const nodes = descendants(UserCenter({}));
|
||||||
|
const route = nodes.find((node) => node.props.path === '/');
|
||||||
|
assert.equal(route.props.element.props.to, '/user-center/service-dashboard');
|
||||||
|
const service = nodes.find((node) => node.props.path === 'service-dashboard');
|
||||||
|
assert.ok(
|
||||||
|
descendants(service.props.element).some(
|
||||||
|
(node) => node.type === ServiceDashboard,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user