新版UI-登录页面-我的页面(简单适配)-设备的部分(无设备的+有设备)
This commit is contained in:
@@ -0,0 +1,344 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:maibu_satabot_v2/components/capsule_toast.dart';
|
||||
|
||||
/// 设备状态 V2 —— 卡片视图设计稿组件。
|
||||
///
|
||||
/// 纯展示组件:点击回调、在线状态、电量均由页面传入真实数据
|
||||
/// (在线态来自 onlineStatus,电量来自 battery / capacityPercent,与旧卡片一致)。
|
||||
/// 仅版本 / SN 掩码等后端暂未返回的字段用设备 ID 做**稳定伪随机**占位
|
||||
/// (同一设备每次渲染结果一致,不会闪变),等后端补齐字段后替换为真值即可。
|
||||
|
||||
/// 设备展示状态(对应设计稿徽章:作业中 / 在线 / 离线)
|
||||
enum DeviceV2Status { working, online, offline }
|
||||
|
||||
/// 占位数据生成器:以设备唯一串为种子,保证同设备结果稳定
|
||||
class DeviceV2Display {
|
||||
DeviceV2Display._();
|
||||
|
||||
static const _editions = ['PLUS 智能版', 'STD 标准版', 'PRO 旗舰版'];
|
||||
|
||||
static int _seed(String key) => key.hashCode & 0x7FFFFFFF;
|
||||
|
||||
/// 版本后缀:PLUS 智能版 / STD 标准版 / PRO 旗舰版
|
||||
static String editionOf(String key) => _editions[_seed(key) % _editions.length];
|
||||
|
||||
/// SN 掩码展示:前4 · · · 后2
|
||||
static String maskedSn(String key) {
|
||||
if (key.length <= 6) return key.toUpperCase();
|
||||
return '${key.substring(0, 4)} · · · ${key.substring(key.length - 2)}'
|
||||
.toUpperCase();
|
||||
}
|
||||
|
||||
/// 底部作业态文案
|
||||
static String workTextOf(DeviceV2Status status) {
|
||||
return switch (status) {
|
||||
DeviceV2Status.working => '自主作业中',
|
||||
DeviceV2Status.online => '待机',
|
||||
DeviceV2Status.offline => '暂时无法连接',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// 设计稿设备卡片:缩略图 + 名称/徽章 + 型号版本 + SN + 底部作业态/电量
|
||||
class DeviceCardV2 extends StatelessWidget {
|
||||
const DeviceCardV2({
|
||||
super.key,
|
||||
required this.name,
|
||||
required this.modelText,
|
||||
required this.snKey,
|
||||
required this.status,
|
||||
required this.onTap,
|
||||
this.batteryLevel,
|
||||
});
|
||||
|
||||
/// 设备名称(别名优先,页面已处理)
|
||||
final String name;
|
||||
|
||||
/// 型号 · 版本,如 "MC700 · PLUS 智能版"
|
||||
final String modelText;
|
||||
|
||||
/// 用于 SN 掩码/复制与占位随机的设备唯一串
|
||||
final String snKey;
|
||||
|
||||
final DeviceV2Status status;
|
||||
|
||||
/// 真实电量百分比(离线或无数据时传 null,卡片显示 --)
|
||||
final int? batteryLevel;
|
||||
|
||||
/// 卡片点击:与旧卡片同一跳转逻辑
|
||||
final VoidCallback onTap;
|
||||
|
||||
// ===== 固定视觉配色(与登录/我的/无设备页 V2 同系) =====
|
||||
static const _navy = Color(0xFF1A2B4A);
|
||||
static const _grayText = Color(0xFF86909C);
|
||||
static const _primaryBlue = Color(0xFF1C96F6);
|
||||
static const _cardBorder = Color(0xFFE9F1FA);
|
||||
static const _workingOrange = Color(0xFFF5A623);
|
||||
static const _workingBg = Color(0xFFFEF3E3);
|
||||
static const _onlineGreen = Color(0xFF2FBF6B);
|
||||
static const _onlineBg = Color(0xFFE5F8EC);
|
||||
static const _offlineGray = Color(0xFF6B7280);
|
||||
static const _offlineBg = Color(0xFFF0F2F5);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final offline = status == DeviceV2Status.offline;
|
||||
final battery = offline ? null : batteryLevel;
|
||||
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: _cardBorder),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: _primaryBlue.withValues(alpha: 0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildThumb(offline),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
name,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
// 编辑(改名):后端能力未接,统一提示
|
||||
GestureDetector(
|
||||
onTap: () =>
|
||||
CapsuleToast.show('功能暂未开发', showCheck: false),
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 6),
|
||||
child: Icon(
|
||||
Icons.edit_outlined,
|
||||
size: 15,
|
||||
color: _grayText,
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildBadge(),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
modelText,
|
||||
style: const TextStyle(fontSize: 13, color: _grayText),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
Flexible(
|
||||
child: Text(
|
||||
'SN: ${DeviceV2Display.maskedSn(snKey)}',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
color: _grayText,
|
||||
),
|
||||
),
|
||||
),
|
||||
// 复制完整 SN
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
await Clipboard.setData(
|
||||
ClipboardData(text: snKey),
|
||||
);
|
||||
CapsuleToast.show('SN 已复制到剪贴板');
|
||||
},
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 6),
|
||||
child: Icon(
|
||||
Icons.copy_rounded,
|
||||
size: 15,
|
||||
color: _grayText,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
// 更多操作:二级未开发
|
||||
GestureDetector(
|
||||
onTap: () =>
|
||||
CapsuleToast.show('功能暂未开发', showCheck: false),
|
||||
child: Container(
|
||||
width: 32,
|
||||
height: 32,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF3F6FA),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.more_horiz,
|
||||
size: 18,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
const Icon(
|
||||
Icons.chevron_right,
|
||||
size: 20,
|
||||
color: Color(0xFFC9CDD4),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 10),
|
||||
child: Divider(height: 1, color: Color(0xFFF0F4FA)),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
offline
|
||||
? Icons.link_off
|
||||
: Icons.monitor_heart_outlined,
|
||||
size: 18,
|
||||
color: offline ? _offlineGray : _primaryBlue,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
DeviceV2Display.workTextOf(status),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: offline ? _offlineGray : _navy,
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.keyboard_arrow_right,
|
||||
size: 16,
|
||||
color: Color(0xFFC9CDD4),
|
||||
),
|
||||
const Spacer(),
|
||||
_buildBattery(battery),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 缩略图:透明底车图,离线时置灰
|
||||
Widget _buildThumb(bool offline) {
|
||||
return Container(
|
||||
width: 96,
|
||||
height: 78,
|
||||
clipBehavior: Clip.antiAlias,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
gradient: const LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [Color(0xFFEAF3FE), Color(0xFFD9EAFB)],
|
||||
),
|
||||
),
|
||||
child: () {
|
||||
final car = Image.asset(
|
||||
'assets/images/shebei-logo.png',
|
||||
fit: BoxFit.cover,
|
||||
);
|
||||
// 离线置灰;在线不能套任何滤镜(transparent 滤镜会把图洗没)
|
||||
if (!offline) return car;
|
||||
return ColorFiltered(
|
||||
colorFilter: const ColorFilter.matrix(<double>[
|
||||
0.33, 0.33, 0.33, 0, 40, //
|
||||
0.33, 0.33, 0.33, 0, 40, //
|
||||
0.33, 0.33, 0.33, 0, 40, //
|
||||
0, 0, 0, 1, 0, //
|
||||
]),
|
||||
child: car,
|
||||
);
|
||||
}(),
|
||||
);
|
||||
}
|
||||
|
||||
/// 状态徽章:作业中(橙) / 在线(绿) / 离线(灰)
|
||||
Widget _buildBadge() {
|
||||
final (color, bg, label) = switch (status) {
|
||||
DeviceV2Status.working => (_workingOrange, _workingBg, '作业中'),
|
||||
DeviceV2Status.online => (_onlineGreen, _onlineBg, '在线'),
|
||||
DeviceV2Status.offline => (_offlineGray, _offlineBg, '离线'),
|
||||
};
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(color: bg, borderRadius: BorderRadius.circular(20)),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 5,
|
||||
height: 5,
|
||||
decoration: BoxDecoration(color: color, shape: BoxShape.circle),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(fontSize: 11, fontWeight: FontWeight.w600, color: color),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 电量:离线显示空电池 + --
|
||||
Widget _buildBattery(int? level) {
|
||||
if (level == null) {
|
||||
return const Row(
|
||||
children: [
|
||||
Icon(Icons.battery_unknown, size: 18, color: _offlineGray),
|
||||
SizedBox(width: 4),
|
||||
Text('--', style: TextStyle(fontSize: 13, color: _offlineGray)),
|
||||
],
|
||||
);
|
||||
}
|
||||
final icon = switch (level) {
|
||||
>= 80 => Icons.battery_full,
|
||||
>= 50 => Icons.battery_5_bar,
|
||||
>= 25 => Icons.battery_3_bar,
|
||||
_ => Icons.battery_2_bar,
|
||||
};
|
||||
return Row(
|
||||
children: [
|
||||
Icon(icon, size: 18, color: _onlineGreen),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'$level%',
|
||||
style: const TextStyle(fontSize: 13, color: _navy),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user