优化+摄像头+扫码绑定

This commit is contained in:
2026-08-10 10:00:52 +08:00
parent db70665ced
commit 9dc445eeb5
41 changed files with 2618 additions and 438 deletions

View File

@@ -92,6 +92,8 @@ class _BindDevicePageState extends State<BindDevicePage> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildRoleTag(state.roleKey),
const SizedBox(height: 16),
_buildRequiredField(
label: '已选装备 ID',
child: Container(
@@ -126,10 +128,15 @@ class _BindDevicePageState extends State<BindDevicePage> {
child: _buildSiteDropdown(state),
),
const SizedBox(height: 16),
_buildField(
label: '负责人',
child: _buildUserDropdown(state),
),
_cubit.roleKey == 'user'
? _buildRequiredField(
label: '负责人',
child: _buildUserDropdown(state),
)
: _buildField(
label: '负责人',
child: _buildUserDropdown(state),
),
const SizedBox(height: 32),
Row(
children: [
@@ -206,6 +213,12 @@ class _BindDevicePageState extends State<BindDevicePage> {
);
}
int? _validValue(List<dynamic> list, int? selectedId) {
if (selectedId == null) return null;
final count = list.where((e) => e.id == selectedId).length;
return count == 1 ? selectedId : null;
}
Widget _buildOrgDropdown(BindDeviceState state) {
final enabled = _cubit.isOrgEnabled;
final selectedName = state.selectedOrgId != null
@@ -214,23 +227,22 @@ class _BindDevicePageState extends State<BindDevicePage> {
.fold<String?>(null, (_, org) => org.name)
: null;
if (!enabled && selectedName != null) {
return _buildReadonlyField(selectedName);
if (!enabled) {
return _buildReadonlyField(selectedName ?? '未分配组织');
}
final validValue = _validValue(state.orgList, state.selectedOrgId);
return Container(
decoration: BoxDecoration(
color: enabled ? Colors.white : const Color(0xFFF7F8FA),
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: const Color(0xFFE5E6EB)),
),
child: DropdownButtonFormField<int>(
value: state.selectedOrgId,
decoration: _dropdownDecoration(enabled),
icon: Icon(
Icons.expand_more,
color: enabled ? const Color(0xFF86909C) : const Color(0xFFC9CDD4),
),
value: validValue,
decoration: _dropdownDecoration(enabled, '请选择'),
icon: const Icon(Icons.expand_more, color: Color(0xFF86909C)),
items: state.orgList.map((org) {
return DropdownMenuItem<int>(
value: org.id,
@@ -241,11 +253,9 @@ class _BindDevicePageState extends State<BindDevicePage> {
),
);
}).toList(),
onChanged: enabled
? (v) {
if (v != null) _cubit.onOrgChanged(v);
}
: null,
onChanged: (v) {
if (v != null) _cubit.onOrgChanged(v);
},
),
);
}
@@ -258,23 +268,23 @@ class _BindDevicePageState extends State<BindDevicePage> {
.fold<String?>(null, (_, site) => site.name)
: null;
if (!enabled && selectedName != null) {
return _buildReadonlyField(selectedName);
if (!enabled) {
return _buildReadonlyField(selectedName ?? '未分配场站');
}
final hintText = state.selectedOrgId == null ? '请先选择组织' : '请选择';
final validValue = _validValue(state.siteList, state.selectedSiteId);
return Container(
decoration: BoxDecoration(
color: enabled ? Colors.white : const Color(0xFFF7F8FA),
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: const Color(0xFFE5E6EB)),
),
child: DropdownButtonFormField<int>(
value: state.selectedSiteId,
decoration: _dropdownDecoration(enabled),
icon: Icon(
Icons.expand_more,
color: enabled ? const Color(0xFF86909C) : const Color(0xFFC9CDD4),
),
value: validValue,
decoration: _dropdownDecoration(enabled, hintText),
icon: const Icon(Icons.expand_more, color: Color(0xFF86909C)),
items: state.siteList.map((site) {
return DropdownMenuItem<int>(
value: site.id,
@@ -285,11 +295,9 @@ class _BindDevicePageState extends State<BindDevicePage> {
),
);
}).toList(),
onChanged: enabled
? (v) {
if (v != null) _cubit.onSiteChanged(v);
}
: null,
onChanged: (v) {
if (v != null) _cubit.onSiteChanged(v);
},
),
);
}
@@ -302,23 +310,23 @@ class _BindDevicePageState extends State<BindDevicePage> {
.fold<String?>(null, (_, user) => user.name)
: null;
if (!enabled && selectedName != null) {
return _buildReadonlyField(selectedName);
if (!enabled) {
return _buildReadonlyField(selectedName ?? '未分配负责人');
}
final hintText = state.selectedSiteId == null ? '请先选择场站' : '请选择';
final validValue = _validValue(state.userList, state.selectedUserId);
return Container(
decoration: BoxDecoration(
color: enabled ? Colors.white : const Color(0xFFF7F8FA),
color: Colors.white,
borderRadius: BorderRadius.circular(8),
border: Border.all(color: const Color(0xFFE5E6EB)),
),
child: DropdownButtonFormField<int>(
value: state.selectedUserId,
decoration: _dropdownDecoration(enabled),
icon: Icon(
Icons.expand_more,
color: enabled ? const Color(0xFF86909C) : const Color(0xFFC9CDD4),
),
value: validValue,
decoration: _dropdownDecoration(enabled, hintText),
icon: const Icon(Icons.expand_more, color: Color(0xFF86909C)),
items: state.userList.map((user) {
return DropdownMenuItem<int>(
value: user.id,
@@ -329,11 +337,37 @@ class _BindDevicePageState extends State<BindDevicePage> {
),
);
}).toList(),
onChanged: enabled
? (v) {
_cubit.onUserChanged(v);
}
: null,
onChanged: (v) {
if (v != null) _cubit.onUserChanged(v);
},
),
);
}
Widget _buildRoleTag(String roleKey) {
final roleLabel =
const {
'admin': '管理员',
'manager': '组织管理员',
'siteManager': '场站管理员',
'user': '普通用户',
}[roleKey] ??
'普通用户';
return Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(
color: const Color(0xFFE8F3FF),
borderRadius: BorderRadius.circular(4),
border: Border.all(color: const Color(0xFF165DFF), width: 0.5),
),
child: Text(
'当前角色:$roleLabel($roleKey)',
style: const TextStyle(
fontSize: 12,
color: Color(0xFF165DFF),
fontWeight: FontWeight.w500,
),
),
);
}
@@ -361,14 +395,14 @@ class _BindDevicePageState extends State<BindDevicePage> {
);
}
InputDecoration _dropdownDecoration(bool enabled) {
InputDecoration _dropdownDecoration(bool enabled, String hintText) {
return InputDecoration(
isDense: true,
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
border: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
hintText: enabled ? '请选择' : '请选择',
hintText: hintText,
hintStyle: const TextStyle(color: Color(0xFF86909C), fontSize: 14),
);
}

View File

@@ -618,8 +618,8 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
productName: robot.type,
tenantId: 0,
tenantName: '',
status: robot.status == '在线' ? 1 : 0,
onlineStatus: robot.status == '在线' ? 1 : 0,
status: robot.isOnline ? 1 : 0,
onlineStatus: robot.isOnline ? 1 : 0,
);
final remoteCubit = GetIt.I<RemoteControlCubit>();
@@ -784,6 +784,13 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
BuildContext context,
DeviceListState.DeviceStatusLoaded state,
) {
// 从实际设备列表计算统计数据(不再使用硬编码的假数据)
final devices = state.devices;
final totalCount = devices.length;
final onlineCount = devices.where((d) => d.status == '在线').length;
final exceptionCount = devices.where((d) => d.status == '异常').length;
final offlineCount = totalCount - onlineCount - exceptionCount;
return Container(
margin: const EdgeInsets.symmetric(horizontal: 16.0),
padding: const EdgeInsets.all(16.0),
@@ -801,7 +808,7 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
child: Row(
children: [
_buildStatItem(
value: state.deviceStatus.total.toString(),
value: totalCount.toString(),
label: AppLocalizations.of(
context,
).translate('device_list_v2.total_devices'),
@@ -810,7 +817,7 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
),
Container(width: 1, height: 40, color: const Color(0xFFE5E6EB)),
_buildStatItem(
value: state.deviceStatus.online.toString(),
value: onlineCount.toString(),
label: AppLocalizations.of(
context,
).translate('device_list_v2.online'),
@@ -819,7 +826,7 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
),
Container(width: 1, height: 40, color: const Color(0xFFE5E6EB)),
_buildStatItem(
value: state.deviceStatus.exception.toString(),
value: exceptionCount.toString(),
label: AppLocalizations.of(
context,
).translate('device_list_v2.alarm'),
@@ -828,7 +835,7 @@ class _DeviceStatusViewState extends State<DeviceStatusView> {
),
Container(width: 1, height: 40, color: const Color(0xFFE5E6EB)),
_buildStatItem(
value: state.deviceStatus.offline.toString(),
value: offlineCount.toString(),
label: AppLocalizations.of(
context,
).translate('device_list_v2.offline'),

View File

@@ -109,11 +109,11 @@ class _RobotListViewState extends State<RobotListView> {
final weedingRobots = allRobots.where((r) => r.type == 'weeding').toList();
final onlineInspection = inspectionRobots
.where((r) => r.status == '在线')
.where((r) => r.isOnline)
.length;
final onlineCleaning = cleaningRobots.where((r) => r.status == '在线').length;
final onlineCleaning = cleaningRobots.where((r) => r.isOnline).length;
// 暂且所有设备都视为除草机器人,在线数使用总数
final onlineWeeding = allRobots.where((r) => r.status == '在线').length;
final onlineWeeding = allRobots.where((r) => r.isOnline).length;
return Container(
margin: const EdgeInsets.fromLTRB(16, 16, 16, 12),
padding: const EdgeInsets.symmetric(vertical: 16),
@@ -385,14 +385,12 @@ class _RobotListViewState extends State<RobotListView> {
Widget _buildQuickActions(RobotListLoaded state) {
// 计算统计数据
final onlineCount = state.robots.where((r) => r.status == '在线').length;
final onlineCount = state.robots.where((r) => r.isOnline).length;
final workingCount = state.robots
.where((r) => r.task != '待机中' && r.task != '充电中')
.length;
final standbyCount = state.robots.where((r) => r.task == '待机中').length;
final faultCount = state.robots
.where((r) => r.status == '异常' || r.status == '离线')
.length;
final faultCount = state.robots.where((r) => !r.isOnline).length;
return Container(
margin: const EdgeInsets.fromLTRB(16, 0, 16, 12),
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 16),
@@ -429,7 +427,7 @@ class _RobotListViewState extends State<RobotListView> {
Container(width: 1, height: 40, color: const Color(0xFFE5E6EB)),
_buildStatusItem(
value: '$faultCount',
label: '故障数',
label: '离线数',
valueColor: const Color(0xFFF53F3F),
),
],
@@ -474,6 +472,8 @@ class _RobotListViewState extends State<RobotListView> {
id: '',
type: '',
status: '',
isOnline: false,
statusCode: 0,
battery: 0,
task: '无任务',
),
@@ -641,8 +641,8 @@ class _RobotListViewState extends State<RobotListView> {
productName: robot.type,
tenantId: 0,
tenantName: '',
status: robot.status == '在线' ? 1 : 0,
onlineStatus: robot.status == '在线' ? 1 : 0,
status: robot.isOnline ? 1 : 0,
onlineStatus: robot.isOnline ? 1 : 0,
);
debugPrint('🎯 [RobotListPage] 准备调用 setTargetDevice...');