From 0be921409d5f603a751b331e142d663d75800bb8 Mon Sep 17 00:00:00 2001 From: zhx Date: Tue, 16 Jun 2026 20:47:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=B8=E6=88=8F=E6=9C=BA=E5=99=A8=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/games/pages/GameRobotPage.jsx | 43 +++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/features/games/pages/GameRobotPage.jsx b/src/features/games/pages/GameRobotPage.jsx index 784c7bf..b31154c 100644 --- a/src/features/games/pages/GameRobotPage.jsx +++ b/src/features/games/pages/GameRobotPage.jsx @@ -9,6 +9,7 @@ import { useCallback, useEffect, useMemo, useState } from "react"; import { PERMISSIONS } from "@/app/permissions"; import { useAuth } from "@/app/auth/AuthProvider.jsx"; import { deleteDiceRobot, generateDiceRobots, listDiceRobots, setDiceRobotStatus } from "@/features/games/api"; +import { useCountryOptions } from "@/features/host-org/hooks/useCountryOptions.js"; import styles from "@/features/games/games.module.css"; import { AdminActionIconButton, @@ -28,6 +29,7 @@ import { formatMillis } from "@/shared/utils/time.js"; const defaultGenerateForm = { count: 20, + country: "SA", nicknameLanguage: "arabic", }; const maxGenerateRobotCount = 1000; @@ -39,6 +41,7 @@ export function GameRobotPage() { const canCreate = can(PERMISSIONS.gameCreate); const canUpdate = can(PERMISSIONS.gameUpdate); const canDelete = can(PERMISSIONS.gameDelete) || canUpdate; + const { countryOptions, loadingCountries } = useCountryOptions(); const [items, setItems] = useState([]); const [status, setStatus] = useState(""); const [nextCursor, setNextCursor] = useState(""); @@ -67,6 +70,21 @@ export function GameRobotPage() { load("", false); }, [load]); + useEffect(() => { + setGenerateForm((current) => { + if (countryOptions.length === 0) { + return current; + } + const currentCountryEnabled = countryOptions.some((option) => option.value === current.country); + if (current.country && currentCountryEnabled) { + return current; + } + // 国家主数据由后端控制启用状态;默认优先沿用历史 SA,否则取当前启用列表第一项,避免提交空国家被 user-service 拒绝。 + const defaultCountry = countryOptions.find((option) => option.value === "SA")?.value || countryOptions[0].value; + return { ...current, country: defaultCountry }; + }); + }, [countryOptions]); + const changeStatus = useCallback( async (robot, checked) => { setLoadingAction(`status-${robot.userId}`); @@ -178,7 +196,11 @@ export function GameRobotPage() { event.preventDefault(); setLoadingAction("generate"); try { + const enabledCountry = countryOptions.some((option) => option.value === generateForm.country) + ? generateForm.country + : countryOptions[0]?.value || generateForm.country || "SA"; const result = await generateDiceRobots({ + country: enabledCountry, count: Number(generateForm.count || 0), nicknameLanguage: generateForm.nicknameLanguage || "arabic", }); @@ -244,6 +266,8 @@ export function GameRobotPage() { 0 ? countryOptions : [{ label: "SA", value: "SA" }]; + const selectedCountry = selectCountryOptions.some((country) => country.value === form.country) + ? form.country + : selectCountryOptions[0]?.value || "SA"; return ( 阿拉伯语账号 英语账号 + setForm({ ...form, country: event.target.value })} + > + {selectCountryOptions.map((country) => ( + + {country.label} + + ))} + );