阶段七:完成 React Feature 化与前置重构收口

This commit is contained in:
Christ committed 2026-08-17 20:29:34 +08:00
1 parent 375e84d663
commit 1a228dc35c
305 files changed
+14179 -5431

No files matched your search

@@ -2,22 +2,22 @@
import React from 'react';
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
import { afterEach, describe, expect, test, vi } from 'vitest';
import type { Item } from '../../types';
import type { Item } from '../../shared/api-contract';
import type { DeliveryRuleTarget } from './AuthenticatedShell';
vi.mock('../../components/Dashboard', /* dashboardMockFactory 提供仪表盘页面的轻量替身。 */ () => {
vi.mock('../features/dashboard/pages/Dashboard', /* dashboardMockFactory 提供仪表盘页面的轻量替身。 */ () => {
// DashboardMock 渲染仪表盘页面标识,避免行为测试加载真实图表依赖。
const DashboardMock: React.FC = () => <div data-testid="dashboard-page">仪表盘</div>;
return { default: DashboardMock };
});
vi.mock('../../components/Settings', /* settingsMockFactory 提供设置页面的轻量替身。 */ () => {
vi.mock('../features/settings/pages/Settings', /* settingsMockFactory 提供设置页面的轻量替身。 */ () => {
// SettingsMock 渲染设置页面标识,验证管理员权限分支。
const SettingsMock: React.FC = () => <div data-testid="settings-page">设置</div>;
return { default: SettingsMock };
});
vi.mock('../../components/ItemList', /* itemListMockFactory 提供商品页面的联动替身。 */ () => {
vi.mock('../features/items/pages/ItemList', /* itemListMockFactory 提供商品页面的联动替身。 */ () => {
// MockItemListProps 描述商品页面替身接收的规则配置回调。
interface MockItemListProps {
// onConfigureDelivery 负责通知父级打开商品规则配置。
@@ -32,7 +32,7 @@ vi.mock('../../components/ItemList', /* itemListMockFactory 提供商品页面
return { default: ItemListMock };
});
vi.mock('../../components/Rules', /* rulesMockFactory 提供规则页面的轻量替身。 */ () => {
vi.mock('../features/rules/pages/Rules', /* rulesMockFactory 提供规则页面的轻量替身。 */ () => {
// MockRulesProps 描述规则页面替身接收的联动参数。
interface MockRulesProps {
// initialDeliveryTarget 保存商品页面传来的规则目标。
+38 -16
View File
@@ -1,6 +1,8 @@
import React, { lazy, Suspense } from 'react';
import Sidebar from '../../components/Sidebar';
import type { Item } from '../../types';
import React, { lazy, Suspense, useEffect, useState } from 'react';
import Sidebar from '../../shared/ui/Sidebar';
import type { Item } from '../../shared/api-contract';
import { getHealth } from '../features/system/api';
import type { BuildInfo } from '../features/system/types';
// DeliveryRuleTarget 描述商品页跳转到自动化规则页时需要携带的目标信息。
export interface DeliveryRuleTarget {
@@ -35,23 +37,23 @@ export interface AuthenticatedShellProps {
}
// Dashboard 是按需加载的仪表盘页面,避免首屏同步载入图表依赖。
const Dashboard = lazy(/* Dashboard 页面按路由激活时加载。 */ () => import('../../components/Dashboard'));
const Dashboard = lazy(/* Dashboard 页面按路由激活时加载。 */ () => import('../features/dashboard/pages/Dashboard'));
// AccountList 是按需加载的账号管理页面,避免未访问时载入账号弹窗和二维码代码。
const AccountList = lazy(/* AccountList 页面按路由激活时加载。 */ () => import('../../components/AccountList'));
const AccountList = lazy(/* AccountList 页面按路由激活时加载。 */ () => import('../features/accounts/pages/AccountList'));
// OrderList 是按需加载的订单页面,避免首屏载入订单导入与刷新代码。
const OrderList = lazy(/* OrderList 页面按路由激活时加载。 */ () => import('../../components/OrderList'));
const OrderList = lazy(/* OrderList 页面按路由激活时加载。 */ () => import('../features/orders/pages/OrderList'));
// CardList 是按需加载的卡密页面,避免首屏载入卡密批量处理代码。
const CardList = lazy(/* CardList 页面按路由激活时加载。 */ () => import('../../components/CardList'));
const CardList = lazy(/* CardList 页面按路由激活时加载。 */ () => import('../features/cards/pages/CardList'));
// ItemList 是按需加载的商品页面,避免首屏载入商品发布编辑器代码。
const ItemList = lazy(/* ItemList 页面按路由激活时加载。 */ () => import('../../components/ItemList'));
const ItemList = lazy(/* ItemList 页面按路由激活时加载。 */ () => import('../features/items/pages/ItemList'));
// Settings 是按需加载的系统设置页面,仅在管理员访问时加载。
const Settings = lazy(/* Settings 页面按路由激活时加载。 */ () => import('../../components/Settings'));
const Settings = lazy(/* Settings 页面按路由激活时加载。 */ () => import('../features/settings/pages/Settings'));
// Rules 是按需加载的自动化规则页面,避免首屏载入规则编辑器代码。
const Rules = lazy(/* Rules 页面按路由激活时加载。 */ () => import('../../components/Rules'));
const Rules = lazy(/* Rules 页面按路由激活时加载。 */ () => import('../features/rules/pages/Rules'));
// Notifications 是按需加载的通知页面,避免首屏载入通知配置代码。
const Notifications = lazy(/* Notifications 页面按路由激活时加载。 */ () => import('../../components/Notifications'));
const Notifications = lazy(/* Notifications 页面按路由激活时加载。 */ () => import('../features/notifications/pages/Notifications'));
// Chat 是按需加载的聊天页面,避免未访问时载入聊天历史和 WebSocket 视图。
const Chat = lazy(/* Chat 页面按路由激活时加载。 */ () => import('../../components/Chat'));
const Chat = lazy(/* Chat 页面按路由激活时加载。 */ () => import('../features/chat/pages/Chat'));
// PageLoading 展示路由页面代码加载期间的统一占位状态。
const PageLoading: React.FC = () => (
@@ -128,8 +130,26 @@ const AuthenticatedShell: React.FC<AuthenticatedShellProps> = ({
onLogout,
onConfigureDelivery,
onDeliveryTargetHandled,
}) => (
<div className="flex min-h-screen bg-canvas text-ink">
}) => {
// buildInfo 保存壳层加载的公开构建版本,侧边栏保持为无请求的共享展示组件。
const [buildInfo, setBuildInfo] = useState<BuildInfo>({ version: 'dev', commit: 'unknown' });
useEffect(/* effect 在壳层挂载时读取版本信息,并在卸载时中止尚未完成的请求。 */ () => {
// controller 取消壳层卸载后不再需要的健康检查请求。
const controller = new AbortController();
getHealth({ signal: controller.signal })
.then(/* response 是健康接口返回的公开构建标识。 */ response => setBuildInfo({
version: String(response.version || 'dev'),
commit: String(response.commit || 'unknown'),
}))
.catch(/* error 是健康检查失败原因,取消请求不需要改变默认展示版本。 */ error => {
if (error instanceof DOMException && error.name === 'AbortError') return;
});
return /* cleanup 在壳层卸载时释放健康检查请求。 */ () => controller.abort();
}, []);
return (
<div className="flex min-h-screen bg-canvas text-ink">
<Sidebar
activeTab={activeTab}
isAdmin={isAdmin}
@@ -137,6 +157,7 @@ const AuthenticatedShell: React.FC<AuthenticatedShellProps> = ({
onToggleCollapsed={onToggleCollapsed}
onNavigate={onNavigate}
onLogout={onLogout}
buildInfo={buildInfo}
/>
<main className={`h-screen min-w-0 flex-1 overflow-x-hidden overflow-y-auto scroll-smooth transition-[margin] duration-300 ${collapsed ? 'ml-16' : 'ml-64'} ${activeTab === 'chat' ? 'p-4 md:p-6' : 'p-8 md:p-12'}`}>
@@ -153,7 +174,8 @@ const AuthenticatedShell: React.FC<AuthenticatedShellProps> = ({
/>
</div>
</main>
</div>
);
</div>
);
};
export default AuthenticatedShell;