支持游戏白名单按短号添加用户

This commit is contained in:
zhx 2026-07-14 17:05:08 +08:00
parent 26f8d0767f
commit abb5ba9c52
4 changed files with 13 additions and 12 deletions

View File

@ -367,11 +367,12 @@ export function listGameWhitelistUsers(
).then((result) => ({ ...result, items: (result.items || []).map(normalizeGameWhitelistUser) })); ).then((result) => ({ ...result, items: (result.items || []).map(normalizeGameWhitelistUser) }));
} }
export function addGameWhitelistUser(gameId: string, userId: string): Promise<GameWhitelistUserDto> { export function addGameWhitelistUser(gameId: string, userIdentifier: string): Promise<GameWhitelistUserDto> {
const endpoint = API_ENDPOINTS.addGameWhitelistUser; const endpoint = API_ENDPOINTS.addGameWhitelistUser;
return apiRequest<GameWhitelistUserDto, { userId: string }>( return apiRequest<GameWhitelistUserDto, { userId: string }>(
apiEndpointPath(API_OPERATIONS.addGameWhitelistUser, { game_id: gameId }), apiEndpointPath(API_OPERATIONS.addGameWhitelistUser, { game_id: gameId }),
{ body: { userId }, method: endpoint.method }, // 兼容已发布契约字段 userId服务端会把内部 ID、默认短号或当前靓号统一解析成 owner user_id。
{ body: { userId: userIdentifier }, method: endpoint.method },
).then(normalizeGameWhitelistUser); ).then(normalizeGameWhitelistUser);
} }

View File

@ -47,9 +47,8 @@ export function GameWhitelistDialog({ open, page, onClose }) {
<form className={styles.whitelistSearchRow} onSubmit={page.addWhitelistUser}> <form className={styles.whitelistSearchRow} onSubmit={page.addWhitelistUser}>
<TextField <TextField
fullWidth fullWidth
label="搜索用户 ID" label="搜索用户 ID / 短号 / 靓号"
placeholder="输入内部用户 ID" placeholder="输入任一用户标识,自动匹配真实用户"
slotProps={{ htmlInput: { inputMode: "numeric" } }}
value={page.whitelistUserId} value={page.whitelistUserId}
onChange={(event) => page.setWhitelistUserId(event.target.value)} onChange={(event) => page.setWhitelistUserId(event.target.value)}
/> />
@ -68,7 +67,7 @@ export function GameWhitelistDialog({ open, page, onClose }) {
<div className={styles.whitelistTable}> <div className={styles.whitelistTable}>
<div className={styles.whitelistTableHeader}> <div className={styles.whitelistTableHeader}>
<span>用户</span> <span>用户</span>
<span>用户 ID</span> <span>内部 ID / 当前短号</span>
<span>状态</span> <span>状态</span>
<span>加入时间</span> <span>加入时间</span>
<span>操作</span> <span>操作</span>

View File

@ -24,7 +24,7 @@ test("renders current members and exposes whitelist toggle, add and remove actio
}, },
], ],
whitelistLoading: false, whitelistLoading: false,
whitelistUserId: "42", whitelistUserId: "VIP2026",
}; };
render( render(
@ -36,6 +36,7 @@ test("renders current members and exposes whitelist toggle, add and remove actio
expect(screen.getByText("游戏白名单 · Private Slot")).toBeInTheDocument(); expect(screen.getByText("游戏白名单 · Private Slot")).toBeInTheDocument();
expect(screen.getByText("Alice")).toBeInTheDocument(); expect(screen.getByText("Alice")).toBeInTheDocument();
expect(screen.getByText("90001")).toBeInTheDocument(); expect(screen.getByText("90001")).toBeInTheDocument();
expect(screen.getByRole("textbox", { name: "搜索用户 ID / 短号 / 靓号" })).toHaveValue("VIP2026");
await user.click(screen.getByRole("switch", { name: "游戏白名单状态" })); await user.click(screen.getByRole("switch", { name: "游戏白名单状态" }));
expect(page.changeWhitelistEnabled).toHaveBeenCalledWith(false); expect(page.changeWhitelistEnabled).toHaveBeenCalledWith(false);

View File

@ -440,17 +440,17 @@ export function useGamesPage() {
const addWhitelistUser = async (event) => { const addWhitelistUser = async (event) => {
event.preventDefault(); event.preventDefault();
const userId = whitelistUserId.trim(); const userIdentifier = whitelistUserId.trim();
if (!whitelistGame || !/^\d+$/.test(userId) || userId === "0") { if (!whitelistGame || !userIdentifier) {
showToast("请输入正确的用户 ID", "error"); showToast("请输入用户 ID、短号或靓号", "error");
return; return;
} }
setLoadingAction(`whitelist-add-${whitelistGame.gameId}`); setLoadingAction(`whitelist-add-${whitelistGame.gameId}`);
try { try {
await addGameWhitelistUser(whitelistGame.gameId, userId); const matchedUser = await addGameWhitelistUser(whitelistGame.gameId, userIdentifier);
setWhitelistUserId(""); setWhitelistUserId("");
await loadWhitelist(whitelistGame); await loadWhitelist(whitelistGame);
showToast("用户已加入白名单", "success"); showToast(`已匹配用户 ${matchedUser.displayUserId || matchedUser.userId} 并加入白名单`, "success");
} catch (err) { } catch (err) {
showToast(err.message || "添加白名单用户失败", "error"); showToast(err.message || "添加白名单用户失败", "error");
} finally { } finally {