Commit e5f6d0a9 authored by akari's avatar akari

fix: 修复SN读取跟写入

parent e5d7ce05
...@@ -12,7 +12,7 @@ class UserModel extends Equatable { ...@@ -12,7 +12,7 @@ class UserModel extends Equatable {
final String? hospitalName; final String? hospitalName;
// ignore: non_constant_identifier_names // ignore: non_constant_identifier_names
static String? MAC; static String? SN;
const UserModel({ const UserModel({
required this.id, required this.id,
......
...@@ -24,3 +24,6 @@ class TokenExpiredEvent {} ...@@ -24,3 +24,6 @@ class TokenExpiredEvent {}
// 退出登录事件 // 退出登录事件
class LogoutEvent {} class LogoutEvent {}
// 打开蓝牙扫描/绑定页面事件
class OpenBluetoothScanEvent {}
...@@ -9,7 +9,7 @@ class StorageService { ...@@ -9,7 +9,7 @@ class StorageService {
static const String _keyRememberSmsCode = 'remember_sms_code'; static const String _keyRememberSmsCode = 'remember_sms_code';
static const String _keyRememberEnabled = 'remember_enabled'; static const String _keyRememberEnabled = 'remember_enabled';
static const String _keyUserInfo = 'user_info'; static const String _keyUserInfo = 'user_info';
static const String _keyUserMac = 'user_mac'; static const String _keyUserSn = 'user_sn';
static const String _keyClientId = 'client_id'; static const String _keyClientId = 'client_id';
static const String _keyBoundBluetoothDeviceId = 'bound_bluetooth_device_id'; static const String _keyBoundBluetoothDeviceId = 'bound_bluetooth_device_id';
static const String _keyBoundBluetoothDeviceName = static const String _keyBoundBluetoothDeviceName =
...@@ -76,11 +76,12 @@ class StorageService { ...@@ -76,11 +76,12 @@ class StorageService {
final jsonStr = final jsonStr =
'${userInfo.id}|${userInfo.nickname ?? ''}|${userInfo.phone ?? ''}|${userInfo.avatar ?? ''}|${userInfo.type ?? ''}|${userInfo.canControlDevice ?? ''}|${userInfo.canViewOperation ?? ''}|${userInfo.hospitalId ?? ''}|${userInfo.hospitalName ?? ''}'; '${userInfo.id}|${userInfo.nickname ?? ''}|${userInfo.phone ?? ''}|${userInfo.avatar ?? ''}|${userInfo.type ?? ''}|${userInfo.canControlDevice ?? ''}|${userInfo.canViewOperation ?? ''}|${userInfo.hospitalId ?? ''}|${userInfo.hospitalName ?? ''}';
await _storage.write(key: _keyUserInfo, value: jsonStr); await _storage.write(key: _keyUserInfo, value: jsonStr);
await getUserSn();
} }
Future<UserModel?> getUserInfo() async { Future<UserModel?> getUserInfo() async {
final value = await _storage.read(key: _keyUserInfo); final value = await _storage.read(key: _keyUserInfo);
UserModel.MAC = await getUserMac(); UserModel.SN = await getUserSn();
if (value == null || value.isEmpty) return null; if (value == null || value.isEmpty) return null;
final parts = value.split('|'); final parts = value.split('|');
if (parts.length < 9) return null; if (parts.length < 9) return null;
...@@ -101,20 +102,20 @@ class StorageService { ...@@ -101,20 +102,20 @@ class StorageService {
await _storage.delete(key: _keyUserInfo); await _storage.delete(key: _keyUserInfo);
} }
Future<void> saveUserMac(String mac) async { Future<void> saveUserSn(String sn) async {
UserModel.MAC = mac; UserModel.SN = sn;
await _storage.write(key: _keyUserMac, value: mac); await _storage.write(key: _keyUserSn, value: sn);
} }
Future<String?> getUserMac() async { Future<String?> getUserSn() async {
final mac = await _storage.read(key: _keyUserMac); final sn = await _storage.read(key: _keyUserSn);
UserModel.MAC = mac; UserModel.SN = sn;
return mac; return sn;
} }
Future<void> deleteUserMac() async { Future<void> deleteUserSn() async {
UserModel.MAC = null; UserModel.SN = null;
await _storage.delete(key: _keyUserMac); await _storage.delete(key: _keyUserSn);
} }
// ==================== ClientId 相关 ==================== // ==================== ClientId 相关 ====================
......
...@@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; ...@@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../../routes/app_router.gr.dart'; import '../../routes/app_router.gr.dart';
import '../../utils/event_bus.dart';
import 'cubit/default_layout_cubit.dart'; import 'cubit/default_layout_cubit.dart';
import 'cubit/default_layout_state.dart'; import 'cubit/default_layout_state.dart';
import 'widgets/monitoring_bottom_menu.dart'; import 'widgets/monitoring_bottom_menu.dart';
...@@ -78,9 +79,7 @@ class _DefaultLayoutContent extends StatelessWidget { ...@@ -78,9 +79,7 @@ class _DefaultLayoutContent extends StatelessWidget {
return PreferredSize( return PreferredSize(
preferredSize: Size.fromHeight(104.h), preferredSize: Size.fromHeight(104.h),
child: Container( child: Container(
decoration: const BoxDecoration( decoration: const BoxDecoration(),
// border: BoxBorder.all(width: 1.w,color: Colors.red)
),
child: Stack( child: Stack(
children: [ children: [
Positioned( Positioned(
...@@ -92,7 +91,7 @@ class _DefaultLayoutContent extends StatelessWidget { ...@@ -92,7 +91,7 @@ class _DefaultLayoutContent extends StatelessWidget {
height: 162.h, height: 162.h,
), ),
), ),
Container( SizedBox(
height: 104.h, height: 104.h,
child: const MonitoringTopStatusBar(), child: const MonitoringTopStatusBar(),
), ),
...@@ -107,6 +106,15 @@ class _DefaultLayoutContent extends StatelessWidget { ...@@ -107,6 +106,15 @@ class _DefaultLayoutContent extends StatelessWidget {
menuItems: state.menuItems, menuItems: state.menuItems,
selectedMenuId: selectedMenuId, selectedMenuId: selectedMenuId,
onMenuItemTap: (menuId) { onMenuItemTap: (menuId) {
if (menuId == 'tsaas') {
if (tabsRouter.activeIndex != 0) {
tabsRouter.setActiveIndex(0);
}
WidgetsBinding.instance.addPostFrameCallback((_) {
eventBus.emit(OpenBluetoothScanEvent());
});
return;
}
final index = indexFromMenuId(menuId); final index = indexFromMenuId(menuId);
tabsRouter.setActiveIndex(index); tabsRouter.setActiveIndex(index);
}, },
......
...@@ -13,11 +13,9 @@ class MonitoringTopStatusBar extends StatelessWidget { ...@@ -13,11 +13,9 @@ class MonitoringTopStatusBar extends StatelessWidget {
fit: BoxFit.fill, fit: BoxFit.fill,
), ),
), ),
padding: EdgeInsets.only(left: 32.w,bottom: 22.h), padding: EdgeInsets.only(left: 32.w, bottom: 22.h),
child: Row( child: Row(
children: [ children: [
// SizedBox(width: 18.w),
Text( Text(
'总运行时长:9999h', '总运行时长:9999h',
style: TextStyle( style: TextStyle(
...@@ -41,12 +39,8 @@ class MonitoringTopStatusBar extends StatelessWidget { ...@@ -41,12 +39,8 @@ class MonitoringTopStatusBar extends StatelessWidget {
fontSize: 25.sp, fontSize: 25.sp,
), ),
), ),
// const Spacer(),
], ],
), ),
); );
} }
} }
...@@ -83,11 +83,16 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -83,11 +83,16 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
emit(state.copyWith(bluetoothMessage: message)); emit(state.copyWith(bluetoothMessage: message));
}); });
_bluetoothDataSub = _bluetoothManager.dataStream.listen((packet) { _bluetoothDataSub = _bluetoothManager.dataStream.listen((packet) async {
if (isClosed) return; if (isClosed) return;
try { try {
final reports = _mcuReportDecoder.addBytes(packet.bytes); final reports = _mcuReportDecoder.addBytes(packet.bytes);
final latestReport = reports.isEmpty ? null : reports.last; final latestReport = reports.isEmpty ? null : reports.last;
final latestSn = latestReport?.sn.trim();
if (latestSn != null && latestSn.isNotEmpty) {
await _storageService.saveUserSn(latestSn);
if (isClosed) return;
}
emit(state.copyWith( emit(state.copyWith(
latestBluetoothRawHex: packet.rawHex, latestBluetoothRawHex: packet.rawHex,
latestMcuReport: latestReport, latestMcuReport: latestReport,
...@@ -108,14 +113,7 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -108,14 +113,7 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
final boundDevice = await _storageService.getBoundBluetoothDevice(); final boundDevice = await _storageService.getBoundBluetoothDevice();
if (isClosed) return; if (isClosed) return;
final deviceId = boundDevice['deviceId']; final deviceId = boundDevice['deviceId'];
if (deviceId != null && deviceId.isNotEmpty) { await _storageService.getUserSn();
final userMac = await _storageService.getUserMac();
if (userMac == null || userMac.isEmpty) {
await _storageService.saveUserMac(deviceId);
}
} else {
await _storageService.getUserMac();
}
if (isClosed) return; if (isClosed) return;
emit(state.copyWith( emit(state.copyWith(
boundBluetoothDeviceId: boundBluetoothDeviceId:
...@@ -312,7 +310,6 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -312,7 +310,6 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
deviceId: device.remoteId, deviceId: device.remoteId,
deviceName: device.name, deviceName: device.name,
); );
await _storageService.saveUserMac(device.remoteId);
if (isClosed) return; if (isClosed) return;
emit(state.copyWith( emit(state.copyWith(
isBluetoothBinding: false, isBluetoothBinding: false,
...@@ -334,7 +331,7 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> { ...@@ -334,7 +331,7 @@ class MonitoringIndexCubit extends Cubit<MonitoringIndexState> {
Future<void> unbindBluetoothDevice() async { Future<void> unbindBluetoothDevice() async {
await _bluetoothManager.disconnect(); await _bluetoothManager.disconnect();
await _storageService.deleteBoundBluetoothDevice(); await _storageService.deleteBoundBluetoothDevice();
await _storageService.deleteUserMac(); await _storageService.deleteUserSn();
_mcuReportDecoder.clear(); _mcuReportDecoder.clear();
if (isClosed) return; if (isClosed) return;
emit(state.copyWith( emit(state.copyWith(
......
import 'dart:async';
import 'package:auto_route/auto_route.dart'; import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:laki_icu_app/enums/video_stream_mode_enum.dart'; import 'package:laki_icu_app/enums/video_stream_mode_enum.dart';
import 'package:laki_icu_app/models/bo/monitoring_bo.dart'; import 'package:laki_icu_app/models/bo/monitoring_bo.dart';
import 'package:laki_icu_app/utils/event_bus.dart';
import 'cubit/monitoring_index_cubit.dart'; import 'cubit/monitoring_index_cubit.dart';
import 'cubit/monitoring_index_state.dart'; import 'cubit/monitoring_index_state.dart';
...@@ -35,11 +38,22 @@ class MonitoringIndexContent extends StatefulWidget { ...@@ -35,11 +38,22 @@ class MonitoringIndexContent extends StatefulWidget {
class _MonitoringIndexContentState extends State<MonitoringIndexContent> { class _MonitoringIndexContentState extends State<MonitoringIndexContent> {
late final MonitoringIndexCubit _monitoringIndexCubit; late final MonitoringIndexCubit _monitoringIndexCubit;
StreamSubscription<OpenBluetoothScanEvent>? _bluetoothScanEventSub;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_monitoringIndexCubit = context.read<MonitoringIndexCubit>(); _monitoringIndexCubit = context.read<MonitoringIndexCubit>();
_bluetoothScanEventSub = eventBus.on<OpenBluetoothScanEvent>().listen((_) {
if (!mounted) return;
_showBluetoothDialog();
});
}
@override
void dispose() {
_bluetoothScanEventSub?.cancel();
super.dispose();
} }
@override @override
...@@ -136,13 +150,8 @@ class _MonitoringIndexContentState extends State<MonitoringIndexContent> { ...@@ -136,13 +150,8 @@ class _MonitoringIndexContentState extends State<MonitoringIndexContent> {
for (int i = 0; i < displayMetrics.length; i++) { for (int i = 0; i < displayMetrics.length; i++) {
children.add( children.add(
Expanded( Expanded(
child: Container(
decoration: BoxDecoration(
// border: BoxBorder.all(width: 1.w, color: Colors.red),
),
child: MonitoringMetricCard(metric: displayMetrics[i]), child: MonitoringMetricCard(metric: displayMetrics[i]),
), ),
),
); );
if (i < displayMetrics.length - 1) { if (i < displayMetrics.length - 1) {
children.add(SizedBox(width: 20.w)); children.add(SizedBox(width: 20.w));
......
...@@ -75,7 +75,7 @@ class _BluetoothBindDialogState extends State<BluetoothBindDialog> { ...@@ -75,7 +75,7 @@ class _BluetoothBindDialogState extends State<BluetoothBindDialog> {
'设备连接', '设备连接',
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 42.sp, fontSize: 49.sp,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
), ),
), ),
...@@ -84,7 +84,7 @@ class _BluetoothBindDialogState extends State<BluetoothBindDialog> { ...@@ -84,7 +84,7 @@ class _BluetoothBindDialogState extends State<BluetoothBindDialog> {
'搜索蓝牙设备完成配对连接', '搜索蓝牙设备完成配对连接',
style: TextStyle( style: TextStyle(
color: Colors.white.withValues(alpha: 0.84), color: Colors.white.withValues(alpha: 0.84),
fontSize: 22.sp, fontSize: 29.sp,
), ),
), ),
], ],
...@@ -147,7 +147,7 @@ class _BluetoothBindDialogState extends State<BluetoothBindDialog> { ...@@ -147,7 +147,7 @@ class _BluetoothBindDialogState extends State<BluetoothBindDialog> {
message, message,
style: TextStyle( style: TextStyle(
color: Colors.white.withValues(alpha: 0.88), color: Colors.white.withValues(alpha: 0.88),
fontSize: 21.sp, fontSize: 28.sp,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
), ),
maxLines: 1, maxLines: 1,
...@@ -174,7 +174,7 @@ class _BluetoothBindDialogState extends State<BluetoothBindDialog> { ...@@ -174,7 +174,7 @@ class _BluetoothBindDialogState extends State<BluetoothBindDialog> {
style: TextButton.styleFrom( style: TextButton.styleFrom(
foregroundColor: Colors.white, foregroundColor: Colors.white,
disabledForegroundColor: Colors.white70, disabledForegroundColor: Colors.white70,
textStyle: TextStyle(fontSize: 17.sp), textStyle: TextStyle(fontSize: 24.sp),
), ),
), ),
], ],
...@@ -188,7 +188,7 @@ class _BluetoothBindDialogState extends State<BluetoothBindDialog> { ...@@ -188,7 +188,7 @@ class _BluetoothBindDialogState extends State<BluetoothBindDialog> {
state.isBluetoothScanning ? '正在扫描附近设备...' : '暂无设备', state.isBluetoothScanning ? '正在扫描附近设备...' : '暂无设备',
style: TextStyle( style: TextStyle(
color: Colors.white.withValues(alpha: 0.76), color: Colors.white.withValues(alpha: 0.76),
fontSize: 24.sp, fontSize: 31.sp,
), ),
), ),
); );
...@@ -290,7 +290,7 @@ class _BluetoothBindDialogState extends State<BluetoothBindDialog> { ...@@ -290,7 +290,7 @@ class _BluetoothBindDialogState extends State<BluetoothBindDialog> {
color: rawHex != null && rawHex.isNotEmpty color: rawHex != null && rawHex.isNotEmpty
? const Color(0xFF00F6FF) ? const Color(0xFF00F6FF)
: Colors.white.withValues(alpha: 0.66), : Colors.white.withValues(alpha: 0.66),
fontSize: 15.sp, fontSize: 22.sp,
), ),
maxLines: 2, maxLines: 2,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
...@@ -323,7 +323,7 @@ class _BluetoothReportSummary extends StatelessWidget { ...@@ -323,7 +323,7 @@ class _BluetoothReportSummary extends StatelessWidget {
report.sn.isEmpty ? 'SN --' : 'SN ${report.sn}', report.sn.isEmpty ? 'SN --' : 'SN ${report.sn}',
style: TextStyle( style: TextStyle(
color: const Color(0xFF00F6FF), color: const Color(0xFF00F6FF),
fontSize: 15.sp, fontSize: 22.sp,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
), ),
maxLines: 1, maxLines: 1,
...@@ -380,14 +380,14 @@ class _BluetoothReportMetric extends StatelessWidget { ...@@ -380,14 +380,14 @@ class _BluetoothReportMetric extends StatelessWidget {
text: '$label ', text: '$label ',
style: TextStyle( style: TextStyle(
color: Colors.white.withValues(alpha: 0.58), color: Colors.white.withValues(alpha: 0.58),
fontSize: 13.sp, fontSize: 20.sp,
), ),
), ),
TextSpan( TextSpan(
text: value, text: value,
style: TextStyle( style: TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 16.sp, fontSize: 23.sp,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
), ),
), ),
...@@ -395,7 +395,7 @@ class _BluetoothReportMetric extends StatelessWidget { ...@@ -395,7 +395,7 @@ class _BluetoothReportMetric extends StatelessWidget {
text: unit, text: unit,
style: TextStyle( style: TextStyle(
color: Colors.white.withValues(alpha: 0.72), color: Colors.white.withValues(alpha: 0.72),
fontSize: 12.sp, fontSize: 19.sp,
), ),
), ),
], ],
...@@ -446,7 +446,7 @@ class _BluetoothDeviceRow extends StatelessWidget { ...@@ -446,7 +446,7 @@ class _BluetoothDeviceRow extends StatelessWidget {
device.name, device.name,
style: TextStyle( style: TextStyle(
color: textColor, color: textColor,
fontSize: 26.sp, fontSize: 33.sp,
fontWeight: isBound ? FontWeight.w600 : FontWeight.w400, fontWeight: isBound ? FontWeight.w600 : FontWeight.w400,
), ),
maxLines: 1, maxLines: 1,
...@@ -457,7 +457,7 @@ class _BluetoothDeviceRow extends StatelessWidget { ...@@ -457,7 +457,7 @@ class _BluetoothDeviceRow extends StatelessWidget {
'${device.remoteId} RSSI ${device.rssi}', '${device.remoteId} RSSI ${device.rssi}',
style: TextStyle( style: TextStyle(
color: Colors.white.withValues(alpha: 0.42), color: Colors.white.withValues(alpha: 0.42),
fontSize: 13.sp, fontSize: 20.sp,
), ),
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
...@@ -473,7 +473,7 @@ class _BluetoothDeviceRow extends StatelessWidget { ...@@ -473,7 +473,7 @@ class _BluetoothDeviceRow extends StatelessWidget {
textAlign: TextAlign.left, textAlign: TextAlign.left,
style: TextStyle( style: TextStyle(
color: textColor, color: textColor,
fontSize: 25.sp, fontSize: 32.sp,
fontWeight: isBound ? FontWeight.w600 : FontWeight.w400, fontWeight: isBound ? FontWeight.w600 : FontWeight.w400,
), ),
), ),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment