Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| daf20157ce | |||
| 001fbac538 | |||
| b9eae439ba | |||
| d076fb5325 | |||
| 4c6e9acb6e | |||
| dbdfed378e |
+11
-9
@@ -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
|
||||||
|
|
||||||
### 调整 · 认证页表单必填标识、就地校验与间距统一
|
### 调整 · 认证页表单必填标识、就地校验与间距统一
|
||||||
@@ -210,14 +220,6 @@
|
|||||||
- **回滚**:`controls.jsx` 与上述三处调用方需一起还原;文档按文件还原。
|
- **回滚**:`controls.jsx` 与上述三处调用方需一起还原;文档按文件还原。
|
||||||
- **关联**:`docs/standards/DEV_STANDARDS.md` 2.3
|
- **关联**:`docs/standards/DEV_STANDARDS.md` 2.3
|
||||||
|
|
||||||
### 调整 · 隐藏用户中心服务监控
|
|
||||||
|
|
||||||
- **范围**:用户中心桌面侧栏、移动端底栏、服务监控路由与面包屑。
|
|
||||||
- **变更**:移除服务监控菜单,原页面地址与旧 `/service-dashboard` 地址均跳转到用户中心首个已开放页面;默认页候选排除服务监控,无可用页面时回到首页。
|
|
||||||
- **影响**:服务监控不再挂载,不触发该页面的监控请求;保留页面源码与后台配置,其他菜单沿用原有配置。
|
|
||||||
- **回滚**:仅还原本条涉及的用户中心入口、侧栏、面包屑及服务监控规范差异。
|
|
||||||
- **关联**:`docs/ui/SERVICE_DASHBOARD_SPEC.md`。
|
|
||||||
|
|
||||||
## 2026-11-17
|
## 2026-11-17
|
||||||
|
|
||||||
### 调整 · 官网设置指标只填数字并实时预览官网展示
|
### 调整 · 官网设置指标只填数字并实时预览官网展示
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
# 服务监控 UI 规范(/user-center/service-dashboard)
|
# 服务监控 UI 规范(/user-center/service-dashboard)
|
||||||
|
|
||||||
> 状态:有效(页面暂不开放) · 适用:antd 6.7.0 · 更新:2026-11-18 · 版本:v2.2
|
> 状态:有效 · 适用: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 秒自动刷新、逐秒倒计时、分组权限、模型测试与请求不变 |
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ const pageTitles = {
|
|||||||
'/user-center/key-management': '密钥管理',
|
'/user-center/key-management': '密钥管理',
|
||||||
'/user-center/dashboard': '数据看板',
|
'/user-center/dashboard': '数据看板',
|
||||||
'/user-center/usage-record': '使用记录',
|
'/user-center/usage-record': '使用记录',
|
||||||
|
'/user-center/service-dashboard': '服务监控',
|
||||||
'/user-center/topup': '在线充值',
|
'/user-center/topup': '在线充值',
|
||||||
'/user-center/settings': '个人设置',
|
'/user-center/settings': '个人设置',
|
||||||
'/user-center/invite': '邀请有奖',
|
'/user-center/invite': '邀请有奖',
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
|
|||||||
@@ -36,11 +36,13 @@ import {
|
|||||||
UserRound,
|
UserRound,
|
||||||
Receipt,
|
Receipt,
|
||||||
Gift,
|
Gift,
|
||||||
|
Activity,
|
||||||
MonitorDown,
|
MonitorDown,
|
||||||
} 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';
|
||||||
|
|
||||||
@@ -56,46 +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,
|
|
||||||
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),非激活中性灰,靠图标本身区分功能。
|
||||||
@@ -119,6 +87,12 @@ const UserCenterSidebar = () => {
|
|||||||
text: t('密钥管理'),
|
text: t('密钥管理'),
|
||||||
icon: KeyRound,
|
icon: KeyRound,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
itemKey: '/user-center/service-dashboard',
|
||||||
|
configKey: 'serviceDashboard',
|
||||||
|
text: t('服务监控'),
|
||||||
|
icon: Activity,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
itemKey: '/user-center/topup',
|
itemKey: '/user-center/topup',
|
||||||
configKey: 'topup',
|
configKey: 'topup',
|
||||||
@@ -167,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]);
|
||||||
|
|||||||
@@ -32,10 +32,13 @@ import {
|
|||||||
ScrollText,
|
ScrollText,
|
||||||
Wallet,
|
Wallet,
|
||||||
UserRound,
|
UserRound,
|
||||||
|
Activity,
|
||||||
Gift,
|
Gift,
|
||||||
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';
|
||||||
@@ -46,6 +49,7 @@ import Invite from './Invite';
|
|||||||
import Invoice from './Invoice';
|
import Invoice from './Invoice';
|
||||||
import TopUp from '../TopUp';
|
import TopUp from '../TopUp';
|
||||||
import PersonalSetting from '../../components/settings/PersonalSetting';
|
import PersonalSetting from '../../components/settings/PersonalSetting';
|
||||||
|
import ServiceDashboard from '../ServiceDashboard';
|
||||||
import WeyAiDownload from '../WeyAiDownload';
|
import WeyAiDownload from '../WeyAiDownload';
|
||||||
import KeyManagement from '../KeyManagement';
|
import KeyManagement from '../KeyManagement';
|
||||||
import { normalizeSidebarModulesAdmin } from '../../constants/sidebarModules';
|
import { normalizeSidebarModulesAdmin } from '../../constants/sidebarModules';
|
||||||
@@ -59,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 = [
|
||||||
{
|
{
|
||||||
@@ -79,6 +85,12 @@ const MobileBottomNav = ({ sidebarConfig }) => {
|
|||||||
label: t('密钥管理'),
|
label: t('密钥管理'),
|
||||||
path: '/user-center/key-management',
|
path: '/user-center/key-management',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: 'serviceDashboard',
|
||||||
|
icon: Activity,
|
||||||
|
label: t('监控'),
|
||||||
|
path: '/user-center/service-dashboard',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: 'invite',
|
key: 'invite',
|
||||||
icon: Gift,
|
icon: Gift,
|
||||||
@@ -108,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)),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -147,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';
|
||||||
|
|
||||||
@@ -161,6 +174,7 @@ const UserCenter = ({ keyManagementMode = false }) => {
|
|||||||
const userCenterRoutes = [
|
const userCenterRoutes = [
|
||||||
'dashboard',
|
'dashboard',
|
||||||
'usageRecord',
|
'usageRecord',
|
||||||
|
'serviceDashboard',
|
||||||
'topup',
|
'topup',
|
||||||
'invoice',
|
'invoice',
|
||||||
'invite',
|
'invite',
|
||||||
@@ -169,6 +183,7 @@ const UserCenter = ({ keyManagementMode = false }) => {
|
|||||||
const routePathMap = {
|
const routePathMap = {
|
||||||
dashboard: 'dashboard',
|
dashboard: 'dashboard',
|
||||||
usageRecord: 'usage-record',
|
usageRecord: 'usage-record',
|
||||||
|
serviceDashboard: 'service-dashboard',
|
||||||
topup: 'topup',
|
topup: 'topup',
|
||||||
invoice: 'invoice',
|
invoice: 'invoice',
|
||||||
invite: 'invite',
|
invite: 'invite',
|
||||||
@@ -182,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]}`)
|
||||||
@@ -193,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;
|
||||||
@@ -236,10 +251,15 @@ const UserCenter = ({ keyManagementMode = false }) => {
|
|||||||
path='usage-record'
|
path='usage-record'
|
||||||
element={guardUserCenterRoute('usageRecord', <UsageRecord />)}
|
element={guardUserCenterRoute('usageRecord', <UsageRecord />)}
|
||||||
/>
|
/>
|
||||||
{/* 服务监控暂不开放,历史地址回到首个已开放页面。 */}
|
{/* ServiceDashboard 组件内部有 min-h-screen pt-[88px],嵌入 UserCenter 后用 -mt-[64px] 部分抵消 pt,保留 24px 顶部间距(与其他页面 p-6 一致),[&>div]:min-h-0 避免撑高 */}
|
||||||
<Route
|
<Route
|
||||||
path='service-dashboard'
|
path='service-dashboard'
|
||||||
element={<Navigate to={firstVisibleRoute} replace />}
|
element={guardUserCenterRoute(
|
||||||
|
'serviceDashboard',
|
||||||
|
<div className='-mt-[64px] [&>div]:min-h-0'>
|
||||||
|
<ServiceDashboard />
|
||||||
|
</div>,
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
{/* TopUp 组件内部有 pt-[64px] 用于独立路由清除固定头部,UserCenter 已处理顶部偏移,需用 -mt 抵消。
|
{/* TopUp 组件内部有 pt-[64px] 用于独立路由清除固定头部,UserCenter 已处理顶部偏移,需用 -mt 抵消。
|
||||||
* embedded:UserCenter shell 已提供 PageBackground,子页面不再渲染自身背景,避免双层叠加 */}
|
* embedded:UserCenter shell 已提供 PageBackground,子页面不再渲染自身背景,避免双层叠加 */}
|
||||||
|
|||||||
@@ -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