From 47d9e666c1f69675fc3e3b4c737ce75402bb1df2 Mon Sep 17 00:00:00 2001 From: liyi Date: Mon, 15 Sep 2025 18:16:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E5=96=84=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E3=80=81=E5=88=A0=E9=99=A4=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E3=80=81=E6=90=9C=E7=B4=A2=E7=BD=91=E7=BB=9C=E3=80=81=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E7=BD=91=E7=BB=9C=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/base/base_controller.dart | 10 ++ .../constant/app_view_parameter_keys.dart | 2 + lib/routes/app_pages.dart | 14 ++ lib/routes/app_routes.dart | 2 + .../device_configure_network_binding.dart | 9 ++ .../device_configure_network_controller.dart | 45 +++++++ .../device_configure_network_view.dart | 80 +++++++++++ .../deviceManage/device_manage_view.dart | 115 ++++++++-------- .../device_search_network_binding.dart | 9 ++ .../device_search_network_controller.dart | 45 +++++++ .../device_search_network_view.dart | 125 ++++++++++++++++++ lib/views/home/home_controller.dart | 2 - lib/views/main/main_controller.dart | 7 +- 13 files changed, 407 insertions(+), 58 deletions(-) create mode 100644 lib/views/device/deviceConfigureNetwork/device_configure_network_binding.dart create mode 100644 lib/views/device/deviceConfigureNetwork/device_configure_network_controller.dart create mode 100644 lib/views/device/deviceConfigureNetwork/device_configure_network_view.dart create mode 100644 lib/views/device/deviceSearchNetwork/device_search_network_binding.dart create mode 100644 lib/views/device/deviceSearchNetwork/device_search_network_controller.dart create mode 100644 lib/views/device/deviceSearchNetwork/device_search_network_view.dart diff --git a/lib/base/base_controller.dart b/lib/base/base_controller.dart index bed984f..de67215 100644 --- a/lib/base/base_controller.dart +++ b/lib/base/base_controller.dart @@ -48,6 +48,16 @@ class BaseController extends GetxController { ); } + @override + void onInit() { + super.onInit(); + } + + @override + void onReady() { + super.onReady(); + } + @override void onClose() { if (EasyLoading.isShow) { diff --git a/lib/common/constant/app_view_parameter_keys.dart b/lib/common/constant/app_view_parameter_keys.dart index f3b7ce2..8bb0124 100644 --- a/lib/common/constant/app_view_parameter_keys.dart +++ b/lib/common/constant/app_view_parameter_keys.dart @@ -1,4 +1,6 @@ class AppViewParameterKeys { static const String deviceList = "deviceList"; + static const String lockInfo = "lockInfo"; + static const String networkInfo = "networkInfo"; } \ No newline at end of file diff --git a/lib/routes/app_pages.dart b/lib/routes/app_pages.dart index d1a3b16..b4d1974 100644 --- a/lib/routes/app_pages.dart +++ b/lib/routes/app_pages.dart @@ -2,8 +2,12 @@ import 'package:get/get.dart'; import 'package:starwork_flutter/routes/app_routes.dart'; import 'package:starwork_flutter/views/device/confirmPairDevice/confirm_pair_device_binding.dart'; import 'package:starwork_flutter/views/device/confirmPairDevice/confirm_pair_device_view.dart'; +import 'package:starwork_flutter/views/device/deviceConfigureNetwork/device_configure_network_binding.dart'; +import 'package:starwork_flutter/views/device/deviceConfigureNetwork/device_configure_network_view.dart'; import 'package:starwork_flutter/views/device/deviceManage/device_manage_binding.dart'; import 'package:starwork_flutter/views/device/deviceManage/device_manage_view.dart'; +import 'package:starwork_flutter/views/device/deviceSearchNetwork/device_search_network_binding.dart'; +import 'package:starwork_flutter/views/device/deviceSearchNetwork/device_search_network_view.dart'; import 'package:starwork_flutter/views/device/removeDevice/remove_device_binding.dart'; import 'package:starwork_flutter/views/device/removeDevice/remove_device_view.dart'; import 'package:starwork_flutter/views/device/searchDevice/search_device_binding.dart'; @@ -137,5 +141,15 @@ class AppPages { page: () => RemoveDeviceView(), binding: RemoveDeviceBinding(), ), + GetPage( + name: AppRoutes.deviceConfigureNetwork, + page: () => DeviceConfigureNetworkView(), + binding: DeviceConfigureNetworkBinding(), + ), + GetPage( + name: AppRoutes.deviceSearchNetwork, + page: () => DeviceSearchNetworkView(), + binding: DeviceSearchNetworkBinding(), + ), ]; } diff --git a/lib/routes/app_routes.dart b/lib/routes/app_routes.dart index 79aa67f..ff6793a 100644 --- a/lib/routes/app_routes.dart +++ b/lib/routes/app_routes.dart @@ -19,4 +19,6 @@ class AppRoutes{ static const String searchDevice = '/device/searchDevice'; static const String confirmPairDevice = '/device/confirmPairDevice'; static const String deviceRemoveDevice = '/device/removeDevice'; + static const String deviceSearchNetwork = '/device/searchNetwork'; + static const String deviceConfigureNetwork = '/device/configureNetwork'; } \ No newline at end of file diff --git a/lib/views/device/deviceConfigureNetwork/device_configure_network_binding.dart b/lib/views/device/deviceConfigureNetwork/device_configure_network_binding.dart new file mode 100644 index 0000000..f79e126 --- /dev/null +++ b/lib/views/device/deviceConfigureNetwork/device_configure_network_binding.dart @@ -0,0 +1,9 @@ +import 'package:get/get.dart'; +import 'package:starwork_flutter/views/device/deviceConfigureNetwork/device_configure_network_controller.dart'; + +class DeviceConfigureNetworkBinding implements Bindings { + @override + void dependencies() { + Get.lazyPut(() => DeviceConfigureNetworkController()); + } +} diff --git a/lib/views/device/deviceConfigureNetwork/device_configure_network_controller.dart b/lib/views/device/deviceConfigureNetwork/device_configure_network_controller.dart new file mode 100644 index 0000000..380b5c4 --- /dev/null +++ b/lib/views/device/deviceConfigureNetwork/device_configure_network_controller.dart @@ -0,0 +1,45 @@ +import 'package:flutter/widgets.dart'; +import 'package:get/get.dart'; +import 'package:starcloud/entity/star_cloud_lock_list.dart'; +import 'package:starcloud/entity/star_cloud_search_wifi_result.dart'; +import 'package:starcloud/sdk/sdk_configure_network_operate_extension.dart'; +import 'package:starcloud/sdk/starcloud.dart'; +import 'package:starwork_flutter/base/base_controller.dart'; +import 'package:starwork_flutter/common/constant/app_view_parameter_keys.dart'; + +class DeviceConfigureNetworkController extends BaseController { + // 锁信息 + StarCloudLock? lockInfo; + StarCloudSearchWifiResult? networkInfo; + + TextEditingController wifiNameInputController = TextEditingController(); + + @override + void onReady() { + super.onReady(); + // 读取参数 + final args = Get.arguments; + if (args != null && args.containsKey(AppViewParameterKeys.lockInfo)) { + final json = args[AppViewParameterKeys.lockInfo]; + lockInfo = StarCloudLock.fromJson(json, 0); + } + if (args != null && args.containsKey(AppViewParameterKeys.networkInfo)) { + final json = args[AppViewParameterKeys.networkInfo]; + networkInfo = StarCloudSearchWifiResult.fromJson(json); + } + } + + void configureNetwork() { + StarCloudSDK.instance.connectWiFi( + lockId: lockInfo!.lockId, + onError: (err) { + print("配置网络失败:${err}"); + }, + onSuccess: () {}, + wifiName: networkInfo!.ssid, + wifiPassword: '', + clientId: '', + starLockPeerId: '', + ); + } +} diff --git a/lib/views/device/deviceConfigureNetwork/device_configure_network_view.dart b/lib/views/device/deviceConfigureNetwork/device_configure_network_view.dart new file mode 100644 index 0000000..4cbe100 --- /dev/null +++ b/lib/views/device/deviceConfigureNetwork/device_configure_network_view.dart @@ -0,0 +1,80 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/src/widgets/framework.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; +import 'package:starwork_flutter/common/constant/app_colors.dart'; +import 'package:starwork_flutter/common/widgets/custome_app_bar_wdiget.dart'; +import 'package:starwork_flutter/views/device/deviceConfigureNetwork/device_configure_network_controller.dart'; + +class DeviceConfigureNetworkView extends GetView { + @override + Widget build(BuildContext context) { + // 即使不使用,只是引用一下 controller 就能触发初始化 + final _ = controller; // 添加这一行 + + return Scaffold( + backgroundColor: AppColors.scaffoldBackgroundColor, + appBar: CustomAppBarWidget( + title: '配置网络'.tr, + ), + body: SafeArea( + child: Column( + children: [ + Container( + height: 38.h, + padding: EdgeInsets.symmetric( + horizontal: 10.w, + ), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(8.r), + ), + child: Row( + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + '*', + style: TextStyle( + fontSize: 14.sp, + fontWeight: FontWeight.w500, + color: Colors.red, + ), + ), + Text( + '团队名称', + style: TextStyle( + fontSize: 14.sp, + fontWeight: FontWeight.w500, + ), + ), + ], + ), + Expanded( + // 使用Expanded来确保TextField可以正确填充剩余空间 + child: TextField( + controller: controller.wifiNameInputController, + keyboardType: TextInputType.text, + textInputAction: TextInputAction.done, + textAlign: TextAlign.end, + decoration: InputDecoration( + hintText: '请输入团队/家庭名称'.tr, + // 设置无边框 + border: InputBorder.none, + // 获取焦点时的边框 + focusedBorder: InputBorder.none, + enabledBorder: InputBorder.none, + ), + ), + ), + ], + ), + ), + ], + ), + ), + ); + } +} diff --git a/lib/views/device/deviceManage/device_manage_view.dart b/lib/views/device/deviceManage/device_manage_view.dart index cea868c..cd90a99 100644 --- a/lib/views/device/deviceManage/device_manage_view.dart +++ b/lib/views/device/deviceManage/device_manage_view.dart @@ -288,63 +288,70 @@ class DeviceManageView extends GetView { itemCount: controller.filteredDeviceList.length, itemBuilder: (context, index) { final lock = controller.filteredDeviceList[index]; - return Container( - width: double.infinity, - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.all(Radius.circular(8.r)), - ), - padding: EdgeInsets.symmetric( - horizontal: 10.w, - ), - alignment: Alignment.centerLeft, - child: Obx( - () => Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (controller.selectedDeviceType.value.iconImagePath != null) - Image( - image: AssetImage(controller.selectedDeviceType.value.iconImagePath!), - width: 26.w, - height: 26.w, - fit: BoxFit.contain, - gaplessPlayback: true, - // 防止闪烁 - filterQuality: FilterQuality.medium, - // 优化过滤质量 - errorBuilder: (context, error, stackTrace) { - return Icon( - Icons.image_not_supported, - size: 26.sp, - color: Colors.grey, - ); - }, + return GestureDetector( + onTap: () { + Get.toNamed(AppRoutes.deviceSearchNetwork, arguments: { + 'lockInfo': lock.toJson(), + }); + }, + child: Container( + width: double.infinity, + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.all(Radius.circular(8.r)), + ), + padding: EdgeInsets.symmetric( + horizontal: 10.w, + ), + alignment: Alignment.centerLeft, + child: Obx( + () => Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (controller.selectedDeviceType.value.iconImagePath != null) + Image( + image: AssetImage(controller.selectedDeviceType.value.iconImagePath!), + width: 26.w, + height: 26.w, + fit: BoxFit.contain, + gaplessPlayback: true, + // 防止闪烁 + filterQuality: FilterQuality.medium, + // 优化过滤质量 + errorBuilder: (context, error, stackTrace) { + return Icon( + Icons.image_not_supported, + size: 26.sp, + color: Colors.grey, + ); + }, + ), + SizedBox( + height: 6.h, ), - SizedBox( - height: 6.h, - ), - Text( - lock.lockName, - style: TextStyle( - fontSize: 10.sp, - fontWeight: FontWeight.w400, + Text( + lock.lockName, + style: TextStyle( + fontSize: 10.sp, + fontWeight: FontWeight.w400, + ), + maxLines: 1, + overflow: TextOverflow.ellipsis, ), - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - SizedBox( - height: 4.h, - ), - Text( - lock.isOnline ?? false ? '在线' : '离线', - style: TextStyle( - color: lock.isOnline ?? false ? Colors.green : Colors.grey, - fontSize: 10.sp, - fontWeight: FontWeight.w500, + SizedBox( + height: 4.h, ), - ) - ], + Text( + lock.isOnline ?? false ? '在线' : '离线', + style: TextStyle( + color: lock.isOnline ?? false ? Colors.green : Colors.grey, + fontSize: 10.sp, + fontWeight: FontWeight.w500, + ), + ) + ], + ), ), ), ); diff --git a/lib/views/device/deviceSearchNetwork/device_search_network_binding.dart b/lib/views/device/deviceSearchNetwork/device_search_network_binding.dart new file mode 100644 index 0000000..b3913e3 --- /dev/null +++ b/lib/views/device/deviceSearchNetwork/device_search_network_binding.dart @@ -0,0 +1,9 @@ +import 'package:get/get.dart'; +import 'package:starwork_flutter/views/device/deviceSearchNetwork/device_search_network_controller.dart'; + +class DeviceSearchNetworkBinding extends Bindings{ + @override + void dependencies() { + Get.lazyPut(() => DeviceSearchNetworkController()); + } +} \ No newline at end of file diff --git a/lib/views/device/deviceSearchNetwork/device_search_network_controller.dart b/lib/views/device/deviceSearchNetwork/device_search_network_controller.dart new file mode 100644 index 0000000..0d0f787 --- /dev/null +++ b/lib/views/device/deviceSearchNetwork/device_search_network_controller.dart @@ -0,0 +1,45 @@ +import 'package:get/get.dart'; +import 'package:starcloud/entity/star_cloud_lock_list.dart'; +import 'package:starcloud/entity/star_cloud_search_wifi_result.dart'; +import 'package:starcloud/sdk/sdk_configure_network_operate_extension.dart'; +import 'package:starcloud/sdk/starcloud.dart'; +import 'package:starwork_flutter/base/app_logger.dart'; +import 'package:starwork_flutter/base/base_controller.dart'; +import 'package:starwork_flutter/common/constant/app_view_parameter_keys.dart'; + +class DeviceSearchNetworkController extends BaseController { + // 锁信息 + StarCloudLock? lockInfo; + + // wifi列表 + final searchResultWifiList = [].obs; + + @override + void onReady() { + super.onReady(); + // 读取参数 + final args = Get.arguments; + if (args != null && args.containsKey(AppViewParameterKeys.lockInfo)) { + final json = args[AppViewParameterKeys.lockInfo]; + lockInfo = StarCloudLock.fromJson(json, 0); + } + starSearchNetwork(); + } + + void starSearchNetwork() { + searchResultWifiList.clear(); + showLoading(); + StarCloudSDK.instance.searchWiFi( + lockId: lockInfo!.lockId, + onError: (err) { + print("搜索wifi失败:${err}"); + hideLoading(); + }, + onSuccess: (List result) { + searchResultWifiList.value = result; + searchResultWifiList.refresh(); + hideLoading(); + }, + ); + } +} diff --git a/lib/views/device/deviceSearchNetwork/device_search_network_view.dart b/lib/views/device/deviceSearchNetwork/device_search_network_view.dart new file mode 100644 index 0000000..29359cc --- /dev/null +++ b/lib/views/device/deviceSearchNetwork/device_search_network_view.dart @@ -0,0 +1,125 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/src/widgets/framework.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; +import 'package:starcloud/entity/star_cloud_lock_list.dart'; +import 'package:starwork_flutter/base/app_logger.dart'; +import 'package:starwork_flutter/common/constant/app_colors.dart'; +import 'package:starwork_flutter/common/constant/app_view_parameter_keys.dart'; +import 'package:starwork_flutter/common/widgets/custome_app_bar_wdiget.dart'; +import 'package:starwork_flutter/extension/function_extension.dart'; +import 'package:starwork_flutter/routes/app_routes.dart'; +import 'package:starwork_flutter/views/device/deviceSearchNetwork/device_search_network_controller.dart'; + +class DeviceSearchNetworkView extends GetView { + const DeviceSearchNetworkView({super.key}); + + @override + Widget build(BuildContext context) { + // 即使不使用,只是引用一下 controller 就能触发初始化 + final _ = controller; // 添加这一行 + + return Scaffold( + backgroundColor: AppColors.scaffoldBackgroundColor, + appBar: CustomAppBarWidget( + title: '搜索网络'.tr, + actions: [ + TextButton( + onPressed: () { + controller.starSearchNetwork(); + }, + child: Text( + '刷新'.tr, + style: TextStyle( + fontSize: 16.sp, + color: Colors.black87, + fontWeight: FontWeight.w500, + ), + ), + ) + ], + ), + body: SafeArea( + child: Column( + children: [ + Expanded( + child: Obx( + () { + return Container( + padding: EdgeInsets.symmetric( + horizontal: 10.w, + vertical: 10.h, + ), + child: ListView.builder( + itemBuilder: (context, index) { + final item = controller.searchResultWifiList[index]; + return GestureDetector( + onTap: () { + Get.toNamed( + AppRoutes.deviceConfigureNetwork, + arguments: { + AppViewParameterKeys.lockInfo: controller.lockInfo?.toJson(), + AppViewParameterKeys.networkInfo: item.toJson(), + }, + ); + }, + child: Container( + padding: EdgeInsets.symmetric( + horizontal: 10.w, + vertical: 10.h, + ), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(8.r), + ), + margin: EdgeInsets.only( + bottom: 10.h, + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Text( + item.ssid, + style: TextStyle( + fontSize: 16.sp, + color: Colors.black87, + ), + ), + Icon( + _getWifiSignalIcon( + item.rssi.toString(), + ), + color: Colors.blue, + ), + ], + ), + ), + ); + }, + itemCount: controller.searchResultWifiList.length, + ), + ); + }, + ), + ) + ], + ), + ), + ); + } + + /// 计算WiFi信号强度图标 + IconData _getWifiSignalIcon(String rssi) { + final int rssiValue = int.parse(rssi); + if (rssiValue >= -50) { + return Icons.signal_wifi_4_bar; + } else if (rssiValue >= -70) { + return Icons.network_wifi; + } else if (rssiValue >= -80) { + return Icons.network_wifi_2_bar_rounded; + } else { + return Icons.signal_wifi_0_bar; + } + } +} diff --git a/lib/views/home/home_controller.dart b/lib/views/home/home_controller.dart index 40f25da..98bed78 100644 --- a/lib/views/home/home_controller.dart +++ b/lib/views/home/home_controller.dart @@ -50,8 +50,6 @@ class HomeController extends BaseController { isOpenNotificationPermission.value = await AppPermission.checkPermission( permission: Permission.notification, ); - // 触发刷新设备列表 - EventBusUtil().instance.fire(RefreshDeviceListEvent()); } // 根据轮播图索引更新渐变颜色 diff --git a/lib/views/main/main_controller.dart b/lib/views/main/main_controller.dart index 3fd0ced..5406915 100644 --- a/lib/views/main/main_controller.dart +++ b/lib/views/main/main_controller.dart @@ -54,8 +54,8 @@ class MainController extends BaseController { late StreamSubscription _refreshDeviceListSubscription; @override - void onInit() { - super.onInit(); + void onReady() { + super.onReady(); /// 请求团队信息 requestAllTeamInfoList(); @@ -214,15 +214,18 @@ class MainController extends BaseController { } void _requestTeamDeviceList() async { + showLoading(); await StarCloudSDK.instance.getDeviceList( pageNo: 1, pageSize: 999, cloudUid: selectedTeam.value.teamCloudInfo!.uid!, onSuccess: (StarCloudLockList list) { deviceCountSize.value = list.total; + hideLoading(); }, onError: (err) { AppLogger.error('获取设备列表失败:${err}'); + hideLoading(); }, ); }