From 603f41f9caae574221b7b4873609eebb85c00875 Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 7 Jan 2026 06:05:42 -0800 Subject: [PATCH] =?UTF-8?q?fix(admin-web):=20=E4=BF=AE=E5=A4=8D=E5=9B=BA?= =?UTF-8?q?=E5=AE=9A=E8=B4=A6=E6=88=B7=E7=BB=84=E4=BB=B6=E7=A9=BA=E5=80=BC?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=92=8C=20hooks=20=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 data 空值检查防止 undefined 错误 - 将 useState hooks 移到条件返回之前(React hooks 规则) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../system-account-report/SystemAccountsTab.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/frontend/admin-web/src/components/features/system-account-report/SystemAccountsTab.tsx b/frontend/admin-web/src/components/features/system-account-report/SystemAccountsTab.tsx index 8244e3a0..4c7c516f 100644 --- a/frontend/admin-web/src/components/features/system-account-report/SystemAccountsTab.tsx +++ b/frontend/admin-web/src/components/features/system-account-report/SystemAccountsTab.tsx @@ -300,6 +300,16 @@ export default function SystemAccountsTab() { * [2026-01-07] 更新:添加查看分类账明细按钮,在卡片下方公共区域显示明细 */ function FixedAccountsSection({ data }: { data: SystemAccountReportResponse['fixedAccounts'] }) { + // [2026-01-07] 新增:选中账户和分类账数据(hooks 必须在条件返回之前) + const [selectedAccount, setSelectedAccount] = useState(null); + const [allLedgerData, setAllLedgerData] = useState(null); + const [ledgerLoading, setLedgerLoading] = useState(false); + + // [2026-01-07] 修复:添加空值检查,防止 data 为 undefined 时报错 + if (!data) { + return
固定账户数据加载中...
; + } + // [2026-01-07] 修复:从后端返回数据中读取真实的 accountSequence,过滤掉不存在的账户 // 后端映射:S0000000001=HQ_COMMUNITY, S0000000002=COST_ACCOUNT, S0000000003=OPERATION_ACCOUNT const accounts = [ @@ -315,11 +325,6 @@ function FixedAccountsSection({ data }: { data: SystemAccountReportResponse['fix sequence: item.data?.accountSequence || '', })); - // [2026-01-07] 新增:选中账户和分类账数据 - const [selectedAccount, setSelectedAccount] = useState(null); - const [allLedgerData, setAllLedgerData] = useState(null); - const [ledgerLoading, setLedgerLoading] = useState(false); - // 加载所有固定账户的分类账明细 const loadAllLedger = useCallback(async () => { if (allLedgerData) return; // 已加载过,不重复加载