fix(admin-web): 修复固定账户组件空值检查和 hooks 顺序

- 添加 data 空值检查防止 undefined 错误
- 将 useState hooks 移到条件返回之前(React hooks 规则)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-01-07 06:05:42 -08:00
parent c22ce4ecc4
commit 603f41f9ca
1 changed files with 10 additions and 5 deletions

View File

@ -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<string | null>(null);
const [allLedgerData, setAllLedgerData] = useState<AllSystemAccountsLedgerResponse | null>(null);
const [ledgerLoading, setLedgerLoading] = useState(false);
// [2026-01-07] 修复:添加空值检查,防止 data 为 undefined 时报错
if (!data) {
return <div className={styles.empty}>...</div>;
}
// [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<string | null>(null);
const [allLedgerData, setAllLedgerData] = useState<AllSystemAccountsLedgerResponse | null>(null);
const [ledgerLoading, setLedgerLoading] = useState(false);
// 加载所有固定账户的分类账明细
const loadAllLedger = useCallback(async () => {
if (allLedgerData) return; // 已加载过,不重复加载