cp相关
This commit is contained in:
parent
2f7e3bb86a
commit
5bdbe33f8f
12
AGENTS.md
12
AGENTS.md
@ -28,7 +28,7 @@
|
|||||||
- 应用壳:`src/app/App.jsx`、`src/app/layout/AdminLayout.jsx`、`src/app/router/routeConfig.ts`。
|
- 应用壳:`src/app/App.jsx`、`src/app/layout/AdminLayout.jsx`、`src/app/router/routeConfig.ts`。
|
||||||
- 页面加载占位:`src/shared/ui/PageSkeleton.jsx`。
|
- 页面加载占位:`src/shared/ui/PageSkeleton.jsx`。
|
||||||
- 公共时间选择器:`src/shared/ui/TimeRangeFilter.jsx`,使用 `{ startMs, endMs }` 毫秒值作为输入输出。
|
- 公共时间选择器:`src/shared/ui/TimeRangeFilter.jsx`,使用 `{ startMs, endMs }` 毫秒值作为输入输出。
|
||||||
- 全局资源组选择抽屉:`src/shared/ui/ResourceGroupSelectDrawer.jsx`,资源组字段优先使用该组件,不在业务页面里重复手写普通下拉。
|
- 全局资源组选择抽屉:`src/shared/ui/ResourceGroupSelectDrawer.jsx`,业务表单资源组字段统一使用其导出的 `ResourceGroupSelectField`,不在业务页面里重复手写普通下拉或资源组 ID 输入框。
|
||||||
- 顶部搜索弹窗:`src/features/search/components/SearchDialog.jsx`。
|
- 顶部搜索弹窗:`src/features/search/components/SearchDialog.jsx`。
|
||||||
- MUI 主题:`src/theme.js`。
|
- MUI 主题:`src/theme.js`。
|
||||||
- CSS token:`src/styles/tokens.css`。
|
- CSS token:`src/styles/tokens.css`。
|
||||||
@ -77,10 +77,10 @@ import { Refresh } from "@mui/icons-material";
|
|||||||
## 样式规则
|
## 样式规则
|
||||||
|
|
||||||
- 状态色不要随意改:
|
- 状态色不要随意改:
|
||||||
- `--success`:运行中
|
- `--success`:运行中
|
||||||
- `--warning`:警告
|
- `--warning`:警告
|
||||||
- `--danger`:异常/危险操作
|
- `--danger`:异常/危险操作
|
||||||
- `--stopped`:已停止
|
- `--stopped`:已停止
|
||||||
- 新增颜色优先写入 token 或 theme,不要在多个组件里重复硬编码。
|
- 新增颜色优先写入 token 或 theme,不要在多个组件里重复硬编码。
|
||||||
- 基础组件的视觉兼容优先改封装组件,不要让页面直接依赖 MUI 细节。
|
- 基础组件的视觉兼容优先改封装组件,不要让页面直接依赖 MUI 细节。
|
||||||
- 不添加卡片套卡片。
|
- 不添加卡片套卡片。
|
||||||
@ -93,7 +93,7 @@ import { Refresh } from "@mui/icons-material";
|
|||||||
- 表格状态筛选使用 Select 下拉框,默认值为 `全部状态`,不使用状态 chip 组。
|
- 表格状态筛选使用 Select 下拉框,默认值为 `全部状态`,不使用状态 chip 组。
|
||||||
- 后台列表页的时间区间筛选必须使用统一的单入口时间区间筛选框(`src/shared/ui/TimeRangeFilter.jsx`);不要在工具栏里并排放两个开始/结束时间输入框,也不要使用浏览器原生日期/时间输入样式。时间区间弹层内使用快捷项、日历和时分下拉点选,不使用手写时间文本框。
|
- 后台列表页的时间区间筛选必须使用统一的单入口时间区间筛选框(`src/shared/ui/TimeRangeFilter.jsx`);不要在工具栏里并排放两个开始/结束时间输入框,也不要使用浏览器原生日期/时间输入样式。时间区间弹层内使用快捷项、日历和时分下拉点选,不使用手写时间文本框。
|
||||||
- 后台表单里的生效时间、有效期、投放时间等时间区间必须使用统一公共时间选择器(`src/shared/ui/TimeRangeFilter.jsx`);不要并排放两个开始/结束时间输入框,也不要使用浏览器原生日期/时间输入样式。
|
- 后台表单里的生效时间、有效期、投放时间等时间区间必须使用统一公共时间选择器(`src/shared/ui/TimeRangeFilter.jsx`);不要并排放两个开始/结束时间输入框,也不要使用浏览器原生日期/时间输入样式。
|
||||||
- 资源组选择必须优先使用统一的 `src/shared/ui/ResourceGroupSelectDrawer.jsx`,点击输入框打开右侧资源组图标抽屉,点击资源组后自动回填并关闭,不要在业务页面里重复实现资源组 Select 下拉。
|
- 资源组选择必须优先使用统一的 `src/shared/ui/ResourceGroupSelectDrawer.jsx` / `ResourceGroupSelectField`,点击输入框打开右侧资源组图标抽屉,点击资源组后自动回填并关闭,不要在业务页面里重复实现资源组 Select 下拉,也不要用普通文本框填写资源组 ID。
|
||||||
- 区域编辑弹窗必须同时包含区域基础字段和国家码字段;国家码使用可搜索多选下拉框,不再拆成独立“区域国家”弹窗。
|
- 区域编辑弹窗必须同时包含区域基础字段和国家码字段;国家码使用可搜索多选下拉框,不再拆成独立“区域国家”弹窗。
|
||||||
- 头像、图片、封面等图片资源字段必须使用 `src/shared/ui/UploadField.jsx` 上传表单组件,不使用普通文本输入框承载 URL。
|
- 头像、图片、封面等图片资源字段必须使用 `src/shared/ui/UploadField.jsx` 上传表单组件,不使用普通文本输入框承载 URL。
|
||||||
- 图片上传表单必须提供统一预览;`webp` 使用浏览器原生动效预览,`svga` 使用 SVGA 播放器预览,`pag` 使用 libpag + wasm 预览。
|
- 图片上传表单必须提供统一预览;`webp` 使用浏览器原生动效预览,`svga` 使用 SVGA 播放器预览,`pag` 使用 libpag + wasm 预览。
|
||||||
|
|||||||
72
README.md
72
README.md
@ -54,40 +54,40 @@ pnpm build
|
|||||||
|
|
||||||
- `src/App.jsx` 只负责应用状态、页面切换、抽屉挂载和数据分发。
|
- `src/App.jsx` 只负责应用状态、页面切换、抽屉挂载和数据分发。
|
||||||
- 页面模块放在 `src/pages/`:
|
- 页面模块放在 `src/pages/`:
|
||||||
- `OverviewPage.jsx`
|
- `OverviewPage.jsx`
|
||||||
- `ServicesPage.jsx`
|
- `ServicesPage.jsx`
|
||||||
- `UserManagementPage.jsx`
|
- `UserManagementPage.jsx`
|
||||||
- 基础组件放在 `src/components/base/`,对 MUI 做项目级封装:
|
- 基础组件放在 `src/components/base/`,对 MUI 做项目级封装:
|
||||||
- `Button`
|
- `Button`
|
||||||
- `IconButton`
|
- `IconButton`
|
||||||
- `Card`
|
- `Card`
|
||||||
- `SearchBox`
|
- `SearchBox`
|
||||||
- `FilterChip`
|
- `FilterChip`
|
||||||
- `KpiCard`
|
- `KpiCard`
|
||||||
- `SegmentControl`
|
- `SegmentControl`
|
||||||
- 当前共享后台组件统一放在 `src/shared/ui/`;资源组字段使用 `ResourceGroupSelectDrawer.jsx`,点击输入框打开右侧资源组图标抽屉,选择后自动回填。
|
- 当前共享后台组件统一放在 `src/shared/ui/`;资源组字段统一使用 `ResourceGroupSelectDrawer.jsx` 导出的 `ResourceGroupSelectField`,点击输入框打开右侧资源组图标抽屉,选择后自动回填,不在业务页面里手写资源组下拉或资源组 ID 输入框。
|
||||||
- 布局组件放在 `src/components/layout/`:
|
- 布局组件放在 `src/components/layout/`:
|
||||||
- `Header`
|
- `Header`
|
||||||
- `Sidebar`
|
- `Sidebar`
|
||||||
- `PageHead`
|
- `PageHead`
|
||||||
- `PageSkeleton`
|
- `PageSkeleton`
|
||||||
- 图表组件放在 `src/components/charts/`,统一封装 ECharts:
|
- 图表组件放在 `src/components/charts/`,统一封装 ECharts:
|
||||||
- `EChart`
|
- `EChart`
|
||||||
- `LineChart`
|
- `LineChart`
|
||||||
- `BarChart`
|
- `BarChart`
|
||||||
- `StatusDonut`
|
- `StatusDonut`
|
||||||
- `ChartCard`
|
- `ChartCard`
|
||||||
- 服务业务组件放在 `src/components/service/`:
|
- 服务业务组件放在 `src/components/service/`:
|
||||||
- `ServiceTable`
|
- `ServiceTable`
|
||||||
- `ServerRail`
|
- `ServerRail`
|
||||||
- `DetailPanel`
|
- `DetailPanel`
|
||||||
- `RowActions`
|
- `RowActions`
|
||||||
- `ResourceCell`
|
- `ResourceCell`
|
||||||
- `StatusBadge`
|
- `StatusBadge`
|
||||||
- 常量、模拟数据和工具函数分别放在:
|
- 常量、模拟数据和工具函数分别放在:
|
||||||
- `src/constants/`
|
- `src/constants/`
|
||||||
- `src/data/`
|
- `src/data/`
|
||||||
- `src/utils/`
|
- `src/utils/`
|
||||||
|
|
||||||
## 样式约定
|
## 样式约定
|
||||||
|
|
||||||
@ -97,10 +97,10 @@ pnpm build
|
|||||||
- MUI 主题集中在 `src/theme.js`,优先在主题层统一颜色、圆角、hover、focus 和组件兼容样式。
|
- MUI 主题集中在 `src/theme.js`,优先在主题层统一颜色、圆角、hover、focus 和组件兼容样式。
|
||||||
- 避免在页面里直接散落 MUI 组件样式;优先改项目封装组件。
|
- 避免在页面里直接散落 MUI 组件样式;优先改项目封装组件。
|
||||||
- 状态色必须保持语义一致:
|
- 状态色必须保持语义一致:
|
||||||
- 运行中:`--success`
|
- 运行中:`--success`
|
||||||
- 警告:`--warning`
|
- 警告:`--warning`
|
||||||
- 异常:`--danger`
|
- 异常:`--danger`
|
||||||
- 已停止:`--stopped`
|
- 已停止:`--stopped`
|
||||||
|
|
||||||
## 按需导入约定
|
## 按需导入约定
|
||||||
|
|
||||||
@ -109,9 +109,9 @@ pnpm build
|
|||||||
- 不使用 `@mui/material` 或 `@mui/icons-material` 总入口导入。
|
- 不使用 `@mui/material` 或 `@mui/icons-material` 总入口导入。
|
||||||
- ECharts 通过封装组件按需加载所需图表和组件能力。
|
- ECharts 通过封装组件按需加载所需图表和组件能力。
|
||||||
- 页面使用 `React.lazy` 拆分:
|
- 页面使用 `React.lazy` 拆分:
|
||||||
- `OverviewPage`
|
- `OverviewPage`
|
||||||
- `ServicesPage`
|
- `ServicesPage`
|
||||||
- `DetailDrawer`
|
- `DetailDrawer`
|
||||||
|
|
||||||
## 动画与加载
|
## 动画与加载
|
||||||
|
|
||||||
|
|||||||
178
src/App.test.jsx
178
src/App.test.jsx
@ -7,125 +7,127 @@ import { adminRoutes } from "@/app/router/routeConfig";
|
|||||||
import { setAccessToken } from "@/shared/api/request";
|
import { setAccessToken } from "@/shared/api/request";
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
window.localStorage.clear();
|
window.localStorage.clear();
|
||||||
vi.stubGlobal(
|
vi.stubGlobal(
|
||||||
"fetch",
|
"fetch",
|
||||||
vi.fn(async () => new Response(JSON.stringify({ code: 401, message: "unauthorized" }), { status: 401 }))
|
vi.fn(async () => new Response(JSON.stringify({ code: 401, message: "unauthorized" }), { status: 401 })),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
vi.unstubAllGlobals();
|
vi.unstubAllGlobals();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("renders login route", async () => {
|
test("renders login route", async () => {
|
||||||
renderWithRoute("/login");
|
renderWithRoute("/login");
|
||||||
|
|
||||||
expect(await screen.findByText("HYApp 管理平台")).toBeInTheDocument();
|
expect(await screen.findByText("HYApp 管理平台")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("redirects protected route to login when unauthenticated", async () => {
|
test("redirects protected route to login when unauthenticated", async () => {
|
||||||
renderWithRoute("/system/users");
|
renderWithRoute("/system/users");
|
||||||
|
|
||||||
expect(await screen.findByText("HYApp 管理平台")).toBeInTheDocument();
|
expect(await screen.findByText("HYApp 管理平台")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("renders resource list route with an authenticated session", async () => {
|
test("renders resource list route with an authenticated session", async () => {
|
||||||
setAccessToken("test-token");
|
setAccessToken("test-token");
|
||||||
vi.mocked(fetch).mockImplementation(async (input) => {
|
vi.mocked(fetch).mockImplementation(async (input) => {
|
||||||
const url = String(input);
|
const url = String(input);
|
||||||
if (url.includes("/v1/auth/refresh") || url.includes("/v1/auth/me")) {
|
if (url.includes("/v1/auth/refresh") || url.includes("/v1/auth/me")) {
|
||||||
return jsonResponse({
|
return jsonResponse({
|
||||||
accessToken: "test-token",
|
accessToken: "test-token",
|
||||||
permissions: ["resource:view"],
|
permissions: ["resource:view"],
|
||||||
user: { userId: 1, username: "admin" },
|
user: { userId: 1, username: "admin" },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (url.includes("/v1/admin/apps")) {
|
if (url.includes("/v1/admin/apps")) {
|
||||||
return jsonResponse({ items: [{ appCode: "lalu", name: "Lalu" }], total: 1 });
|
return jsonResponse({ items: [{ appCode: "lalu", name: "Lalu" }], total: 1 });
|
||||||
}
|
}
|
||||||
if (url.includes("/v1/admin/navigation/menus")) {
|
if (url.includes("/v1/admin/navigation/menus")) {
|
||||||
return jsonResponse([]);
|
return jsonResponse([]);
|
||||||
}
|
}
|
||||||
if (url.includes("/v1/admin/resources")) {
|
if (url.includes("/v1/admin/resources")) {
|
||||||
return jsonResponse({ items: [], page: 1, pageSize: 50, total: 0 });
|
return jsonResponse({ items: [], page: 1, pageSize: 50, total: 0 });
|
||||||
}
|
}
|
||||||
return jsonResponse(null);
|
return jsonResponse(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
renderWithRoute("/resources");
|
renderWithRoute("/resources");
|
||||||
|
|
||||||
expect(await screen.findByText("资源")).toBeInTheDocument();
|
expect((await screen.findAllByText("资源列表")).length).toBeGreaterThan(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("renders cp config route with an authenticated session", async () => {
|
test("renders cp config route with an authenticated session", async () => {
|
||||||
setAccessToken("test-token");
|
setAccessToken("test-token");
|
||||||
vi.mocked(fetch).mockImplementation(async (input) => {
|
vi.mocked(fetch).mockImplementation(async (input) => {
|
||||||
const url = String(input);
|
const url = String(input);
|
||||||
if (url.includes("/v1/auth/refresh") || url.includes("/v1/auth/me")) {
|
if (url.includes("/v1/auth/refresh") || url.includes("/v1/auth/me")) {
|
||||||
return jsonResponse({
|
return jsonResponse({
|
||||||
accessToken: "test-token",
|
accessToken: "test-token",
|
||||||
permissions: ["cp-config:view"],
|
permissions: ["cp-config:view"],
|
||||||
user: { userId: 1, username: "admin" },
|
user: { userId: 1, username: "admin" },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (url.includes("/v1/admin/apps")) {
|
if (url.includes("/v1/admin/apps")) {
|
||||||
return jsonResponse({ items: [{ appCode: "lalu", name: "Lalu" }], total: 1 });
|
return jsonResponse({ items: [{ appCode: "lalu", name: "Lalu" }], total: 1 });
|
||||||
}
|
}
|
||||||
if (url.includes("/v1/admin/navigation/menus")) {
|
if (url.includes("/v1/admin/navigation/menus")) {
|
||||||
return jsonResponse([]);
|
return jsonResponse([]);
|
||||||
}
|
}
|
||||||
if (url.includes("/v1/admin/activity/cp/config")) {
|
if (url.includes("/v1/admin/resource-groups")) {
|
||||||
return jsonResponse({
|
return jsonResponse({ items: [], page: 1, pageSize: 50, total: 0 });
|
||||||
appCode: "lalu",
|
}
|
||||||
relations: [
|
if (url.includes("/v1/admin/activity/cp/config")) {
|
||||||
cpRelationFixture("cp", "CP", 1),
|
return jsonResponse({
|
||||||
cpRelationFixture("brother", "兄弟", 5),
|
appCode: "lalu",
|
||||||
cpRelationFixture("sister", "姐妹", 5),
|
relations: [
|
||||||
],
|
cpRelationFixture("cp", "CP", 1),
|
||||||
});
|
cpRelationFixture("brother", "兄弟", 5),
|
||||||
}
|
cpRelationFixture("sister", "姐妹", 5),
|
||||||
return jsonResponse(null);
|
],
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
return jsonResponse(null);
|
||||||
|
});
|
||||||
|
|
||||||
renderWithRoute("/activities/cp-config");
|
renderWithRoute("/activities/cp-config");
|
||||||
|
|
||||||
expect((await screen.findAllByText("CP配置")).length).toBeGreaterThan(0);
|
expect((await screen.findAllByText("CP配置")).length).toBeGreaterThan(0);
|
||||||
expect(await screen.findByText("兄弟上限")).toBeInTheDocument();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test("admin routes declare menu code and permission", () => {
|
test("admin routes declare menu code and permission", () => {
|
||||||
expect(adminRoutes.length).toBeGreaterThan(0);
|
expect(adminRoutes.length).toBeGreaterThan(0);
|
||||||
expect(adminRoutes.every((route) => route.menuCode && route.permission)).toBe(true);
|
expect(adminRoutes.every((route) => route.menuCode && route.permission)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
function renderWithRoute(route) {
|
function renderWithRoute(route) {
|
||||||
return render(
|
return render(
|
||||||
<AppProviders>
|
<AppProviders>
|
||||||
<MemoryRouter initialEntries={[route]}>
|
<MemoryRouter initialEntries={[route]}>
|
||||||
<App />
|
<App />
|
||||||
</MemoryRouter>
|
</MemoryRouter>
|
||||||
</AppProviders>
|
</AppProviders>,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function jsonResponse(data) {
|
function jsonResponse(data) {
|
||||||
return new Response(JSON.stringify({ code: 0, data }), { status: 200 });
|
return new Response(JSON.stringify({ code: 0, data }), { status: 200 });
|
||||||
}
|
}
|
||||||
|
|
||||||
function cpRelationFixture(relationType, displayName, maxCountPerUser) {
|
function cpRelationFixture(relationType, displayName, maxCountPerUser) {
|
||||||
return {
|
return {
|
||||||
relationType,
|
relationType,
|
||||||
displayName,
|
displayName,
|
||||||
maxCountPerUser,
|
maxCountPerUser,
|
||||||
applicationExpireHours: 24,
|
applicationExpireHours: 24,
|
||||||
status: "active",
|
status: "active",
|
||||||
levels: Array.from({ length: 5 }, (_, index) => ({
|
levels: Array.from({ length: 5 }, (_, index) => ({
|
||||||
level: index + 1,
|
level: index + 1,
|
||||||
intimacyThreshold: index * 10000,
|
intimacyThreshold: index * 10000,
|
||||||
rewardResourceGroupId: 0,
|
rewardResourceGroupId: 0,
|
||||||
levelIconUrl: "",
|
levelIconUrl: "",
|
||||||
status: "active",
|
status: "active",
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -92,22 +92,84 @@
|
|||||||
.relationEditorList,
|
.relationEditorList,
|
||||||
.levelEditorList {
|
.levelEditorList {
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 12px;
|
gap: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.relationEditor,
|
.configDrawer {
|
||||||
.levelEditor {
|
box-sizing: border-box;
|
||||||
border: 1px solid var(--color-border-subtle);
|
width: min(980px, calc(100vw - 48px));
|
||||||
border-radius: 8px;
|
height: 100vh;
|
||||||
background: var(--color-surface-subtle);
|
max-height: 100vh;
|
||||||
|
grid-template-rows: auto minmax(0, 1fr) auto;
|
||||||
|
overflow: hidden;
|
||||||
|
padding: var(--space-5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.configDrawerHeader {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: var(--space-4);
|
||||||
|
padding-bottom: var(--space-3);
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.configDrawerHeader h2 {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.configDrawerStats {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: flex-end;
|
||||||
|
gap: var(--space-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.configDrawerStats span {
|
||||||
|
display: inline-flex;
|
||||||
|
height: var(--admin-tag-height);
|
||||||
|
align-items: center;
|
||||||
|
padding: 0 var(--space-3);
|
||||||
|
border: 1px solid var(--admin-tag-border);
|
||||||
|
border-radius: var(--admin-tag-radius);
|
||||||
|
background: var(--admin-tag-bg);
|
||||||
|
color: var(--admin-tag-color);
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 700;
|
||||||
|
}
|
||||||
|
|
||||||
|
.configDrawerBody {
|
||||||
|
min-height: 0;
|
||||||
|
overflow: auto;
|
||||||
|
padding-right: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.configDrawerActions {
|
||||||
|
padding-top: var(--space-3);
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
background: var(--bg-card);
|
||||||
}
|
}
|
||||||
|
|
||||||
.relationEditor {
|
.relationEditor {
|
||||||
padding: 14px;
|
border: 1px solid var(--color-border-subtle);
|
||||||
|
border-radius: 8px;
|
||||||
|
background: var(--bg-card);
|
||||||
|
}
|
||||||
|
|
||||||
|
.relationEditor {
|
||||||
|
padding: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.levelEditor {
|
.levelEditor {
|
||||||
padding: 12px;
|
display: grid;
|
||||||
|
gap: var(--space-3);
|
||||||
|
min-width: 0;
|
||||||
|
padding: 16px;
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: var(--radius-control);
|
||||||
|
background: var(--bg-card-strong);
|
||||||
}
|
}
|
||||||
|
|
||||||
.relationEditorHeader,
|
.relationEditorHeader,
|
||||||
@ -116,12 +178,54 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
gap: 12px;
|
gap: 12px;
|
||||||
margin-bottom: 12px;
|
margin-bottom: 14px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
}
|
}
|
||||||
|
|
||||||
.levelEditorList {
|
.levelEditorList {
|
||||||
margin-top: 12px;
|
grid-template-columns: repeat(2, minmax(320px, 1fr));
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.relationTitleGroup,
|
||||||
|
.levelTitleGroup {
|
||||||
|
display: grid;
|
||||||
|
min-width: 0;
|
||||||
|
gap: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.relationTitle,
|
||||||
|
.levelTitle {
|
||||||
|
color: var(--text-primary);
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: 800;
|
||||||
|
}
|
||||||
|
|
||||||
|
.relationSubtitle,
|
||||||
|
.levelMeta {
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
color: var(--text-tertiary);
|
||||||
|
font-size: 12px;
|
||||||
|
font-weight: 650;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.relationControls {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(2, minmax(220px, 1fr));
|
||||||
|
gap: var(--space-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.levelFields {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(140px, 0.7fr) minmax(220px, 1fr);
|
||||||
|
gap: var(--space-3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.levelFields > :last-child {
|
||||||
|
grid-column: 1 / -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 760px) {
|
@media (max-width: 760px) {
|
||||||
@ -133,4 +237,24 @@
|
|||||||
.summaryActions {
|
.summaryActions {
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.configDrawer {
|
||||||
|
width: 100vw;
|
||||||
|
padding: var(--space-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.configDrawerHeader {
|
||||||
|
align-items: flex-start;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.levelEditorList,
|
||||||
|
.relationControls,
|
||||||
|
.levelFields {
|
||||||
|
grid-template-columns: 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.levelFields > :last-child {
|
||||||
|
grid-column: auto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||||
import { getCPConfig, updateCPConfig } from "@/features/cp-config/api";
|
import { getCPConfig, updateCPConfig } from "@/features/cp-config/api";
|
||||||
import { useCPConfigAbilities } from "@/features/cp-config/permissions.js";
|
import { useCPConfigAbilities } from "@/features/cp-config/permissions.js";
|
||||||
|
import { listResourceGroups } from "@/features/resources/api";
|
||||||
import { useToast } from "@/shared/ui/ToastProvider.jsx";
|
import { useToast } from "@/shared/ui/ToastProvider.jsx";
|
||||||
|
|
||||||
export const cpRelationTypes = ["cp", "brother", "sister"];
|
export const cpRelationTypes = ["cp", "brother", "sister"];
|
||||||
@ -20,6 +21,7 @@ export function useCPConfigPage() {
|
|||||||
const [form, setForm] = useState({ relations: defaultRelations().map(relationToForm) });
|
const [form, setForm] = useState({ relations: defaultRelations().map(relationToForm) });
|
||||||
const [drawerOpen, setDrawerOpen] = useState(false);
|
const [drawerOpen, setDrawerOpen] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [resourceGroups, setResourceGroups] = useState([]);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
|
|
||||||
const activeRelationCount = useMemo(
|
const activeRelationCount = useMemo(
|
||||||
@ -30,10 +32,23 @@ export function useCPConfigPage() {
|
|||||||
const reload = useCallback(async () => {
|
const reload = useCallback(async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
const remoteConfig = await getCPConfig();
|
const [configResult, groupResult] = await Promise.allSettled([
|
||||||
const relations = completeRelations(remoteConfig.relations || []);
|
getCPConfig(),
|
||||||
setConfig({ ...remoteConfig, relations });
|
listResourceGroups({ page: 1, page_size: 200, status: "active" }),
|
||||||
setForm({ relations: relations.map(relationToForm) });
|
]);
|
||||||
|
if (configResult.status === "fulfilled") {
|
||||||
|
const remoteConfig = configResult.value;
|
||||||
|
const relations = completeRelations(remoteConfig.relations || []);
|
||||||
|
setConfig({ ...remoteConfig, relations });
|
||||||
|
setForm({ relations: relations.map(relationToForm) });
|
||||||
|
} else {
|
||||||
|
showToast(configResult.reason?.message || "加载 CP 配置失败", "error");
|
||||||
|
}
|
||||||
|
if (groupResult.status === "fulfilled") {
|
||||||
|
setResourceGroups(groupResult.value?.items || []);
|
||||||
|
} else {
|
||||||
|
showToast(groupResult.reason?.message || "加载资源组失败", "error");
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
showToast(err.message || "加载 CP 配置失败", "error");
|
showToast(err.message || "加载 CP 配置失败", "error");
|
||||||
} finally {
|
} finally {
|
||||||
@ -120,6 +135,7 @@ export function useCPConfigPage() {
|
|||||||
loading,
|
loading,
|
||||||
openDrawer,
|
openDrawer,
|
||||||
reload,
|
reload,
|
||||||
|
resourceGroups,
|
||||||
saving,
|
saving,
|
||||||
submit,
|
submit,
|
||||||
updateLevel,
|
updateLevel,
|
||||||
@ -218,7 +234,10 @@ function payloadFromForm(form) {
|
|||||||
|
|
||||||
function completeFormRelations(relations) {
|
function completeFormRelations(relations) {
|
||||||
const byType = new Map((relations || []).map((relation) => [relation.relationType, relation]));
|
const byType = new Map((relations || []).map((relation) => [relation.relationType, relation]));
|
||||||
return defaultRelations().map((fallback) => ({ ...relationToForm(fallback), ...(byType.get(fallback.relationType) || {}) }));
|
return defaultRelations().map((fallback) => ({
|
||||||
|
...relationToForm(fallback),
|
||||||
|
...(byType.get(fallback.relationType) || {}),
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function completeFormLevels(levels, relationType) {
|
function completeFormLevels(levels, relationType) {
|
||||||
|
|||||||
@ -4,16 +4,14 @@ import SaveOutlined from "@mui/icons-material/SaveOutlined";
|
|||||||
import Drawer from "@mui/material/Drawer";
|
import Drawer from "@mui/material/Drawer";
|
||||||
import TextField from "@mui/material/TextField";
|
import TextField from "@mui/material/TextField";
|
||||||
import { useMemo } from "react";
|
import { useMemo } from "react";
|
||||||
import {
|
import { cpRelationLabels, useCPConfigPage } from "@/features/cp-config/hooks/useCPConfigPage.js";
|
||||||
cpRelationLabels,
|
|
||||||
useCPConfigPage,
|
|
||||||
} from "@/features/cp-config/hooks/useCPConfigPage.js";
|
|
||||||
import styles from "@/features/cp-config/cp-config.module.css";
|
import styles from "@/features/cp-config/cp-config.module.css";
|
||||||
import { AdminListBody, AdminListPage } from "@/shared/ui/AdminListLayout.jsx";
|
import { AdminListBody, AdminListPage } from "@/shared/ui/AdminListLayout.jsx";
|
||||||
import { AdminSwitch } from "@/shared/ui/AdminSwitch.jsx";
|
import { AdminSwitch } from "@/shared/ui/AdminSwitch.jsx";
|
||||||
import { Button } from "@/shared/ui/Button.jsx";
|
import { Button } from "@/shared/ui/Button.jsx";
|
||||||
import { DataState } from "@/shared/ui/DataState.jsx";
|
import { DataState } from "@/shared/ui/DataState.jsx";
|
||||||
import { DataTable } from "@/shared/ui/DataTable.jsx";
|
import { DataTable } from "@/shared/ui/DataTable.jsx";
|
||||||
|
import { ResourceGroupSelectField } from "@/shared/ui/ResourceGroupSelectDrawer.jsx";
|
||||||
import { formatMillis } from "@/shared/utils/time.js";
|
import { formatMillis } from "@/shared/utils/time.js";
|
||||||
|
|
||||||
export function CPConfigPage() {
|
export function CPConfigPage() {
|
||||||
@ -31,7 +29,11 @@ export function CPConfigPage() {
|
|||||||
<SummaryItem label="姐妹上限">{relationMax(relations, "sister")}</SummaryItem>
|
<SummaryItem label="姐妹上限">{relationMax(relations, "sister")}</SummaryItem>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.summaryActions}>
|
<div className={styles.summaryActions}>
|
||||||
<Button disabled={page.loading} startIcon={<RefreshOutlined fontSize="small" />} onClick={page.reload}>
|
<Button
|
||||||
|
disabled={page.loading}
|
||||||
|
startIcon={<RefreshOutlined fontSize="small" />}
|
||||||
|
onClick={page.reload}
|
||||||
|
>
|
||||||
刷新
|
刷新
|
||||||
</Button>
|
</Button>
|
||||||
{page.abilities.canUpdate ? (
|
{page.abilities.canUpdate ? (
|
||||||
@ -48,7 +50,12 @@ export function CPConfigPage() {
|
|||||||
</div>
|
</div>
|
||||||
<DataState loading={page.loading} onRetry={page.reload}>
|
<DataState loading={page.loading} onRetry={page.reload}>
|
||||||
<AdminListBody>
|
<AdminListBody>
|
||||||
<DataTable columns={columns} items={relations} minWidth="1120px" rowKey={(item) => item.relationType} />
|
<DataTable
|
||||||
|
columns={columns}
|
||||||
|
items={relations}
|
||||||
|
minWidth="1120px"
|
||||||
|
rowKey={(item) => item.relationType}
|
||||||
|
/>
|
||||||
</AdminListBody>
|
</AdminListBody>
|
||||||
</DataState>
|
</DataState>
|
||||||
<CPConfigDrawer page={page} />
|
<CPConfigDrawer page={page} />
|
||||||
@ -60,23 +67,32 @@ function CPConfigDrawer({ page }) {
|
|||||||
const disabled = !page.abilities.canUpdate || page.saving || page.loading;
|
const disabled = !page.abilities.canUpdate || page.saving || page.loading;
|
||||||
return (
|
return (
|
||||||
<Drawer anchor="right" open={page.drawerOpen} onClose={page.saving ? undefined : page.closeDrawer}>
|
<Drawer anchor="right" open={page.drawerOpen} onClose={page.saving ? undefined : page.closeDrawer}>
|
||||||
<form className="form-drawer form-drawer--wide" onSubmit={page.submit}>
|
<form className={["form-drawer", styles.configDrawer].join(" ")} onSubmit={page.submit}>
|
||||||
<h2>CP配置</h2>
|
<div className={styles.configDrawerHeader}>
|
||||||
<section className="form-drawer__section">
|
<h2>CP配置</h2>
|
||||||
<div className="form-drawer__section-title">关系与等级</div>
|
<div className={styles.configDrawerStats}>
|
||||||
<div className={styles.relationEditorList}>
|
<span>{(page.form.relations || []).length} 个关系</span>
|
||||||
{(page.form.relations || []).map((relation) => (
|
<span>{page.activeRelationCount} 个启用</span>
|
||||||
<RelationEditor
|
|
||||||
disabled={disabled}
|
|
||||||
key={relation.relationType}
|
|
||||||
relation={relation}
|
|
||||||
updateLevel={page.updateLevel}
|
|
||||||
updateRelation={page.updateRelation}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</div>
|
||||||
<div className="form-drawer__actions">
|
<div className={styles.configDrawerBody}>
|
||||||
|
<section className="form-drawer__section">
|
||||||
|
<div className="form-drawer__section-title">关系与等级</div>
|
||||||
|
<div className={styles.relationEditorList}>
|
||||||
|
{(page.form.relations || []).map((relation) => (
|
||||||
|
<RelationEditor
|
||||||
|
disabled={disabled}
|
||||||
|
key={relation.relationType}
|
||||||
|
relation={relation}
|
||||||
|
resourceGroups={page.resourceGroups}
|
||||||
|
updateLevel={page.updateLevel}
|
||||||
|
updateRelation={page.updateRelation}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
<div className={["form-drawer__actions", styles.configDrawerActions].join(" ")}>
|
||||||
<Button disabled={page.saving} type="button" onClick={page.closeDrawer}>
|
<Button disabled={page.saving} type="button" onClick={page.closeDrawer}>
|
||||||
取消
|
取消
|
||||||
</Button>
|
</Button>
|
||||||
@ -94,14 +110,22 @@ function CPConfigDrawer({ page }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function RelationEditor({ disabled, relation, updateLevel, updateRelation }) {
|
function RelationEditor({ disabled, relation, resourceGroups, updateLevel, updateRelation }) {
|
||||||
const relationType = relation.relationType;
|
const relationType = relation.relationType;
|
||||||
const maxCountDisabled = disabled || relationType === "cp";
|
const maxCountDisabled = disabled || relationType === "cp";
|
||||||
|
const activeLevelCount = (relation.levels || []).filter((level) => level.status === "active").length;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.relationEditor}>
|
<div className={styles.relationEditor}>
|
||||||
<div className={styles.relationEditorHeader}>
|
<div className={styles.relationEditorHeader}>
|
||||||
<span>{relation.displayName || cpRelationLabels[relationType]}</span>
|
<div className={styles.relationTitleGroup}>
|
||||||
|
<span className={styles.relationTitle}>
|
||||||
|
{relation.displayName || cpRelationLabels[relationType]}
|
||||||
|
</span>
|
||||||
|
<span className={styles.relationSubtitle}>
|
||||||
|
{relationType} / {activeLevelCount} 个等级启用
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
<AdminSwitch
|
<AdminSwitch
|
||||||
checked={relation.status === "active"}
|
checked={relation.status === "active"}
|
||||||
checkedLabel="启用"
|
checkedLabel="启用"
|
||||||
@ -113,7 +137,7 @@ function RelationEditor({ disabled, relation, updateLevel, updateRelation }) {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="form-drawer__grid">
|
<div className={styles.relationControls}>
|
||||||
<TextField
|
<TextField
|
||||||
disabled={maxCountDisabled}
|
disabled={maxCountDisabled}
|
||||||
inputProps={{ min: 1, step: 1 }}
|
inputProps={{ min: 1, step: 1 }}
|
||||||
@ -138,6 +162,7 @@ function RelationEditor({ disabled, relation, updateLevel, updateRelation }) {
|
|||||||
key={`${relationType}-${level.level}`}
|
key={`${relationType}-${level.level}`}
|
||||||
level={level}
|
level={level}
|
||||||
relationType={relationType}
|
relationType={relationType}
|
||||||
|
resourceGroups={resourceGroups}
|
||||||
updateLevel={updateLevel}
|
updateLevel={updateLevel}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
@ -146,11 +171,18 @@ function RelationEditor({ disabled, relation, updateLevel, updateRelation }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function LevelEditor({ disabled, level, relationType, updateLevel }) {
|
function LevelEditor({ disabled, level, relationType, resourceGroups, updateLevel }) {
|
||||||
|
const selectedGroup = resourceGroups.find((group) => String(group.groupId) === String(level.rewardResourceGroupId));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.levelEditor}>
|
<div className={styles.levelEditor}>
|
||||||
<div className={styles.levelEditorHeader}>
|
<div className={styles.levelEditorHeader}>
|
||||||
<span>{level.level}级</span>
|
<div className={styles.levelTitleGroup}>
|
||||||
|
<span className={styles.levelTitle}>{level.level}级</span>
|
||||||
|
<span className={styles.levelMeta}>
|
||||||
|
{resourceGroupLabel(selectedGroup, level.rewardResourceGroupId)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
<AdminSwitch
|
<AdminSwitch
|
||||||
checked={level.status === "active"}
|
checked={level.status === "active"}
|
||||||
checkedLabel="启用"
|
checkedLabel="启用"
|
||||||
@ -164,7 +196,7 @@ function LevelEditor({ disabled, level, relationType, updateLevel }) {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="form-drawer__grid">
|
<div className={styles.levelFields}>
|
||||||
<TextField
|
<TextField
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
inputProps={{ min: 0, step: 1 }}
|
inputProps={{ min: 0, step: 1 }}
|
||||||
@ -175,15 +207,16 @@ function LevelEditor({ disabled, level, relationType, updateLevel }) {
|
|||||||
updateLevel(relationType, level.level, { intimacyThreshold: event.target.value })
|
updateLevel(relationType, level.level, { intimacyThreshold: event.target.value })
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<TextField
|
<ResourceGroupSelectField
|
||||||
|
allowEmpty
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
inputProps={{ min: 0, step: 1 }}
|
drawerTitle={`${cpRelationLabels[relationType]} ${level.level}级奖励资源组`}
|
||||||
label="奖励资源组ID"
|
emptyLabel="不配置奖励"
|
||||||
type="number"
|
groups={resourceGroups}
|
||||||
|
label="奖励资源组"
|
||||||
|
placeholder="点击选择奖励资源组"
|
||||||
value={level.rewardResourceGroupId}
|
value={level.rewardResourceGroupId}
|
||||||
onChange={(event) =>
|
onChange={(value) => updateLevel(relationType, level.level, { rewardResourceGroupId: value })}
|
||||||
updateLevel(relationType, level.level, { rewardResourceGroupId: event.target.value })
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
@ -277,6 +310,13 @@ function relationMax(relations, relationType) {
|
|||||||
return relation ? formatNumber(relation.maxCountPerUser) : "-";
|
return relation ? formatNumber(relation.maxCountPerUser) : "-";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resourceGroupLabel(group, value) {
|
||||||
|
if (group) {
|
||||||
|
return group.name || group.groupCode || `资源组 #${group.groupId}`;
|
||||||
|
}
|
||||||
|
return value ? `资源组 #${value}` : "未配置奖励";
|
||||||
|
}
|
||||||
|
|
||||||
function formatNumber(value) {
|
function formatNumber(value) {
|
||||||
return Number(value || 0).toLocaleString("zh-CN");
|
return Number(value || 0).toLocaleString("zh-CN");
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user