Compare commits
4 Commits
2f7e3bb86a
...
4ad96f07be
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ad96f07be | ||
|
|
ae8ae7db55 | ||
|
|
4520e16470 | ||
|
|
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",
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@ export interface CPRelationConfigDto {
|
|||||||
displayName: string;
|
displayName: string;
|
||||||
maxCountPerUser: number;
|
maxCountPerUser: number;
|
||||||
applicationExpireHours: number;
|
applicationExpireHours: number;
|
||||||
|
breakupCostCoins: number;
|
||||||
status: string;
|
status: string;
|
||||||
levels: CPLevelDto[];
|
levels: CPLevelDto[];
|
||||||
updatedAtMs?: number;
|
updatedAtMs?: number;
|
||||||
@ -32,6 +33,7 @@ export interface CPConfigPayload {
|
|||||||
relationType: CPRelationType;
|
relationType: CPRelationType;
|
||||||
maxCountPerUser: number;
|
maxCountPerUser: number;
|
||||||
applicationExpireHours: number;
|
applicationExpireHours: number;
|
||||||
|
breakupCostCoins: number;
|
||||||
status: string;
|
status: string;
|
||||||
levels: Array<{
|
levels: Array<{
|
||||||
level: number;
|
level: number;
|
||||||
@ -74,6 +76,7 @@ function normalizeRelation(raw: unknown): CPRelationConfigDto {
|
|||||||
displayName: stringValue(item.displayName ?? item.display_name) || relationLabel(relationType),
|
displayName: stringValue(item.displayName ?? item.display_name) || relationLabel(relationType),
|
||||||
maxCountPerUser: numberValue(item.maxCountPerUser ?? item.max_count_per_user),
|
maxCountPerUser: numberValue(item.maxCountPerUser ?? item.max_count_per_user),
|
||||||
applicationExpireHours: numberValue(item.applicationExpireHours ?? item.application_expire_hours),
|
applicationExpireHours: numberValue(item.applicationExpireHours ?? item.application_expire_hours),
|
||||||
|
breakupCostCoins: numberValue(item.breakupCostCoins ?? item.breakup_cost_coins),
|
||||||
status: stringValue(item.status) || "active",
|
status: stringValue(item.status) || "active",
|
||||||
levels: arrayValue(item.levels).map(normalizeLevel),
|
levels: arrayValue(item.levels).map(normalizeLevel),
|
||||||
updatedAtMs: numberValue(item.updatedAtMs ?? item.updated_at_ms),
|
updatedAtMs: numberValue(item.updatedAtMs ?? item.updated_at_ms),
|
||||||
|
|||||||
@ -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(3, minmax(180px, 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,
|
||||||
@ -133,6 +149,7 @@ export function defaultRelations() {
|
|||||||
displayName: cpRelationLabels[relationType],
|
displayName: cpRelationLabels[relationType],
|
||||||
maxCountPerUser: relationType === "cp" ? 1 : 5,
|
maxCountPerUser: relationType === "cp" ? 1 : 5,
|
||||||
applicationExpireHours: defaultExpireHours,
|
applicationExpireHours: defaultExpireHours,
|
||||||
|
breakupCostCoins: 0,
|
||||||
status: "active",
|
status: "active",
|
||||||
levels: defaultLevels(),
|
levels: defaultLevels(),
|
||||||
updatedAtMs: 0,
|
updatedAtMs: 0,
|
||||||
@ -178,6 +195,7 @@ function relationToForm(relation) {
|
|||||||
displayName: relation.displayName || cpRelationLabels[relation.relationType],
|
displayName: relation.displayName || cpRelationLabels[relation.relationType],
|
||||||
maxCountPerUser: relation.relationType === "cp" ? "1" : String(relation.maxCountPerUser || 5),
|
maxCountPerUser: relation.relationType === "cp" ? "1" : String(relation.maxCountPerUser || 5),
|
||||||
applicationExpireHours: String(relation.applicationExpireHours || defaultExpireHours),
|
applicationExpireHours: String(relation.applicationExpireHours || defaultExpireHours),
|
||||||
|
breakupCostCoins: String(relation.breakupCostCoins || 0),
|
||||||
status: relation.status || "active",
|
status: relation.status || "active",
|
||||||
levels: completeLevels(relation.levels || []).map(levelToForm),
|
levels: completeLevels(relation.levels || []).map(levelToForm),
|
||||||
};
|
};
|
||||||
@ -198,6 +216,7 @@ function payloadFromForm(form) {
|
|||||||
const relationType = relation.relationType;
|
const relationType = relation.relationType;
|
||||||
const maxCountPerUser = relationType === "cp" ? 1 : Number(relation.maxCountPerUser || 0);
|
const maxCountPerUser = relationType === "cp" ? 1 : Number(relation.maxCountPerUser || 0);
|
||||||
const applicationExpireHours = Number(relation.applicationExpireHours || 0);
|
const applicationExpireHours = Number(relation.applicationExpireHours || 0);
|
||||||
|
const breakupCostCoins = Number(relation.breakupCostCoins || 0);
|
||||||
const status = relation.status === "disabled" ? "disabled" : "active";
|
const status = relation.status === "disabled" ? "disabled" : "active";
|
||||||
if (!Number.isInteger(maxCountPerUser) || maxCountPerUser <= 0) {
|
if (!Number.isInteger(maxCountPerUser) || maxCountPerUser <= 0) {
|
||||||
throw new Error(`${cpRelationLabels[relationType]}数量必须大于 0`);
|
throw new Error(`${cpRelationLabels[relationType]}数量必须大于 0`);
|
||||||
@ -205,10 +224,14 @@ function payloadFromForm(form) {
|
|||||||
if (!Number.isInteger(applicationExpireHours) || applicationExpireHours <= 0) {
|
if (!Number.isInteger(applicationExpireHours) || applicationExpireHours <= 0) {
|
||||||
throw new Error(`${cpRelationLabels[relationType]}申请过期小时必须大于 0`);
|
throw new Error(`${cpRelationLabels[relationType]}申请过期小时必须大于 0`);
|
||||||
}
|
}
|
||||||
|
if (!Number.isInteger(breakupCostCoins) || breakupCostCoins < 0) {
|
||||||
|
throw new Error(`${cpRelationLabels[relationType]}解除费用不能小于 0`);
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
relationType,
|
relationType,
|
||||||
maxCountPerUser,
|
maxCountPerUser,
|
||||||
applicationExpireHours,
|
applicationExpireHours,
|
||||||
|
breakupCostCoins,
|
||||||
status,
|
status,
|
||||||
levels: completeFormLevels(relation.levels || [], relationType),
|
levels: completeFormLevels(relation.levels || [], relationType),
|
||||||
};
|
};
|
||||||
@ -218,7 +241,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() {
|
||||||
@ -29,9 +27,14 @@ export function CPConfigPage() {
|
|||||||
<SummaryItem label="启用类型">{page.activeRelationCount}</SummaryItem>
|
<SummaryItem label="启用类型">{page.activeRelationCount}</SummaryItem>
|
||||||
<SummaryItem label="兄弟上限">{relationMax(relations, "brother")}</SummaryItem>
|
<SummaryItem label="兄弟上限">{relationMax(relations, "brother")}</SummaryItem>
|
||||||
<SummaryItem label="姐妹上限">{relationMax(relations, "sister")}</SummaryItem>
|
<SummaryItem label="姐妹上限">{relationMax(relations, "sister")}</SummaryItem>
|
||||||
|
<SummaryItem label="CP解除费">{relationBreakupCost(relations, "cp")}</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 +51,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 +68,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 +111,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 +138,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 }}
|
||||||
@ -130,6 +155,14 @@ function RelationEditor({ disabled, relation, updateLevel, updateRelation }) {
|
|||||||
value={relation.applicationExpireHours}
|
value={relation.applicationExpireHours}
|
||||||
onChange={(event) => updateRelation(relationType, { applicationExpireHours: event.target.value })}
|
onChange={(event) => updateRelation(relationType, { applicationExpireHours: event.target.value })}
|
||||||
/>
|
/>
|
||||||
|
<TextField
|
||||||
|
disabled={disabled}
|
||||||
|
inputProps={{ min: 0, step: 1 }}
|
||||||
|
label="解除费用金币"
|
||||||
|
type="number"
|
||||||
|
value={relation.breakupCostCoins}
|
||||||
|
onChange={(event) => updateRelation(relationType, { breakupCostCoins: event.target.value })}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className={styles.levelEditorList}>
|
<div className={styles.levelEditorList}>
|
||||||
{(relation.levels || []).map((level) => (
|
{(relation.levels || []).map((level) => (
|
||||||
@ -138,6 +171,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 +180,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 +205,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 +216,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}
|
||||||
@ -221,10 +263,16 @@ function cpConfigColumns() {
|
|||||||
width: "minmax(130px, 0.45fr)",
|
width: "minmax(130px, 0.45fr)",
|
||||||
render: (item) => `${formatNumber(item.applicationExpireHours)} 小时`,
|
render: (item) => `${formatNumber(item.applicationExpireHours)} 小时`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: "breakupCost",
|
||||||
|
label: "解除费用",
|
||||||
|
width: "minmax(130px, 0.45fr)",
|
||||||
|
render: (item) => `${formatNumber(item.breakupCostCoins)} 金币`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: "levels",
|
key: "levels",
|
||||||
label: "等级亲密值",
|
label: "等级亲密值",
|
||||||
width: "minmax(360px, 1.3fr)",
|
width: "minmax(360px, 1.2fr)",
|
||||||
render: (item) => <LevelPreview levels={item.levels || []} />,
|
render: (item) => <LevelPreview levels={item.levels || []} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -277,6 +325,18 @@ function relationMax(relations, relationType) {
|
|||||||
return relation ? formatNumber(relation.maxCountPerUser) : "-";
|
return relation ? formatNumber(relation.maxCountPerUser) : "-";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function relationBreakupCost(relations, relationType) {
|
||||||
|
const relation = relations.find((item) => item.relationType === relationType);
|
||||||
|
return relation ? `${formatNumber(relation.breakupCostCoins)} 金币` : "-";
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,6 +48,17 @@ const defaultPlatformForm = {
|
|||||||
sortOrder: 0,
|
sortOrder: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const defaultBridgeScriptForm = {
|
||||||
|
bridgeScriptUrl: "",
|
||||||
|
bridgeScriptVersion: "",
|
||||||
|
bridgeScriptSha256: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaultBridgeHashState = {
|
||||||
|
loading: false,
|
||||||
|
error: "",
|
||||||
|
};
|
||||||
|
|
||||||
const emptyCatalog = { items: [], pageSize: 50 };
|
const emptyCatalog = { items: [], pageSize: 50 };
|
||||||
const emptyPlatforms = { items: [] };
|
const emptyPlatforms = { items: [] };
|
||||||
const defaultPageSize = 50;
|
const defaultPageSize = 50;
|
||||||
@ -69,6 +80,8 @@ export function useGamesPage() {
|
|||||||
const [editingPlatformCode, setEditingPlatformCode] = useState("");
|
const [editingPlatformCode, setEditingPlatformCode] = useState("");
|
||||||
const [gameForm, setGameForm] = useState(defaultGameForm);
|
const [gameForm, setGameForm] = useState(defaultGameForm);
|
||||||
const [platformForm, setPlatformForm] = useState(defaultPlatformForm);
|
const [platformForm, setPlatformForm] = useState(defaultPlatformForm);
|
||||||
|
const [bridgeScriptForm, setBridgeScriptForm] = useState(defaultBridgeScriptForm);
|
||||||
|
const [bridgeHashState, setBridgeHashState] = useState(defaultBridgeHashState);
|
||||||
const [loadingAction, setLoadingAction] = useState("");
|
const [loadingAction, setLoadingAction] = useState("");
|
||||||
const [syncPlatform, setSyncPlatform] = useState(null);
|
const [syncPlatform, setSyncPlatform] = useState(null);
|
||||||
const [syncCandidates, setSyncCandidates] = useState([]);
|
const [syncCandidates, setSyncCandidates] = useState([]);
|
||||||
@ -104,7 +117,9 @@ export function useGamesPage() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
setCatalogMeta(result);
|
setCatalogMeta(result);
|
||||||
setCatalogItems((current) => (append ? mergeCatalogItems(current, result.items || []) : result.items || []));
|
setCatalogItems((current) =>
|
||||||
|
append ? mergeCatalogItems(current, result.items || []) : result.items || [],
|
||||||
|
);
|
||||||
return result;
|
return result;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (catalogRequestRef.current === requestId) {
|
if (catalogRequestRef.current === requestId) {
|
||||||
@ -200,6 +215,12 @@ export function useGamesPage() {
|
|||||||
setActiveAction("manage-platforms");
|
setActiveAction("manage-platforms");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const openBridgeScript = () => {
|
||||||
|
setBridgeScriptForm(bridgeScriptFormFromPlatforms(platformData.items || []));
|
||||||
|
setBridgeHashState(defaultBridgeHashState);
|
||||||
|
setActiveAction("bridge-script");
|
||||||
|
};
|
||||||
|
|
||||||
const openEditPlatform = (platform) => {
|
const openEditPlatform = (platform) => {
|
||||||
setEditingPlatformCode(platform.platformCode);
|
setEditingPlatformCode(platform.platformCode);
|
||||||
setPlatformForm(platformToForm(platform));
|
setPlatformForm(platformToForm(platform));
|
||||||
@ -212,11 +233,80 @@ export function useGamesPage() {
|
|||||||
setSyncCandidates([]);
|
setSyncCandidates([]);
|
||||||
setSelectedSyncGameIds([]);
|
setSelectedSyncGameIds([]);
|
||||||
}
|
}
|
||||||
|
if (activeAction === "bridge-script") {
|
||||||
|
setBridgeScriptForm(defaultBridgeScriptForm);
|
||||||
|
setBridgeHashState(defaultBridgeHashState);
|
||||||
|
}
|
||||||
setActiveAction("");
|
setActiveAction("");
|
||||||
setEditingGameId("");
|
setEditingGameId("");
|
||||||
setEditingPlatformCode("");
|
setEditingPlatformCode("");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const refreshBridgeScriptHash = useCallback(async () => {
|
||||||
|
const url = bridgeScriptForm.bridgeScriptUrl.trim();
|
||||||
|
if (activeAction !== "bridge-script" || url === "") {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
setBridgeHashState({ loading: true, error: "" });
|
||||||
|
try {
|
||||||
|
const hash = await calculateBridgeScriptSha256(url);
|
||||||
|
setBridgeScriptForm((current) => {
|
||||||
|
if (current.bridgeScriptUrl.trim() !== url) {
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
return { ...current, bridgeScriptSha256: hash };
|
||||||
|
});
|
||||||
|
setBridgeHashState(defaultBridgeHashState);
|
||||||
|
return hash;
|
||||||
|
} catch (err) {
|
||||||
|
const message = err.message || "生成 SHA256 失败";
|
||||||
|
setBridgeHashState({ loading: false, error: message });
|
||||||
|
showToast(message, "error");
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}, [activeAction, bridgeScriptForm.bridgeScriptUrl, showToast]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (activeAction !== "bridge-script") {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const url = bridgeScriptForm.bridgeScriptUrl.trim();
|
||||||
|
const version = bridgeScriptForm.bridgeScriptVersion.trim();
|
||||||
|
if (!url || !version) {
|
||||||
|
setBridgeScriptForm((current) =>
|
||||||
|
current.bridgeScriptSha256 ? { ...current, bridgeScriptSha256: "" } : current,
|
||||||
|
);
|
||||||
|
setBridgeHashState(defaultBridgeHashState);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
let cancelled = false;
|
||||||
|
const timer = window.setTimeout(async () => {
|
||||||
|
setBridgeHashState({ loading: true, error: "" });
|
||||||
|
try {
|
||||||
|
const hash = await calculateBridgeScriptSha256(url);
|
||||||
|
if (cancelled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setBridgeScriptForm((current) => {
|
||||||
|
if (current.bridgeScriptUrl.trim() !== url || current.bridgeScriptVersion.trim() !== version) {
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
return { ...current, bridgeScriptSha256: hash };
|
||||||
|
});
|
||||||
|
setBridgeHashState(defaultBridgeHashState);
|
||||||
|
} catch (err) {
|
||||||
|
if (cancelled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setBridgeHashState({ loading: false, error: err.message || "生成 SHA256 失败" });
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
window.clearTimeout(timer);
|
||||||
|
};
|
||||||
|
}, [activeAction, bridgeScriptForm.bridgeScriptUrl, bridgeScriptForm.bridgeScriptVersion]);
|
||||||
|
|
||||||
const submitGame = async (event) => {
|
const submitGame = async (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const payload = gamePayload(gameForm);
|
const payload = gamePayload(gameForm);
|
||||||
@ -258,6 +348,54 @@ export function useGamesPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const submitBridgeScript = async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const platforms = platformData.items || [];
|
||||||
|
if (platforms.length === 0) {
|
||||||
|
showToast("暂无游戏平台可写入", "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const bridgeScriptUrl = bridgeScriptForm.bridgeScriptUrl.trim();
|
||||||
|
const bridgeScriptVersion = bridgeScriptForm.bridgeScriptVersion.trim();
|
||||||
|
if (!bridgeScriptUrl || !bridgeScriptVersion) {
|
||||||
|
showToast("请填写 bridge_script_url 和 bridge_script_version", "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let bridgeScriptSha256 = bridgeScriptForm.bridgeScriptSha256.trim();
|
||||||
|
if (!bridgeScriptSha256) {
|
||||||
|
bridgeScriptSha256 = await refreshBridgeScriptHash();
|
||||||
|
}
|
||||||
|
if (!bridgeScriptSha256) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setLoadingAction("bridge-script");
|
||||||
|
try {
|
||||||
|
await Promise.all(
|
||||||
|
platforms.map((platform) => {
|
||||||
|
const config = parseJsonObject(platform.adapterConfigJson);
|
||||||
|
config.bridge_script_url = bridgeScriptUrl;
|
||||||
|
config.bridge_script_version = bridgeScriptVersion;
|
||||||
|
config.bridge_script_sha256 = bridgeScriptSha256;
|
||||||
|
delete config.bridgeScriptUrl;
|
||||||
|
delete config.bridgeScriptVersion;
|
||||||
|
delete config.bridgeScriptSha256;
|
||||||
|
return upsertGamePlatform(
|
||||||
|
platformUpsertPayload(platform, JSON.stringify(config, null, 2)),
|
||||||
|
platform.platformCode,
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
await reloadPlatforms();
|
||||||
|
await reloadCatalog();
|
||||||
|
showToast(`JS 桥接配置已同步 ${platforms.length} 个平台`, "success");
|
||||||
|
closeAction();
|
||||||
|
} catch (err) {
|
||||||
|
showToast(err.message || "保存 JS 桥接配置失败", "error");
|
||||||
|
} finally {
|
||||||
|
setLoadingAction("");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const changeGameStatus = async (game, checked) => {
|
const changeGameStatus = async (game, checked) => {
|
||||||
const nextStatus = checked ? "active" : "maintenance";
|
const nextStatus = checked ? "active" : "maintenance";
|
||||||
setLoadingAction(`status-${game.gameId}`);
|
setLoadingAction(`status-${game.gameId}`);
|
||||||
@ -380,6 +518,8 @@ export function useGamesPage() {
|
|||||||
abilities,
|
abilities,
|
||||||
activeAction,
|
activeAction,
|
||||||
allSyncGamesSelected,
|
allSyncGamesSelected,
|
||||||
|
bridgeHashState,
|
||||||
|
bridgeScriptForm,
|
||||||
changeGameStatus,
|
changeGameStatus,
|
||||||
deleteGame,
|
deleteGame,
|
||||||
closeAction,
|
closeAction,
|
||||||
@ -400,6 +540,7 @@ export function useGamesPage() {
|
|||||||
importSingleSyncGame,
|
importSingleSyncGame,
|
||||||
openCreateGame,
|
openCreateGame,
|
||||||
openCreatePlatform,
|
openCreatePlatform,
|
||||||
|
openBridgeScript,
|
||||||
openEditGame,
|
openEditGame,
|
||||||
openEditPlatform,
|
openEditPlatform,
|
||||||
openManagePlatforms,
|
openManagePlatforms,
|
||||||
@ -409,15 +550,18 @@ export function useGamesPage() {
|
|||||||
platformForm,
|
platformForm,
|
||||||
platformOptions,
|
platformOptions,
|
||||||
loadNextPage,
|
loadNextPage,
|
||||||
|
refreshBridgeScriptHash,
|
||||||
reload: reloadCatalog,
|
reload: reloadCatalog,
|
||||||
resetFilters,
|
resetFilters,
|
||||||
resolveGameURL,
|
resolveGameURL,
|
||||||
changePageSize,
|
changePageSize,
|
||||||
setGameForm,
|
setGameForm,
|
||||||
|
setBridgeScriptForm,
|
||||||
setPlatformCode: changePlatformCode,
|
setPlatformCode: changePlatformCode,
|
||||||
setPlatformForm,
|
setPlatformForm,
|
||||||
setStatus: changeStatus,
|
setStatus: changeStatus,
|
||||||
status,
|
status,
|
||||||
|
submitBridgeScript,
|
||||||
submitGame,
|
submitGame,
|
||||||
submitPlatform,
|
submitPlatform,
|
||||||
syncCandidates,
|
syncCandidates,
|
||||||
@ -440,6 +584,66 @@ function mergeCatalogItems(current, nextItems) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function bridgeScriptFormFromPlatform(platform) {
|
||||||
|
if (!platform) {
|
||||||
|
return defaultBridgeScriptForm;
|
||||||
|
}
|
||||||
|
const config = parseJsonObject(platform.adapterConfigJson);
|
||||||
|
return {
|
||||||
|
bridgeScriptUrl: readConfigString(config.bridge_script_url ?? config.bridgeScriptUrl),
|
||||||
|
bridgeScriptVersion: readConfigString(config.bridge_script_version ?? config.bridgeScriptVersion),
|
||||||
|
bridgeScriptSha256: readConfigString(
|
||||||
|
config.bridge_script_sha256 ?? config.bridgeScriptSha256 ?? config.bridge_script_hash,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function bridgeScriptFormFromPlatforms(platforms) {
|
||||||
|
for (const platform of platforms) {
|
||||||
|
const form = bridgeScriptFormFromPlatform(platform);
|
||||||
|
if (form.bridgeScriptUrl || form.bridgeScriptVersion || form.bridgeScriptSha256) {
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultBridgeScriptForm;
|
||||||
|
}
|
||||||
|
|
||||||
|
function readConfigString(value) {
|
||||||
|
if (value === null || value === undefined) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return String(value).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function platformUpsertPayload(platform, adapterConfigJson) {
|
||||||
|
return {
|
||||||
|
platformCode: platform.platformCode,
|
||||||
|
platformName: platform.platformName,
|
||||||
|
status: platform.status,
|
||||||
|
apiBaseUrl: platform.apiBaseUrl,
|
||||||
|
adapterType: platform.adapterType,
|
||||||
|
callbackSecret: "",
|
||||||
|
callbackIpWhitelist: platform.callbackIpWhitelist || [],
|
||||||
|
adapterConfigJson,
|
||||||
|
sortOrder: Number(platform.sortOrder || 0),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function calculateBridgeScriptSha256(url) {
|
||||||
|
if (!window.crypto?.subtle) {
|
||||||
|
throw new Error("当前浏览器不支持 SHA256 计算");
|
||||||
|
}
|
||||||
|
const response = await fetch(url, { cache: "no-store" });
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(`拉取 JS 失败:HTTP ${response.status}`);
|
||||||
|
}
|
||||||
|
const buffer = await response.arrayBuffer();
|
||||||
|
const digest = await window.crypto.subtle.digest("SHA-256", buffer);
|
||||||
|
return Array.from(new Uint8Array(digest))
|
||||||
|
.map((byte) => byte.toString(16).padStart(2, "0"))
|
||||||
|
.join("");
|
||||||
|
}
|
||||||
|
|
||||||
async function saveGameUrl(platforms, game, gameUrl) {
|
async function saveGameUrl(platforms, game, gameUrl) {
|
||||||
const platform = platforms.find((item) => item.platformCode === game.platformCode);
|
const platform = platforms.find((item) => item.platformCode === game.platformCode);
|
||||||
if (!platform) {
|
if (!platform) {
|
||||||
@ -452,9 +656,10 @@ async function saveGameUrl(platforms, game, gameUrl) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const config = parseJsonObject(platform.adapterConfigJson);
|
const config = parseJsonObject(platform.adapterConfigJson);
|
||||||
const gameURLs = config.game_urls && typeof config.game_urls === "object" && !Array.isArray(config.game_urls)
|
const gameURLs =
|
||||||
? { ...config.game_urls }
|
config.game_urls && typeof config.game_urls === "object" && !Array.isArray(config.game_urls)
|
||||||
: {};
|
? { ...config.game_urls }
|
||||||
|
: {};
|
||||||
const keys = gameUrlKeys(game);
|
const keys = gameUrlKeys(game);
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
delete gameURLs[key];
|
delete gameURLs[key];
|
||||||
@ -468,20 +673,7 @@ async function saveGameUrl(platforms, game, gameUrl) {
|
|||||||
delete config.game_urls;
|
delete config.game_urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
await upsertGamePlatform(
|
await upsertGamePlatform(platformUpsertPayload(platform, JSON.stringify(config, null, 2)), platform.platformCode);
|
||||||
{
|
|
||||||
platformCode: platform.platformCode,
|
|
||||||
platformName: platform.platformName,
|
|
||||||
status: platform.status,
|
|
||||||
apiBaseUrl: platform.apiBaseUrl,
|
|
||||||
adapterType: platform.adapterType,
|
|
||||||
callbackSecret: "",
|
|
||||||
callbackIpWhitelist: platform.callbackIpWhitelist || [],
|
|
||||||
adapterConfigJson: JSON.stringify(config, null, 2),
|
|
||||||
sortOrder: Number(platform.sortOrder || 0),
|
|
||||||
},
|
|
||||||
platform.platformCode,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function gameToForm(game, platforms = []) {
|
function gameToForm(game, platforms = []) {
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import Add from "@mui/icons-material/Add";
|
import Add from "@mui/icons-material/Add";
|
||||||
|
import CodeOutlined from "@mui/icons-material/CodeOutlined";
|
||||||
import DeleteOutlineOutlined from "@mui/icons-material/DeleteOutlineOutlined";
|
import DeleteOutlineOutlined from "@mui/icons-material/DeleteOutlineOutlined";
|
||||||
import EditOutlined from "@mui/icons-material/EditOutlined";
|
import EditOutlined from "@mui/icons-material/EditOutlined";
|
||||||
import SettingsOutlined from "@mui/icons-material/SettingsOutlined";
|
import SettingsOutlined from "@mui/icons-material/SettingsOutlined";
|
||||||
@ -148,6 +149,11 @@ export function GameListPage() {
|
|||||||
<AdminListToolbar
|
<AdminListToolbar
|
||||||
actions={
|
actions={
|
||||||
<>
|
<>
|
||||||
|
{page.abilities.canUpdate ? (
|
||||||
|
<AdminActionIconButton label="JS 桥接" onClick={page.openBridgeScript}>
|
||||||
|
<CodeOutlined fontSize="small" />
|
||||||
|
</AdminActionIconButton>
|
||||||
|
) : null}
|
||||||
{page.abilities.canUpdate ? (
|
{page.abilities.canUpdate ? (
|
||||||
<AdminActionIconButton label="平台配置" onClick={page.openManagePlatforms}>
|
<AdminActionIconButton label="平台配置" onClick={page.openManagePlatforms}>
|
||||||
<SettingsOutlined fontSize="small" />
|
<SettingsOutlined fontSize="small" />
|
||||||
@ -209,6 +215,14 @@ export function GameListPage() {
|
|||||||
onClose={page.closeAction}
|
onClose={page.closeAction}
|
||||||
onSubmit={page.submitPlatform}
|
onSubmit={page.submitPlatform}
|
||||||
/>
|
/>
|
||||||
|
<BridgeScriptDialog
|
||||||
|
form={page.bridgeScriptForm}
|
||||||
|
loading={page.loadingAction === "bridge-script"}
|
||||||
|
open={page.activeAction === "bridge-script"}
|
||||||
|
page={page}
|
||||||
|
onClose={page.closeAction}
|
||||||
|
onSubmit={page.submitBridgeScript}
|
||||||
|
/>
|
||||||
<PlatformManageDialog
|
<PlatformManageDialog
|
||||||
open={page.activeAction === "manage-platforms"}
|
open={page.activeAction === "manage-platforms"}
|
||||||
page={page}
|
page={page}
|
||||||
@ -419,6 +433,73 @@ function GameFormDialog({ form, loading, mode, open, page, onClose, onSubmit })
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function BridgeScriptDialog({ form, loading, open, page, onClose, onSubmit }) {
|
||||||
|
const hashState = page.bridgeHashState || {};
|
||||||
|
const disabled = !page.abilities.canUpdate;
|
||||||
|
const submitDisabled =
|
||||||
|
disabled ||
|
||||||
|
loading ||
|
||||||
|
hashState.loading ||
|
||||||
|
!form.bridgeScriptUrl.trim() ||
|
||||||
|
!form.bridgeScriptVersion.trim() ||
|
||||||
|
!form.bridgeScriptSha256.trim();
|
||||||
|
return (
|
||||||
|
<AdminFormDialog
|
||||||
|
disabled={disabled}
|
||||||
|
loading={loading}
|
||||||
|
open={open}
|
||||||
|
submitDisabled={submitDisabled}
|
||||||
|
submitLabel="保存桥接"
|
||||||
|
title="JS 桥接配置"
|
||||||
|
onClose={onClose}
|
||||||
|
onSubmit={onSubmit}
|
||||||
|
>
|
||||||
|
<AdminFormSection
|
||||||
|
title="通用桥接脚本"
|
||||||
|
actions={
|
||||||
|
<Button
|
||||||
|
disabled={disabled || hashState.loading || !form.bridgeScriptUrl.trim()}
|
||||||
|
onClick={page.refreshBridgeScriptHash}
|
||||||
|
>
|
||||||
|
{hashState.loading ? "生成中..." : "重新生成 SHA256"}
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<AdminFormFieldGrid columns="repeat(2, minmax(0, 1fr))">
|
||||||
|
<TextField
|
||||||
|
label="bridge_script_version"
|
||||||
|
required
|
||||||
|
value={form.bridgeScriptVersion}
|
||||||
|
onChange={(event) =>
|
||||||
|
page.setBridgeScriptForm({ ...form, bridgeScriptVersion: event.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
className={styles.fullField}
|
||||||
|
label="bridge_script_url"
|
||||||
|
minRows={2}
|
||||||
|
multiline
|
||||||
|
required
|
||||||
|
value={form.bridgeScriptUrl}
|
||||||
|
onChange={(event) => page.setBridgeScriptForm({ ...form, bridgeScriptUrl: event.target.value })}
|
||||||
|
/>
|
||||||
|
<TextField
|
||||||
|
className={styles.fullField}
|
||||||
|
error={Boolean(hashState.error)}
|
||||||
|
helperText={hashState.error || (hashState.loading ? "正在拉取 JS 并计算 SHA256" : "")}
|
||||||
|
label="bridge_script_sha256"
|
||||||
|
required
|
||||||
|
value={form.bridgeScriptSha256}
|
||||||
|
onChange={(event) =>
|
||||||
|
page.setBridgeScriptForm({ ...form, bridgeScriptSha256: event.target.value })
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</AdminFormFieldGrid>
|
||||||
|
</AdminFormSection>
|
||||||
|
</AdminFormDialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function PlatformFormDialog({ form, loading, mode, open, page, onClose, onSubmit }) {
|
function PlatformFormDialog({ form, loading, mode, open, page, onClose, onSubmit }) {
|
||||||
const isLeaderCC = form.adapterType === "leadercc_v1";
|
const isLeaderCC = form.adapterType === "leadercc_v1";
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -51,6 +51,7 @@ test("resource APIs use generated admin paths", async () => {
|
|||||||
badgeKind: "level",
|
badgeKind: "level",
|
||||||
coinPrice: 10,
|
coinPrice: 10,
|
||||||
levelTrack: "wealth",
|
levelTrack: "wealth",
|
||||||
|
managerGrantEnabled: true,
|
||||||
metadataJson: '{"profile_card_layout":{"content_top":117,"content_height":1550}}',
|
metadataJson: '{"profile_card_layout":{"content_top":117,"content_height":1550}}',
|
||||||
name: "VIP Badge",
|
name: "VIP Badge",
|
||||||
previewUrl: "https://media.haiyihy.com/resource/cover.png",
|
previewUrl: "https://media.haiyihy.com/resource/cover.png",
|
||||||
@ -66,6 +67,7 @@ test("resource APIs use generated admin paths", async () => {
|
|||||||
badgeForm: "tile",
|
badgeForm: "tile",
|
||||||
badgeKind: "normal",
|
badgeKind: "normal",
|
||||||
coinPrice: 20,
|
coinPrice: 20,
|
||||||
|
managerGrantEnabled: false,
|
||||||
metadataJson: '{"profile_card_layout":{"content_top":120,"content_height":1500}}',
|
metadataJson: '{"profile_card_layout":{"content_top":120,"content_height":1500}}',
|
||||||
name: "VIP Badge Updated",
|
name: "VIP Badge Updated",
|
||||||
previewUrl: "https://media.haiyihy.com/resource/cover-updated.png",
|
previewUrl: "https://media.haiyihy.com/resource/cover-updated.png",
|
||||||
@ -79,6 +81,7 @@ test("resource APIs use generated admin paths", async () => {
|
|||||||
await createGift({
|
await createGift({
|
||||||
chargeAssetType: "COIN",
|
chargeAssetType: "COIN",
|
||||||
coinPrice: 10,
|
coinPrice: 10,
|
||||||
|
cpRelationType: "",
|
||||||
effectiveAtMs: 1777766400000,
|
effectiveAtMs: 1777766400000,
|
||||||
effectiveFromMs: 0,
|
effectiveFromMs: 0,
|
||||||
effectiveToMs: 0,
|
effectiveToMs: 0,
|
||||||
@ -129,6 +132,7 @@ test("resource APIs use generated admin paths", async () => {
|
|||||||
await updateGift("rose", {
|
await updateGift("rose", {
|
||||||
chargeAssetType: "COIN",
|
chargeAssetType: "COIN",
|
||||||
coinPrice: 10,
|
coinPrice: 10,
|
||||||
|
cpRelationType: "",
|
||||||
effectiveAtMs: 1777766400000,
|
effectiveAtMs: 1777766400000,
|
||||||
effectiveFromMs: 0,
|
effectiveFromMs: 0,
|
||||||
effectiveToMs: 0,
|
effectiveToMs: 0,
|
||||||
|
|||||||
@ -10,6 +10,7 @@ export interface ResourceDto {
|
|||||||
name?: string;
|
name?: string;
|
||||||
status?: string;
|
status?: string;
|
||||||
grantable?: boolean;
|
grantable?: boolean;
|
||||||
|
managerGrantEnabled?: boolean;
|
||||||
grantStrategy?: string;
|
grantStrategy?: string;
|
||||||
walletAssetType?: string;
|
walletAssetType?: string;
|
||||||
walletAssetAmount?: number;
|
walletAssetAmount?: number;
|
||||||
@ -36,6 +37,7 @@ export interface ResourcePayload {
|
|||||||
badgeKind?: string;
|
badgeKind?: string;
|
||||||
coinPrice: number;
|
coinPrice: number;
|
||||||
levelTrack?: string;
|
levelTrack?: string;
|
||||||
|
managerGrantEnabled: boolean;
|
||||||
metadataJson?: string;
|
metadataJson?: string;
|
||||||
name: string;
|
name: string;
|
||||||
previewUrl: string;
|
previewUrl: string;
|
||||||
@ -124,6 +126,7 @@ export interface GiftDto {
|
|||||||
presentationJson?: string;
|
presentationJson?: string;
|
||||||
priceVersion?: string;
|
priceVersion?: string;
|
||||||
giftTypeCode?: string;
|
giftTypeCode?: string;
|
||||||
|
cpRelationType?: string;
|
||||||
chargeAssetType?: string;
|
chargeAssetType?: string;
|
||||||
coinPrice?: number;
|
coinPrice?: number;
|
||||||
effectiveFromMs?: number;
|
effectiveFromMs?: number;
|
||||||
@ -156,6 +159,7 @@ export interface GiftPayload {
|
|||||||
presentationJson: string;
|
presentationJson: string;
|
||||||
priceVersion: string;
|
priceVersion: string;
|
||||||
giftTypeCode: string;
|
giftTypeCode: string;
|
||||||
|
cpRelationType: string;
|
||||||
chargeAssetType: string;
|
chargeAssetType: string;
|
||||||
coinPrice: number;
|
coinPrice: number;
|
||||||
effectiveAtMs: number;
|
effectiveAtMs: number;
|
||||||
|
|||||||
@ -108,6 +108,7 @@ export function resourcePlanToPayload(item) {
|
|||||||
badgeForm: item.resourceType === "badge" ? item.badgeForm || "tile" : undefined,
|
badgeForm: item.resourceType === "badge" ? item.badgeForm || "tile" : undefined,
|
||||||
badgeKind: item.resourceType === "badge" ? "normal" : undefined,
|
badgeKind: item.resourceType === "badge" ? "normal" : undefined,
|
||||||
coinPrice,
|
coinPrice,
|
||||||
|
managerGrantEnabled: true,
|
||||||
metadataJson: item.resourceType === "profile_card" ? profileCardMetadataJSON(item.metadataJson) : undefined,
|
metadataJson: item.resourceType === "profile_card" ? profileCardMetadataJSON(item.metadataJson) : undefined,
|
||||||
name: item.name,
|
name: item.name,
|
||||||
previewUrl: item.coverUrl,
|
previewUrl: item.coverUrl,
|
||||||
|
|||||||
@ -74,6 +74,10 @@ const emptyResourceForm = (resource = {}) => ({
|
|||||||
coinPrice: resource.coinPrice === 0 || resource.coinPrice ? String(resource.coinPrice) : "",
|
coinPrice: resource.coinPrice === 0 || resource.coinPrice ? String(resource.coinPrice) : "",
|
||||||
enabled: resource.status ? resource.status === "active" : true,
|
enabled: resource.status ? resource.status === "active" : true,
|
||||||
levelTrack: resource.resourceType === "badge" ? resource.levelTrack || levelTrackFromMetadata(resource.metadataJson) || "" : "",
|
levelTrack: resource.resourceType === "badge" ? resource.levelTrack || levelTrackFromMetadata(resource.metadataJson) || "" : "",
|
||||||
|
managerGrantEnabled:
|
||||||
|
resource.managerGrantEnabled === undefined || resource.managerGrantEnabled === null
|
||||||
|
? true
|
||||||
|
: Boolean(resource.managerGrantEnabled),
|
||||||
metadataJson: resource.metadataJson || "",
|
metadataJson: resource.metadataJson || "",
|
||||||
name: resource.name || "",
|
name: resource.name || "",
|
||||||
previewUrl: resource.previewUrl || "",
|
previewUrl: resource.previewUrl || "",
|
||||||
@ -118,14 +122,11 @@ const emptyGroupWalletAssetItem = (walletAssetType) => ({
|
|||||||
const emptyGiftForm = (gift = {}) => {
|
const emptyGiftForm = (gift = {}) => {
|
||||||
const giftTypeCode = gift.giftTypeCode || "normal";
|
const giftTypeCode = gift.giftTypeCode || "normal";
|
||||||
const presentationJson = gift.presentationJson || "{}";
|
const presentationJson = gift.presentationJson || "{}";
|
||||||
const cpRelationType =
|
const cpRelationType = cpRelationTypeFromGift({ ...gift, giftTypeCode, presentationJson }) || defaultCPRelationType;
|
||||||
giftTypeCode === cpGiftTypeCode
|
|
||||||
? cpRelationTypeFromPresentationJson(presentationJson) || defaultCPRelationType
|
|
||||||
: "";
|
|
||||||
return {
|
return {
|
||||||
chargeAssetType: gift.chargeAssetType || "COIN",
|
chargeAssetType: gift.chargeAssetType || "COIN",
|
||||||
coinPrice: gift.coinPrice === 0 || gift.coinPrice ? String(gift.coinPrice) : "",
|
coinPrice: gift.coinPrice === 0 || gift.coinPrice ? String(gift.coinPrice) : "",
|
||||||
cpRelationType,
|
cpRelationType: giftTypeCode === cpGiftTypeCode ? cpRelationType : "",
|
||||||
effectTypes: gift.effectTypes || [],
|
effectTypes: gift.effectTypes || [],
|
||||||
effectiveFrom: msToDatetimeLocal(gift.effectiveFromMs),
|
effectiveFrom: msToDatetimeLocal(gift.effectiveFromMs),
|
||||||
effectiveTo: msToDatetimeLocal(gift.effectiveToMs),
|
effectiveTo: msToDatetimeLocal(gift.effectiveToMs),
|
||||||
@ -170,6 +171,18 @@ export function cpRelationTypeFromPresentationJson(presentationJson) {
|
|||||||
return relationType || "";
|
return relationType || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function cpRelationTypeFromGift(gift = {}) {
|
||||||
|
if (gift?.giftTypeCode !== cpGiftTypeCode) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return validCPRelationType(gift.cpRelationType) || cpRelationTypeFromPresentationJson(gift.presentationJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function cpRelationTypeShortLabel(value) {
|
||||||
|
const label = cpRelationTypeLabels[validCPRelationType(value)] || String(value || "").trim();
|
||||||
|
return label.endsWith("礼物") ? label.slice(0, -2) : label;
|
||||||
|
}
|
||||||
|
|
||||||
export function normalizeGiftPresentationJson(presentationJson, giftTypeCode, cpRelationType) {
|
export function normalizeGiftPresentationJson(presentationJson, giftTypeCode, cpRelationType) {
|
||||||
const rawValue = String(presentationJson || "").trim();
|
const rawValue = String(presentationJson || "").trim();
|
||||||
const isCPGift = giftTypeCode === cpGiftTypeCode;
|
const isCPGift = giftTypeCode === cpGiftTypeCode;
|
||||||
@ -235,8 +248,12 @@ function parseGiftPresentationObject(presentationJson) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function normalizedCPRelationType(value) {
|
function normalizedCPRelationType(value) {
|
||||||
|
return validCPRelationType(value) || defaultCPRelationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validCPRelationType(value) {
|
||||||
const relationType = String(value || "").trim().toLowerCase();
|
const relationType = String(value || "").trim().toLowerCase();
|
||||||
return cpRelationTypeValues.has(relationType) ? relationType : defaultCPRelationType;
|
return cpRelationTypeValues.has(relationType) ? relationType : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function cpPresentationJson(basePresentation, cpRelationType) {
|
function cpPresentationJson(basePresentation, cpRelationType) {
|
||||||
@ -384,6 +401,27 @@ export function useResourceListPage() {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toggleManagerGrant = async (resource, nextEnabled = !resource.managerGrantEnabled) => {
|
||||||
|
if (!abilities.canUpdate || !resource?.resourceId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Boolean(resource.managerGrantEnabled) === nextEnabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await runAction(
|
||||||
|
`resource-manager-grant-${resource.resourceId}`,
|
||||||
|
nextEnabled ? "经理赠送已开启" : "经理赠送已关闭",
|
||||||
|
async () => {
|
||||||
|
const formValue = parseForm(resourceFormSchema, {
|
||||||
|
...emptyResourceForm(resource),
|
||||||
|
managerGrantEnabled: nextEnabled,
|
||||||
|
});
|
||||||
|
await updateResource(resource.resourceId, buildResourcePayload(formValue));
|
||||||
|
await result.reload();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const runAction = async (action, successMessage, submitter) => {
|
const runAction = async (action, successMessage, submitter) => {
|
||||||
setLoadingAction(action);
|
setLoadingAction(action);
|
||||||
try {
|
try {
|
||||||
@ -420,6 +458,7 @@ export function useResourceListPage() {
|
|||||||
setForm,
|
setForm,
|
||||||
status,
|
status,
|
||||||
submitResource,
|
submitResource,
|
||||||
|
toggleManagerGrant,
|
||||||
toggleResource,
|
toggleResource,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -1479,6 +1518,7 @@ function buildResourcePayload(form) {
|
|||||||
badgeKind: resourceType === "badge" ? form.badgeKind || "normal" : undefined,
|
badgeKind: resourceType === "badge" ? form.badgeKind || "normal" : undefined,
|
||||||
coinPrice: form.priceType === "coin" ? Number(form.coinPrice) : 0,
|
coinPrice: form.priceType === "coin" ? Number(form.coinPrice) : 0,
|
||||||
levelTrack: resourceType === "badge" && form.badgeKind === "level" ? form.levelTrack : undefined,
|
levelTrack: resourceType === "badge" && form.badgeKind === "level" ? form.levelTrack : undefined,
|
||||||
|
managerGrantEnabled: Boolean(form.managerGrantEnabled),
|
||||||
metadataJson: resourceType === "profile_card" ? profileCardMetadataJSON(form.metadataJson) : undefined,
|
metadataJson: resourceType === "profile_card" ? profileCardMetadataJSON(form.metadataJson) : undefined,
|
||||||
name: form.name.trim(),
|
name: form.name.trim(),
|
||||||
previewUrl: form.previewUrl.trim(),
|
previewUrl: form.previewUrl.trim(),
|
||||||
@ -1602,9 +1642,11 @@ function buildResourceGroupPayload(form) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildGiftPayload(form) {
|
function buildGiftPayload(form) {
|
||||||
|
const cpRelationType = form.giftTypeCode === cpGiftTypeCode ? normalizedCPRelationType(form.cpRelationType) : "";
|
||||||
return {
|
return {
|
||||||
chargeAssetType: form.chargeAssetType,
|
chargeAssetType: form.chargeAssetType,
|
||||||
coinPrice: Number(form.coinPrice),
|
coinPrice: Number(form.coinPrice),
|
||||||
|
cpRelationType,
|
||||||
effectiveAtMs: Date.now(),
|
effectiveAtMs: Date.now(),
|
||||||
effectiveFromMs: datetimeLocalToMs(form.effectiveFrom),
|
effectiveFromMs: datetimeLocalToMs(form.effectiveFrom),
|
||||||
effectiveToMs: datetimeLocalToMs(form.effectiveTo),
|
effectiveToMs: datetimeLocalToMs(form.effectiveTo),
|
||||||
@ -1622,9 +1664,11 @@ function buildGiftPayload(form) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function buildGiftInlineSortPayload(gift, sortOrder) {
|
function buildGiftInlineSortPayload(gift, sortOrder) {
|
||||||
|
const cpRelationType = cpRelationTypeFromGift(gift);
|
||||||
return {
|
return {
|
||||||
chargeAssetType: gift.chargeAssetType || "COIN",
|
chargeAssetType: gift.chargeAssetType || "COIN",
|
||||||
coinPrice: Number(gift.coinPrice || 0),
|
coinPrice: Number(gift.coinPrice || 0),
|
||||||
|
cpRelationType: gift.giftTypeCode === cpGiftTypeCode ? cpRelationType || defaultCPRelationType : "",
|
||||||
effectiveAtMs: Date.now(),
|
effectiveAtMs: Date.now(),
|
||||||
effectiveFromMs: Number(gift.effectiveFromMs || 0),
|
effectiveFromMs: Number(gift.effectiveFromMs || 0),
|
||||||
effectiveToMs: Number(gift.effectiveToMs || 0),
|
effectiveToMs: Number(gift.effectiveToMs || 0),
|
||||||
|
|||||||
@ -2,7 +2,9 @@ import { expect, test, vi } from "vitest";
|
|||||||
import {
|
import {
|
||||||
applyGiftPriceDefaults,
|
applyGiftPriceDefaults,
|
||||||
applyGiftResourceSelection,
|
applyGiftResourceSelection,
|
||||||
|
cpRelationTypeFromGift,
|
||||||
cpRelationTypeFromPresentationJson,
|
cpRelationTypeFromPresentationJson,
|
||||||
|
cpRelationTypeShortLabel,
|
||||||
fetchAllOptionPages,
|
fetchAllOptionPages,
|
||||||
normalizeGiftPresentationJson,
|
normalizeGiftPresentationJson,
|
||||||
} from "./useResourcePages.js";
|
} from "./useResourcePages.js";
|
||||||
@ -67,6 +69,24 @@ test("reads CP relation type from gift presentation json", () => {
|
|||||||
expect(cpRelationTypeFromPresentationJson('{"cp_relation_type":"unknown"}')).toBe("");
|
expect(cpRelationTypeFromPresentationJson('{"cp_relation_type":"unknown"}')).toBe("");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("prefers explicit CP relation type and formats compact list label", () => {
|
||||||
|
expect(
|
||||||
|
cpRelationTypeFromGift({
|
||||||
|
cpRelationType: "brother",
|
||||||
|
giftTypeCode: "cp",
|
||||||
|
presentationJson: '{"cp_relation_type":"sister"}',
|
||||||
|
}),
|
||||||
|
).toBe("brother");
|
||||||
|
expect(
|
||||||
|
cpRelationTypeFromGift({
|
||||||
|
giftTypeCode: "cp",
|
||||||
|
presentationJson: '{"cp_relation_type":"sister"}',
|
||||||
|
}),
|
||||||
|
).toBe("sister");
|
||||||
|
expect(cpRelationTypeShortLabel("brother")).toBe("兄弟");
|
||||||
|
expect(cpRelationTypeShortLabel("cp")).toBe("CP");
|
||||||
|
});
|
||||||
|
|
||||||
test("normalizes CP gift presentation json for submit", () => {
|
test("normalizes CP gift presentation json for submit", () => {
|
||||||
const nextJson = normalizeGiftPresentationJson(
|
const nextJson = normalizeGiftPresentationJson(
|
||||||
'{"other":1,"cp_relation_type":"brother","cpRelationLabel":"old"}',
|
'{"other":1,"cp_relation_type":"brother","cpRelationLabel":"old"}',
|
||||||
|
|||||||
@ -34,14 +34,17 @@ import { createRegionColumnFilter } from "@/shared/ui/RegionFilterControl.jsx";
|
|||||||
import { createOptionsColumnFilter, createTextColumnFilter } from "@/shared/ui/tableFilters.js";
|
import { createOptionsColumnFilter, createTextColumnFilter } from "@/shared/ui/tableFilters.js";
|
||||||
import { formatMillis } from "@/shared/utils/time.js";
|
import { formatMillis } from "@/shared/utils/time.js";
|
||||||
import {
|
import {
|
||||||
cpRelationTypeLabels,
|
|
||||||
cpRelationTypeOptions,
|
cpRelationTypeOptions,
|
||||||
defaultGiftTypeOptions,
|
defaultGiftTypeOptions,
|
||||||
resourceStatusFilters,
|
resourceStatusFilters,
|
||||||
} from "@/features/resources/constants.js";
|
} from "@/features/resources/constants.js";
|
||||||
import { GiftTypeConfigDialog } from "@/features/resources/components/GiftTypeConfigDialog.jsx";
|
import { GiftTypeConfigDialog } from "@/features/resources/components/GiftTypeConfigDialog.jsx";
|
||||||
import { ResourceSelectField } from "@/features/resources/components/ResourceSelectDrawer.jsx";
|
import { ResourceSelectField } from "@/features/resources/components/ResourceSelectDrawer.jsx";
|
||||||
import { cpRelationTypeFromPresentationJson, useGiftListPage } from "@/features/resources/hooks/useResourcePages.js";
|
import {
|
||||||
|
cpRelationTypeFromGift,
|
||||||
|
cpRelationTypeShortLabel,
|
||||||
|
useGiftListPage,
|
||||||
|
} from "@/features/resources/hooks/useResourcePages.js";
|
||||||
import styles from "@/features/resources/resources.module.css";
|
import styles from "@/features/resources/resources.module.css";
|
||||||
|
|
||||||
const effectOptions = [
|
const effectOptions = [
|
||||||
@ -667,13 +670,10 @@ function giftTypeLabel(value, options = defaultGiftTypeOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function GiftTypeIdentity({ gift, giftTypeOptions }) {
|
function GiftTypeIdentity({ gift, giftTypeOptions }) {
|
||||||
const relationType = gift.giftTypeCode === "cp" ? cpRelationTypeFromPresentationJson(gift.presentationJson) : "";
|
const typeLabel = giftTypeLabel(gift.giftTypeCode, giftTypeOptions);
|
||||||
return (
|
const relationType = gift.giftTypeCode === "cp" ? cpRelationTypeFromGift(gift) || "cp" : "";
|
||||||
<div className={styles.stack}>
|
const relationLabel = relationType ? cpRelationTypeShortLabel(relationType) : "";
|
||||||
<span>{giftTypeLabel(gift.giftTypeCode, giftTypeOptions)}</span>
|
return <span>{relationLabel ? `${typeLabel}(${relationLabel})` : typeLabel}</span>;
|
||||||
{relationType ? <span className="admin-tag">{cpRelationTypeLabels[relationType] || relationType}</span> : null}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function giftPriceLabel(gift) {
|
function giftPriceLabel(gift) {
|
||||||
|
|||||||
@ -92,6 +92,11 @@ const baseColumns = [
|
|||||||
label: "状态",
|
label: "状态",
|
||||||
width: "minmax(92px, 0.55fr)",
|
width: "minmax(92px, 0.55fr)",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
key: "managerGrant",
|
||||||
|
label: "经理赠送",
|
||||||
|
width: "minmax(112px, 0.6fr)",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: "time",
|
key: "time",
|
||||||
label: "更新时间",
|
label: "更新时间",
|
||||||
@ -146,6 +151,11 @@ export function ResourceListPage() {
|
|||||||
}),
|
}),
|
||||||
render: (resource) => <ResourceStatusSwitch page={page} resource={resource} />,
|
render: (resource) => <ResourceStatusSwitch page={page} resource={resource} />,
|
||||||
}
|
}
|
||||||
|
: column.key === "managerGrant"
|
||||||
|
? {
|
||||||
|
...column,
|
||||||
|
render: (resource) => <ManagerGrantSwitch page={page} resource={resource} />,
|
||||||
|
}
|
||||||
: column.key === "actions"
|
: column.key === "actions"
|
||||||
? {
|
? {
|
||||||
...column,
|
...column,
|
||||||
@ -281,7 +291,7 @@ export function ResourceListPage() {
|
|||||||
<DataTable
|
<DataTable
|
||||||
columns={columns}
|
columns={columns}
|
||||||
items={items}
|
items={items}
|
||||||
minWidth="940px"
|
minWidth="1060px"
|
||||||
pagination={
|
pagination={
|
||||||
total > 0
|
total > 0
|
||||||
? {
|
? {
|
||||||
@ -656,6 +666,14 @@ function ResourceFormDialog({ disabled, form, loading, mode, onClose, onSubmit,
|
|||||||
uncheckedLabel="禁用"
|
uncheckedLabel="禁用"
|
||||||
onChange={(checked) => setForm({ ...form, enabled: checked })}
|
onChange={(checked) => setForm({ ...form, enabled: checked })}
|
||||||
/>
|
/>
|
||||||
|
<AdminFormSwitchField
|
||||||
|
checked={Boolean(form.managerGrantEnabled)}
|
||||||
|
checkedLabel="开启"
|
||||||
|
disabled={disabled}
|
||||||
|
label="经理赠送"
|
||||||
|
uncheckedLabel="关闭"
|
||||||
|
onChange={(checked) => setForm({ ...form, managerGrantEnabled: checked })}
|
||||||
|
/>
|
||||||
</AdminFormSection>
|
</AdminFormSection>
|
||||||
</AdminFormDialog>
|
</AdminFormDialog>
|
||||||
);
|
);
|
||||||
@ -688,6 +706,20 @@ function ResourceStatusSwitch({ page, resource }) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ManagerGrantSwitch({ page, resource }) {
|
||||||
|
const checked = Boolean(resource.managerGrantEnabled);
|
||||||
|
return (
|
||||||
|
<AdminSwitch
|
||||||
|
checked={checked}
|
||||||
|
checkedLabel="开启"
|
||||||
|
disabled={!page.abilities.canUpdate || page.loadingAction === `resource-manager-grant-${resource.resourceId}`}
|
||||||
|
inputProps={{ "aria-label": checked ? "关闭经理赠送" : "开启经理赠送" }}
|
||||||
|
uncheckedLabel="关闭"
|
||||||
|
onChange={(event) => page.toggleManagerGrant(resource, event.target.checked)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function resourcePriceLabel(resource) {
|
function resourcePriceLabel(resource) {
|
||||||
if (resource.priceType === "free") {
|
if (resource.priceType === "free") {
|
||||||
return resourcePriceTypeLabels.free;
|
return resourcePriceTypeLabels.free;
|
||||||
|
|||||||
@ -38,6 +38,7 @@ export const resourceCreateFormSchema = z
|
|||||||
badgeKind: z.enum(badgeKinds).optional(),
|
badgeKind: z.enum(badgeKinds).optional(),
|
||||||
enabled: z.boolean(),
|
enabled: z.boolean(),
|
||||||
levelTrack: z.enum(badgeLevelTracks).optional().or(z.literal("")),
|
levelTrack: z.enum(badgeLevelTracks).optional().or(z.literal("")),
|
||||||
|
managerGrantEnabled: z.boolean(),
|
||||||
metadataJson: z.string().trim().max(4096, "资源元数据不能超过 4096 个字符").optional(),
|
metadataJson: z.string().trim().max(4096, "资源元数据不能超过 4096 个字符").optional(),
|
||||||
name: z.string().trim().min(1, "请输入资源名称").max(128, "资源名称不能超过 128 个字符"),
|
name: z.string().trim().min(1, "请输入资源名称").max(128, "资源名称不能超过 128 个字符"),
|
||||||
coinPrice: z.union([z.string(), z.number()]).optional(),
|
coinPrice: z.union([z.string(), z.number()]).optional(),
|
||||||
|
|||||||
@ -15,6 +15,7 @@ describe("resource form schema", () => {
|
|||||||
animationUrl: "https://media.haiyihy.com/resource/profile-card.pag",
|
animationUrl: "https://media.haiyihy.com/resource/profile-card.pag",
|
||||||
badgeForm: "tile",
|
badgeForm: "tile",
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
managerGrantEnabled: true,
|
||||||
metadataJson:
|
metadataJson:
|
||||||
'{"profile_card_layout":{"source_width":1136,"source_height":1680,"color_content_width":750,"content_top":117,"content_bottom":1666,"content_height":1550,"content_top_ratio":0.069643,"content_height_ratio":0.922619,"detect_version":1}}',
|
'{"profile_card_layout":{"source_width":1136,"source_height":1680,"color_content_width":750,"content_top":117,"content_bottom":1666,"content_height":1550,"content_top_ratio":0.069643,"content_height_ratio":0.922619,"detect_version":1}}',
|
||||||
name: "Profile Card",
|
name: "Profile Card",
|
||||||
@ -36,6 +37,7 @@ describe("resource form schema", () => {
|
|||||||
badgeKind: "level",
|
badgeKind: "level",
|
||||||
enabled: true,
|
enabled: true,
|
||||||
levelTrack: "wealth",
|
levelTrack: "wealth",
|
||||||
|
managerGrantEnabled: true,
|
||||||
name: "VIP Badge",
|
name: "VIP Badge",
|
||||||
previewUrl: "https://media.haiyihy.com/resource/badge.png",
|
previewUrl: "https://media.haiyihy.com/resource/badge.png",
|
||||||
priceType: "free",
|
priceType: "free",
|
||||||
@ -51,6 +53,7 @@ describe("resource form schema", () => {
|
|||||||
parseForm(resourceFormSchema, {
|
parseForm(resourceFormSchema, {
|
||||||
animationUrl: "https://media.haiyihy.com/resource/badge.pag",
|
animationUrl: "https://media.haiyihy.com/resource/badge.pag",
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
managerGrantEnabled: true,
|
||||||
name: "VIP Badge",
|
name: "VIP Badge",
|
||||||
previewUrl: "https://media.haiyihy.com/resource/badge.png",
|
previewUrl: "https://media.haiyihy.com/resource/badge.png",
|
||||||
priceType: "free",
|
priceType: "free",
|
||||||
@ -65,6 +68,7 @@ describe("resource form schema", () => {
|
|||||||
badgeForm: "strip",
|
badgeForm: "strip",
|
||||||
badgeKind: "level",
|
badgeKind: "level",
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
managerGrantEnabled: true,
|
||||||
name: "VIP Badge",
|
name: "VIP Badge",
|
||||||
previewUrl: "https://media.haiyihy.com/resource/badge.png",
|
previewUrl: "https://media.haiyihy.com/resource/badge.png",
|
||||||
priceType: "free",
|
priceType: "free",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user