补全设备负责人显示
This commit is contained in:
@@ -72,6 +72,8 @@ class _RobotOwnershipPageV2State extends State<RobotOwnershipPageV2> {
|
||||
|
||||
/// 组织列表:只用于把 orgId 翻成组织名
|
||||
List<OrgEntity> _orgs = const [];
|
||||
List<UserSimpleEntity> _users = const [];
|
||||
int _usersLoadGeneration = 0;
|
||||
|
||||
bool get _online => widget.robot.isOnline;
|
||||
|
||||
@@ -79,6 +81,39 @@ class _RobotOwnershipPageV2State extends State<RobotOwnershipPageV2> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadOrgs();
|
||||
_loadOwnerUsers();
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant RobotOwnershipPageV2 oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.robot.userId != widget.robot.userId ||
|
||||
oldWidget.robot.userName != widget.robot.userName ||
|
||||
oldWidget.robot.siteId != widget.robot.siteId ||
|
||||
oldWidget.siteId != widget.siteId) {
|
||||
_users = const [];
|
||||
_loadOwnerUsers();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadOwnerUsers() async {
|
||||
final generation = ++_usersLoadGeneration;
|
||||
final userId = widget.robot.userId;
|
||||
final siteId = widget.robot.siteId ?? widget.siteId;
|
||||
if (widget.robot.userName?.trim().isNotEmpty == true ||
|
||||
userId == null ||
|
||||
userId <= 0 ||
|
||||
siteId == null ||
|
||||
siteId <= 0) {
|
||||
return;
|
||||
}
|
||||
// 复用扫码绑定的人员查询,由设备的负责人编号匹配姓名。
|
||||
final result = await sl<GetUsersBySiteUseCase>()(siteId);
|
||||
if (!mounted || generation != _usersLoadGeneration) return;
|
||||
result.fold(
|
||||
(failure) => debugPrint('>>> [Ownership] 负责人姓名加载失败: ${failure.message}'),
|
||||
(users) => setState(() => _users = users),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _loadOrgs() async {
|
||||
@@ -117,7 +152,14 @@ class _RobotOwnershipPageV2State extends State<RobotOwnershipPageV2> {
|
||||
|
||||
String? get _ownerName {
|
||||
final direct = widget.robot.userName?.trim();
|
||||
return (direct != null && direct.isNotEmpty) ? direct : null;
|
||||
if (direct != null && direct.isNotEmpty) return direct;
|
||||
for (final user in _users) {
|
||||
if (user.id == widget.robot.userId) {
|
||||
final name = user.name.trim();
|
||||
return name.isNotEmpty ? name : null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String get _snText =>
|
||||
|
||||
Reference in New Issue
Block a user