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; // 已加载过,不重复加载