游戏机器人
This commit is contained in:
parent
97915b5980
commit
0be921409d
@ -9,6 +9,7 @@ import { useCallback, useEffect, useMemo, useState } from "react";
|
|||||||
import { PERMISSIONS } from "@/app/permissions";
|
import { PERMISSIONS } from "@/app/permissions";
|
||||||
import { useAuth } from "@/app/auth/AuthProvider.jsx";
|
import { useAuth } from "@/app/auth/AuthProvider.jsx";
|
||||||
import { deleteDiceRobot, generateDiceRobots, listDiceRobots, setDiceRobotStatus } from "@/features/games/api";
|
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 styles from "@/features/games/games.module.css";
|
||||||
import {
|
import {
|
||||||
AdminActionIconButton,
|
AdminActionIconButton,
|
||||||
@ -28,6 +29,7 @@ import { formatMillis } from "@/shared/utils/time.js";
|
|||||||
|
|
||||||
const defaultGenerateForm = {
|
const defaultGenerateForm = {
|
||||||
count: 20,
|
count: 20,
|
||||||
|
country: "SA",
|
||||||
nicknameLanguage: "arabic",
|
nicknameLanguage: "arabic",
|
||||||
};
|
};
|
||||||
const maxGenerateRobotCount = 1000;
|
const maxGenerateRobotCount = 1000;
|
||||||
@ -39,6 +41,7 @@ export function GameRobotPage() {
|
|||||||
const canCreate = can(PERMISSIONS.gameCreate);
|
const canCreate = can(PERMISSIONS.gameCreate);
|
||||||
const canUpdate = can(PERMISSIONS.gameUpdate);
|
const canUpdate = can(PERMISSIONS.gameUpdate);
|
||||||
const canDelete = can(PERMISSIONS.gameDelete) || canUpdate;
|
const canDelete = can(PERMISSIONS.gameDelete) || canUpdate;
|
||||||
|
const { countryOptions, loadingCountries } = useCountryOptions();
|
||||||
const [items, setItems] = useState([]);
|
const [items, setItems] = useState([]);
|
||||||
const [status, setStatus] = useState("");
|
const [status, setStatus] = useState("");
|
||||||
const [nextCursor, setNextCursor] = useState("");
|
const [nextCursor, setNextCursor] = useState("");
|
||||||
@ -67,6 +70,21 @@ export function GameRobotPage() {
|
|||||||
load("", false);
|
load("", false);
|
||||||
}, [load]);
|
}, [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(
|
const changeStatus = useCallback(
|
||||||
async (robot, checked) => {
|
async (robot, checked) => {
|
||||||
setLoadingAction(`status-${robot.userId}`);
|
setLoadingAction(`status-${robot.userId}`);
|
||||||
@ -178,7 +196,11 @@ export function GameRobotPage() {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setLoadingAction("generate");
|
setLoadingAction("generate");
|
||||||
try {
|
try {
|
||||||
|
const enabledCountry = countryOptions.some((option) => option.value === generateForm.country)
|
||||||
|
? generateForm.country
|
||||||
|
: countryOptions[0]?.value || generateForm.country || "SA";
|
||||||
const result = await generateDiceRobots({
|
const result = await generateDiceRobots({
|
||||||
|
country: enabledCountry,
|
||||||
count: Number(generateForm.count || 0),
|
count: Number(generateForm.count || 0),
|
||||||
nicknameLanguage: generateForm.nicknameLanguage || "arabic",
|
nicknameLanguage: generateForm.nicknameLanguage || "arabic",
|
||||||
});
|
});
|
||||||
@ -244,6 +266,8 @@ export function GameRobotPage() {
|
|||||||
</AdminListBody>
|
</AdminListBody>
|
||||||
<GenerateDialog
|
<GenerateDialog
|
||||||
form={generateForm}
|
form={generateForm}
|
||||||
|
countryOptions={countryOptions}
|
||||||
|
loadingCountries={loadingCountries}
|
||||||
loading={loadingAction === "generate"}
|
loading={loadingAction === "generate"}
|
||||||
open={dialogOpen}
|
open={dialogOpen}
|
||||||
setForm={setGenerateForm}
|
setForm={setGenerateForm}
|
||||||
@ -254,7 +278,11 @@ export function GameRobotPage() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function GenerateDialog({ form, loading, open, setForm, onClose, onSubmit }) {
|
function GenerateDialog({ countryOptions, form, loading, loadingCountries, open, setForm, onClose, onSubmit }) {
|
||||||
|
const selectCountryOptions = countryOptions.length > 0 ? countryOptions : [{ label: "SA", value: "SA" }];
|
||||||
|
const selectedCountry = selectCountryOptions.some((country) => country.value === form.country)
|
||||||
|
? form.country
|
||||||
|
: selectCountryOptions[0]?.value || "SA";
|
||||||
return (
|
return (
|
||||||
<AdminFormDialog
|
<AdminFormDialog
|
||||||
loading={loading}
|
loading={loading}
|
||||||
@ -282,6 +310,19 @@ function GenerateDialog({ form, loading, open, setForm, onClose, onSubmit }) {
|
|||||||
<MenuItem value="arabic">阿拉伯语账号</MenuItem>
|
<MenuItem value="arabic">阿拉伯语账号</MenuItem>
|
||||||
<MenuItem value="english">英语账号</MenuItem>
|
<MenuItem value="english">英语账号</MenuItem>
|
||||||
</TextField>
|
</TextField>
|
||||||
|
<TextField
|
||||||
|
disabled={loadingCountries}
|
||||||
|
label="国家"
|
||||||
|
select
|
||||||
|
value={selectedCountry}
|
||||||
|
onChange={(event) => setForm({ ...form, country: event.target.value })}
|
||||||
|
>
|
||||||
|
{selectCountryOptions.map((country) => (
|
||||||
|
<MenuItem key={country.value} value={country.value}>
|
||||||
|
{country.label}
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</TextField>
|
||||||
</AdminFormFieldGrid>
|
</AdminFormFieldGrid>
|
||||||
</AdminFormDialog>
|
</AdminFormDialog>
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user