fix(mining-admin-web): 修复用户列表页面空数据和错误处理

- 修复 data.items 可能为 undefined 导致的崩溃
- 添加 API 错误状态显示

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-11 19:06:26 -08:00
parent 2a22d7d669
commit 3fe4f82906
1 changed files with 10 additions and 4 deletions

View File

@ -22,7 +22,7 @@ export default function UsersPage() {
const [page, setPage] = useState(1);
const pageSize = 20;
const { data, isLoading } = useUsers({ page, pageSize, keyword: searchKeyword });
const { data, isLoading, error } = useUsers({ page, pageSize, keyword: searchKeyword });
const handleSearch = () => {
setSearchKeyword(keyword);
@ -102,14 +102,20 @@ export default function UsersPage() {
))}
</TableRow>
))
) : data?.items.length === 0 ? (
) : error ? (
<TableRow>
<TableCell colSpan={12} className="text-center py-8 text-red-500">
: {(error as Error)?.message || '请稍后重试'}
</TableCell>
</TableRow>
) : !data?.items || data.items.length === 0 ? (
<TableRow>
<TableCell colSpan={12} className="text-center py-8 text-muted-foreground">
</TableCell>
</TableRow>
) : (
data?.items.map((user) => (
data.items.map((user) => (
<TableRow key={user.accountSequence}>
{/* 头像 */}
<TableCell>
@ -195,7 +201,7 @@ export default function UsersPage() {
</Table>
</div>
{data && data.totalPages > 1 && (
{data?.items && data.totalPages > 1 && (
<div className="flex items-center justify-between p-4 border-t">
<p className="text-sm text-muted-foreground">
{formatNumber(data.total)} {page} / {data.totalPages}