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:
parent
c22ce4ecc4
commit
603f41f9ca
|
|
@ -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; // 已加载过,不重复加载
|
||||
|
|
|
|||
Loading…
Reference in New Issue