fix: LDAP导入弹框OU列表和用户列表解析失败

根因: 后端 ou-list/user-list API 直接返回数组, 前端错误地从 res.ous/res.users 取值
- loadLdapOus: Array.isArray(res) 兼容处理
- loadLdapUsers: Array.isArray(res) 兼容处理
- LDAP用户显示字段: cn/uid/mail 替代 nickname/username/email
This commit is contained in:
logan committed 2026-05-28 14:30:23 +08:00
1 parent 3a07432032
commit 9dda75efdb
1 file changed
+5 -5
+5 -5
View File
@@ -960,7 +960,7 @@ function BatchImportModal({ onClose, onImported }: { onClose: () => void; onImpo
setLdapLoading(true); setLdapLoading(true);
try { try {
const res = await ldapApi.listOus() as any; const res = await ldapApi.listOus() as any;
setLdapOus(res?.ous || []); setLdapOus(Array.isArray(res) ? res : (res?.ous || res?.data || []));
} catch { toast('error', '加载 LDAP OU 失败'); } } catch { toast('error', '加载 LDAP OU 失败'); }
finally { setLdapLoading(false); } finally { setLdapLoading(false); }
}; };
@@ -969,7 +969,7 @@ function BatchImportModal({ onClose, onImported }: { onClose: () => void; onImpo
setLdapLoading(true); setLdapLoading(true);
try { try {
const res = await ldapApi.listUsers({ base_dn: baseDn }) as any; const res = await ldapApi.listUsers({ base_dn: baseDn }) as any;
setLdapUsers(res?.users || []); setLdapUsers(Array.isArray(res) ? res : (res?.users || res?.data || []));
} catch { toast('error', '加载 LDAP 用户失败'); } } catch { toast('error', '加载 LDAP 用户失败'); }
finally { setLdapLoading(false); } finally { setLdapLoading(false); }
}; };
@@ -1201,9 +1201,9 @@ function BatchImportModal({ onClose, onImported }: { onClose: () => void; onImpo
{ldapUsers.map(u => ( {ldapUsers.map(u => (
<label key={u.dn} className="flex items-center gap-3 px-3 py-2 rounded-lg hover:bg-[var(--dg-bg-hover)] cursor-pointer"> <label key={u.dn} className="flex items-center gap-3 px-3 py-2 rounded-lg hover:bg-[var(--dg-bg-hover)] cursor-pointer">
<input type="checkbox" checked={selectedLdapUsers.has(u.dn)} onChange={() => setSelectedLdapUsers(prev => { const n = new Set(prev); n.has(u.dn) ? n.delete(u.dn) : n.add(u.dn); return n; })} /> <input type="checkbox" checked={selectedLdapUsers.has(u.dn)} onChange={() => setSelectedLdapUsers(prev => { const n = new Set(prev); n.has(u.dn) ? n.delete(u.dn) : n.add(u.dn); return n; })} />
<span className="text-sm font-medium">{u.nickname || u.username}</span> <span className="text-sm font-medium">{u.cn || u.nickname || u.uid}</span>
<span className="text-xs text-[var(--dg-text-muted)]">@{u.username}</span> <span className="text-xs text-[var(--dg-text-muted)]">@{u.uid || u.username}</span>
{u.email && <span className="text-xs text-[var(--dg-text-muted)]">{u.email}</span>} {u.mail && <span className="text-xs text-[var(--dg-text-muted)]">{u.mail}</span>}
</label> </label>
))} ))}
</div> </div>