Commit e5f6d0a9 authored by akari's avatar akari

fix: 修复SN读取跟写入

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