8315d5660a
Project CI / AI game creator shell Rust crates (push) Successful in 1m27s
Project CI / AI game creator shell Rust smoke (push) Successful in 1m53s
Project CI / Frontend tests (push) Has been cancelled
Project CI / Repository checks (push) Has been cancelled
Project CI / AI game creator shell Rust lane 2/2 (push) Has been cancelled
Project CI / Backend tests (push) Has been cancelled
Project CI / Native shell tests (push) Has been cancelled
Project CI / AI game creator shell web tests (push) Has been cancelled
Project CI / AI game creator shell Rust lane 1/2 (push) Has been cancelled
- packages/shared/src/components/admin/ 新增 16 个后台共享组件(AdminPage/AdminPanel/AdminButton/AdminAlert/AdminTable/AdminField/AdminInfoList/AdminTagList/AdminPagination/AdminListPanel/AdminDialog 等)与随组件的 admin.css,经 @genarrative/shared/components 导出 - AdminListPanel 统一列表外壳:columns + renderRow、加载两口径(empty/line)、空态三态(state/text/row)、toolbar 与 pagination 槽位、showEmpty 判据、surface=plain(弹窗内列表) - AdminListPanel 新增列头排序(sortable/sortValue/sortDescription):正序→倒序→不排序循环、同步 th[aria-sort]、稳定排序 - AdminDialog 统一弹窗外壳(遮罩/标题行/关闭动作/role=dialog/aria-modal/Esc/点遮罩关闭/初始聚焦/as=form),12 处各页自写弹窗全部改用它 - AdminFormat 新增 formatAdminDateTime/formatAdminDate,删除 7 份重复的本地时间格式化实现,修掉列表里裸 ISO 时间 - 21 个文件里 26 处列表全部迁到 AdminListPanel(24 处 columns 形态、2 处弹窗内 plain),页内已无手写表头或 AdminTable 当 children 的写法;累计 45 个可排序列 - 页面壳归一:错误报告补 AdminPage wide + AdminPageHeading,详情弹窗移出列表面板;模板管理列表从共享 ui Table 换成 AdminTable - 样式收口:公共组件规则随组件进入共享 styles,清理 admin.css 重复按钮/面板规则,.admin-tag 与 .admin-table th 改 nowrap,埋点用户列参考按钮紧跟本行并留行距,错误报告修版心 - 新增 scripts/admin-web-fake-api.mjs 本地假 API(含 overview/dashboard/tracking/error-reports/feature-gates/邀请码/兑换码/任务/充值/项目工程/AGC 模型与模板/游戏/账号/用户详情夹具),用于本地核对渲染 - docs 同步:共享基础组件库与展示页(后台组件层/列表排序/收敛范围/本地核对)、decision-log 与 pitfalls 记录迁移口径、排序边界与踩坑 - 验证:npm run admin-web:typecheck、npx vitest run apps/admin-web packages/shared/src/components/admin(26 files / 244 tests)、npm run check:encoding、git diff --check、prettier、eslint 全部通过
208 lines
6.2 KiB
TypeScript
208 lines
6.2 KiB
TypeScript
import {
|
|
AdminAlert,
|
|
AdminButton,
|
|
AdminField,
|
|
AdminInfoList,
|
|
AdminListPanel,
|
|
AdminPage,
|
|
AdminPageHeading,
|
|
AdminPanel,
|
|
formatAdminDateTime,
|
|
} from '@genarrative/shared/components';
|
|
import { RefreshCcw, Save } from 'lucide-react';
|
|
import { FormEvent, useEffect, useState } from 'react';
|
|
|
|
import {
|
|
getProfileWalletConfig,
|
|
upsertProfileWalletConfig,
|
|
} from '../api/adminApiClient';
|
|
import type { ProfileWalletConfigAdminResponse } from '../api/adminApiTypes';
|
|
import { useAdminWriteConfirm } from '../components/useAdminWriteConfirm';
|
|
import { handlePageError } from './pageUtils';
|
|
|
|
interface AdminProfileWalletConfigPageProps {
|
|
token: string;
|
|
result: ProfileWalletConfigAdminResponse | null;
|
|
onUnauthorized: (message?: string) => void;
|
|
onResultChange: (result: ProfileWalletConfigAdminResponse) => void;
|
|
}
|
|
|
|
export function AdminProfileWalletConfigPage({
|
|
token,
|
|
result,
|
|
onUnauthorized,
|
|
onResultChange,
|
|
}: AdminProfileWalletConfigPageProps) {
|
|
const [initialMudPoints, setInitialMudPoints] = useState('100');
|
|
const [dailyFreePointsPerDay, setDailyFreePointsPerDay] = useState('20');
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const [isSaving, setIsSaving] = useState(false);
|
|
const [loadErrorMessage, setLoadErrorMessage] = useState('');
|
|
const [errorMessage, setErrorMessage] = useState('');
|
|
const { confirmWrite, confirmDialog } = useAdminWriteConfirm();
|
|
|
|
useEffect(() => {
|
|
void refreshConfig();
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [token]);
|
|
|
|
async function refreshConfig() {
|
|
setIsLoading(true);
|
|
setLoadErrorMessage('');
|
|
try {
|
|
const response = await getProfileWalletConfig(token);
|
|
onResultChange(response);
|
|
setInitialMudPoints(String(response.initialMudPoints));
|
|
setDailyFreePointsPerDay(String(response.dailyFreePointsPerDay));
|
|
} catch (error: unknown) {
|
|
handlePageError(error, onUnauthorized, setLoadErrorMessage);
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
}
|
|
|
|
async function handleSave(event: FormEvent<HTMLFormElement>) {
|
|
event.preventDefault();
|
|
if (isSaving) {
|
|
return;
|
|
}
|
|
const normalizedDailyFreePointsPerDay = parsePositiveInteger(
|
|
dailyFreePointsPerDay,
|
|
);
|
|
if (!normalizedDailyFreePointsPerDay) {
|
|
setErrorMessage('每日免费泥点数必须是大于 0 的整数');
|
|
return;
|
|
}
|
|
|
|
const normalizedInitialMudPoints = parsePositiveInteger(initialMudPoints);
|
|
if (!normalizedInitialMudPoints) {
|
|
setErrorMessage('账号初始泥点数必须是大于 0 的整数');
|
|
return;
|
|
}
|
|
|
|
setErrorMessage('');
|
|
const confirmed = await confirmWrite({
|
|
action: '保存账号配置',
|
|
target: `初始 ${normalizedInitialMudPoints} 泥点,每日免费 ${normalizedDailyFreePointsPerDay} 泥点`,
|
|
});
|
|
if (!confirmed) {
|
|
return;
|
|
}
|
|
|
|
setIsSaving(true);
|
|
try {
|
|
const response = await upsertProfileWalletConfig(token, {
|
|
initialMudPoints: normalizedInitialMudPoints,
|
|
dailyFreePointsPerDay: normalizedDailyFreePointsPerDay,
|
|
});
|
|
onResultChange(response);
|
|
setInitialMudPoints(String(response.initialMudPoints));
|
|
setDailyFreePointsPerDay(String(response.dailyFreePointsPerDay));
|
|
} catch (error: unknown) {
|
|
handlePageError(error, onUnauthorized, setErrorMessage);
|
|
} finally {
|
|
setIsSaving(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<AdminPage>
|
|
<AdminPageHeading
|
|
title="账号配置"
|
|
description="泥点钱包"
|
|
actions={
|
|
<AdminButton
|
|
variant="secondary"
|
|
disabled={isLoading}
|
|
type="button"
|
|
onClick={refreshConfig}
|
|
>
|
|
<RefreshCcw size={17} aria-hidden="true" />
|
|
<span>{isLoading ? '刷新中' : '刷新'}</span>
|
|
</AdminButton>
|
|
}
|
|
/>
|
|
|
|
{loadErrorMessage ? <AdminAlert>{loadErrorMessage}</AdminAlert> : null}
|
|
|
|
<div className="admin-two-column">
|
|
<AdminPanel as="form" onSubmit={handleSave}>
|
|
<AdminField label="账号初始泥点数">
|
|
<input
|
|
min={1}
|
|
step={1}
|
|
type="number"
|
|
value={initialMudPoints}
|
|
onChange={(event) => setInitialMudPoints(event.target.value)}
|
|
/>
|
|
</AdminField>
|
|
|
|
<AdminField label="每日免费泥点数">
|
|
<input
|
|
min={1}
|
|
step={1}
|
|
type="number"
|
|
value={dailyFreePointsPerDay}
|
|
onChange={(event) => setDailyFreePointsPerDay(event.target.value)}
|
|
/>
|
|
</AdminField>
|
|
|
|
{errorMessage ? <AdminAlert>{errorMessage}</AdminAlert> : null}
|
|
|
|
<AdminButton
|
|
variant="primary"
|
|
disabled={
|
|
isSaving ||
|
|
!parsePositiveInteger(initialMudPoints) ||
|
|
!parsePositiveInteger(dailyFreePointsPerDay)
|
|
}
|
|
type="submit"
|
|
>
|
|
<Save size={17} aria-hidden="true" />
|
|
<span>{isSaving ? '保存中' : '保存'}</span>
|
|
</AdminButton>
|
|
</AdminPanel>
|
|
|
|
<AdminListPanel
|
|
busy={isLoading}
|
|
busyText="加载中"
|
|
count={result?.configId ?? '-'}
|
|
className="admin-result-panel"
|
|
emptyText="暂无记录"
|
|
rows={result ? [result] : []}
|
|
title="当前配置"
|
|
>
|
|
{result ? (
|
|
<AdminInfoList
|
|
items={[
|
|
{
|
|
label: <>初始泥点</>,
|
|
value: <>{result.initialMudPoints}</>,
|
|
},
|
|
{
|
|
label: <>每日免费泥点</>,
|
|
value: <>{result.dailyFreePointsPerDay}</>,
|
|
},
|
|
{
|
|
label: <>更新人</>,
|
|
value: <>{result.updatedByDisplayName || '-'}</>,
|
|
},
|
|
{
|
|
label: <>更新</>,
|
|
value: <>{formatAdminDateTime(result.updatedAt)}</>,
|
|
},
|
|
]}
|
|
/>
|
|
) : null}
|
|
</AdminListPanel>
|
|
</div>
|
|
{confirmDialog}
|
|
</AdminPage>
|
|
);
|
|
}
|
|
|
|
function parsePositiveInteger(value: string) {
|
|
const parsed = Number(value);
|
|
return Number.isSafeInteger(parsed) && parsed > 0 ? parsed : 0;
|
|
}
|