diff --git a/lib/appRouters.dart b/lib/appRouters.dart index 39a39eee..2906b045 100755 --- a/lib/appRouters.dart +++ b/lib/appRouters.dart @@ -158,6 +158,7 @@ import 'mine/addLock/nearbyLock/nearbyLock_page.dart'; import 'mine/addLock/saveLock/saveLock_page.dart'; import 'mine/addLock/selectLockType/selectLockType_page.dart'; import 'mine/gateway/addGateway/gatewayConfigurationWifi/gatewayConfigurationWifi_page.dart'; +import 'mine/gateway/addGateway/gatewayGetWifiList/gatewayGetWifiList_page.dart'; import 'mine/gateway/addGateway/selectGateway/selectGatewayList_page.dart'; import 'mine/gateway/addGateway/selectGatewayType/selectGatewayType_page.dart'; import 'mine/gateway/addGateway/selectGatewayTypeNextTip/selectGatewayTypeNextTip_page.dart'; @@ -344,6 +345,7 @@ abstract class Routers { static const String selectGatewayPage = '/SelectGatewayPage'; // 我的-选择网关 static const String gatewayConfigurationWifiPage = '/GatewayConfigurationWifiPage'; // 我的-网关配置wifi + static const String gatewayGetWifiListPage = '/GatewayGetWifiListPage'; // 我的-网关获取wifi列表 static const String messageListPage = '/MessageListPage'; // 我的-消息 static const String messageDetailPage = '/MessageDetailPage'; // 我的-消息详情 @@ -1162,5 +1164,7 @@ abstract class AppRouters { name: Routers.remoteControlDetailPage, page: () => const RemoteControlDetailPage()), GetPage( name: Routers.palmDetailPage, page: () => const PalmDetailPage()), + GetPage( + name: Routers.gatewayGetWifiListPage, page: () => const GatewayGetWifiListPage()), ]; } diff --git a/lib/app_settings/app_colors.dart b/lib/app_settings/app_colors.dart index ee4fd41b..6de61046 100755 --- a/lib/app_settings/app_colors.dart +++ b/lib/app_settings/app_colors.dart @@ -109,6 +109,7 @@ class AppColors { static Color popMenuItemSelectedColor = const Color(0xFF063F71); static Color blackColor = const Color(0xFF000000); + static Color whiteColor = const Color(0xFFFFFFFF); static Color dateSelectedBgColor = const Color(0xFF0093E5); static Color dateSelectedTextColor = const Color(0xFFFFFFFF); diff --git a/lib/blue/io_protocol/io_gateway_configuringWifi.dart b/lib/blue/io_protocol/io_gateway_configuringWifi.dart new file mode 100644 index 00000000..6523660e --- /dev/null +++ b/lib/blue/io_protocol/io_gateway_configuringWifi.dart @@ -0,0 +1,82 @@ + +// 网关配网 +import 'dart:convert'; + +import '../io_reply.dart'; +import '../io_sender.dart'; +import '../io_tool/io_tool.dart'; +import '../io_type.dart'; +import '../sm4Encipher/sm4.dart'; +import 'package:crypto/crypto.dart' as crypto; + +class GatewayConfiguringWifiCommand extends SenderProtocol { + + GatewayConfiguringWifiCommand({ + this.ssid, + this.password, + }) : super(CommandType.gatewayConfiguringWifi); + + String? ssid; + String? password; + + + @override + String toString() { + return 'SenderConfiguringWifiCommand{ssid: $ssid, password: $password}'; + } + + @override + List messageDetail() { + final List data = []; + List subData = []; + + // 指令类型 + final int type = commandType!.typeValue; + final double typeDouble = type / 256; + final int type1 = typeDouble.toInt(); + final int type2 = type % 256; + data.add(type1); + data.add(type2); + + //SSID 30 + final int ssidLength = utf8.encode(ssid!).length; + subData.addAll(utf8.encode(ssid!)); + subData = getFixedLengthList(subData, 30 - ssidLength); + + //Password 20 + final int passwordLength = utf8.encode(password!).length; + subData.addAll(utf8.encode(password!)); + subData = getFixedLengthList(subData, 20 - passwordLength); + + data.add(subData.length); + data.addAll(subData); + + if ((data.length % 16) != 0) { + final int add = 16 - data.length % 16; + for (int i = 0; i < add; i++) { + data.add(0); + } + } + + printLog(data); + return data; + } +} + +class GatewayConfiguringWifiReply extends Reply { + GatewayConfiguringWifiReply.parseData(CommandType commandType, List dataDetail) + : super.parseData(commandType, dataDetail) { + data = dataDetail; + final int status = data[5]; + errorWithStstus(status); + } +} + +class GatewayConfiguringWifiResultReply extends Reply { + GatewayConfiguringWifiResultReply.parseData(CommandType commandType, List dataDetail) + : super.parseData(commandType, dataDetail) { + data = dataDetail; + final int status = data[5]; + errorWithStstus(status); + } +} \ No newline at end of file diff --git a/lib/blue/io_protocol/io_gateway_getWifiList.dart b/lib/blue/io_protocol/io_gateway_getWifiList.dart new file mode 100644 index 00000000..e224dec4 --- /dev/null +++ b/lib/blue/io_protocol/io_gateway_getWifiList.dart @@ -0,0 +1,76 @@ + +import 'dart:convert'; + +import 'package:crypto/crypto.dart' as crypto; + +import '../../app_settings/app_settings.dart'; +import '../io_reply.dart'; +import '../io_sender.dart'; +import '../io_tool/io_tool.dart'; +import '../io_type.dart'; +import '../sm4Encipher/sm4.dart'; + +class GatewayGetWifiCommand extends SenderProtocol { + + GatewayGetWifiCommand({ + this.userID, + }) : super(CommandType.gatewayGetWifiList); + + String? userID; + + + @override + String toString() { + return 'SenderGetWifiCommand{userID: $userID}'; + } + + @override + List messageDetail() { + final List data = []; + List subData = []; + + // 指令类型 + final int type = commandType!.typeValue; + final double typeDouble = type / 256; + final int type1 = typeDouble.toInt(); + final int type2 = type % 256; + data.add(type1); + data.add(type2); + + + //userID 20 + final int userIDLength = utf8.encode(userID!).length; + subData.addAll(utf8.encode(userID!)); + subData = getFixedLengthList(subData, 20 - userIDLength); + AppLog.log('ebcData: $subData'); + + data.add(subData.length); + data.addAll(subData); + + if ((data.length % 16) != 0) { + final int add = 16 - data.length % 16; + for (int i = 0; i < add; i++) { + data.add(0); + } + } + + printLog(data); + return data; + } +} + +class GatewayGetWifiReply extends Reply { + GatewayGetWifiReply.parseData(CommandType commandType, List dataDetail) + : super.parseData(commandType, dataDetail) { + data = dataDetail; + final int status = data[2]; + errorWithStstus(status); + } +} + +class GatewayGetWifiListReply extends Reply { + GatewayGetWifiListReply.parseData(CommandType commandType, List dataDetail) + : super.parseData(commandType, dataDetail) { + data = dataDetail; + } +} diff --git a/lib/blue/io_type.dart b/lib/blue/io_type.dart index 8e21ec5b..f4e90564 100755 --- a/lib/blue/io_type.dart +++ b/lib/blue/io_type.dart @@ -24,6 +24,10 @@ enum CommandType { startOATUpgrade, //OTA升级开始 0x30E0 confirmationOTAUpgrade, //OTA升级开始 0x30E2 processOTAUpgrade, //OTA升级过程 0x30E1 + gatewayConfiguringWifi,//网关配网 0x30F4 + gatewayConfiguringWifiResult,//网关配网结果 0x30F5 + gatewayGetWifiList,//网关获取附近的wifi列表 0x30F6 + gatewayGetWifiListResult,//网关获取附近的wifi列表结果 0x30F7 generalExtendedCommond, // 通用扩展指令 = 0x3030 gecChangeAdministratorPassword, // 通用扩展指令子命令-修改管理员密码 = 2 @@ -181,6 +185,26 @@ extension ExtensionCommandType on CommandType { type = CommandType.confirmationOTAUpgrade; } break; + case 0x30F4: + { + type = CommandType.gatewayConfiguringWifi; + } + break; + case 0x30F5: + { + type = CommandType.gatewayConfiguringWifiResult; + } + break; + case 0x30F6: + { + type = CommandType.gatewayGetWifiList; + } + break; + case 0x30F7: + { + type = CommandType.gatewayGetWifiListResult; + } + break; default: { type = CommandType.readLockStatusInfo; @@ -268,6 +292,18 @@ extension ExtensionCommandType on CommandType { case CommandType.confirmationOTAUpgrade: type = 0x30E2; break; + case CommandType.gatewayConfiguringWifi: + type = 0x30F4; + break; + case CommandType.gatewayConfiguringWifiResult: + type = 0x30F5; + break; + case CommandType.gatewayGetWifiList: + type = 0x30F6; + break; + case CommandType.gatewayGetWifiListResult: + type = 0x30F7; + break; default: type = 0x300A; break; @@ -283,6 +319,8 @@ extension ExtensionCommandType on CommandType { switch (this) { case CommandType.getLockPublicKey: case CommandType.processOTAUpgrade: + case CommandType.gatewayGetWifiList: + case CommandType.gatewayConfiguringWifi: //不加密 type = 0x20; break; @@ -386,6 +424,18 @@ extension ExtensionCommandType on CommandType { case 0x30E1: t = 'oat升级过程'; break; + case 0x30F4: + t = '网关配网'; + break; + case 0x30F5: + t = '网关配网结果'; + break; + case 0x30F6: + t = '网关获取wifi列表'; + break; + case 0x30F7: + t = '网关获取附近的wifi列表结果'; + break; default: t = '读星锁状态信息'; break; diff --git a/lib/blue/reciver_data.dart b/lib/blue/reciver_data.dart index 4c11464b..d7d39dc9 100755 --- a/lib/blue/reciver_data.dart +++ b/lib/blue/reciver_data.dart @@ -10,6 +10,8 @@ import 'package:star_lock/blue/io_protocol/io_cleanUpUsers.dart'; import 'package:star_lock/blue/io_protocol/io_deletUser.dart'; import 'package:star_lock/blue/io_protocol/io_editUser.dart'; import 'package:star_lock/blue/io_protocol/io_factoryDataReset.dart'; +import 'package:star_lock/blue/io_protocol/io_gateway_configuringWifi.dart'; +import 'package:star_lock/blue/io_protocol/io_gateway_getWifiList.dart'; import 'package:star_lock/blue/io_protocol/io_otaUpgrade.dart'; import 'package:star_lock/blue/io_protocol/io_processOtaUpgrade.dart'; import 'package:star_lock/blue/io_protocol/io_queryingFaceStatus.dart'; @@ -250,6 +252,26 @@ class CommandReciverManager { reply = UpdataLockSetReply.parseData(commandType, data); } break; + case CommandType.gatewayConfiguringWifi: + { + reply = GatewayConfiguringWifiReply.parseData(commandType, data); + } + break; + case CommandType.gatewayConfiguringWifiResult: + { + reply = GatewayConfiguringWifiResultReply.parseData(commandType, data); + } + break; + case CommandType.gatewayGetWifiList: + { + reply = GatewayGetWifiReply.parseData(commandType, data); + } + break; + case CommandType.gatewayGetWifiListResult: + { + reply = GatewayGetWifiListReply.parseData(commandType, data); + } + break; case CommandType.generalExtendedCommond: { // 子命令类型 diff --git a/lib/blue/sender_manage.dart b/lib/blue/sender_manage.dart index c5b39779..ec436a09 100755 --- a/lib/blue/sender_manage.dart +++ b/lib/blue/sender_manage.dart @@ -3,6 +3,7 @@ import 'package:star_lock/blue/io_protocol/io_addFace.dart'; import 'package:star_lock/blue/io_protocol/io_changeAdministratorPassword.dart'; import 'package:star_lock/blue/io_protocol/io_cleanUpUsers.dart'; import 'package:star_lock/blue/io_protocol/io_deletUser.dart'; +import 'package:star_lock/blue/io_protocol/io_gateway_getWifiList.dart'; import 'package:star_lock/blue/io_protocol/io_otaUpgrade.dart'; import 'package:star_lock/blue/io_protocol/io_processOtaUpgrade.dart'; import 'package:star_lock/blue/io_protocol/io_queryingFaceStatus.dart'; @@ -24,6 +25,7 @@ import 'io_protocol/io_checkingUserInfoCount.dart'; import 'io_protocol/io_configuringWifi.dart'; import 'io_protocol/io_editUser.dart'; import 'io_protocol/io_factoryDataReset.dart'; +import 'io_protocol/io_gateway_configuringWifi.dart'; import 'io_protocol/io_getPrivateKey.dart'; import 'io_protocol/io_getPublicKey.dart'; import 'io_protocol/io_getStarLockStatusInfo.dart'; @@ -1531,4 +1533,30 @@ class IoSenderManage { callBack: callBack); } + // 网关获取wifi列表 + static void gatewayGetWifiCommand( + {required String? userID, + CommandSendCallBack? callBack}) { + CommandSenderManager().managerSendData( + command: GatewayGetWifiCommand( + userID: userID, + ), + isBeforeAddUser: true, + callBack: callBack); + } + + // 网关配网 + static void gatewayConfiguringWifiCommand({ + required String? ssid, + required String? password, + CommandSendCallBack? callBack}) { + CommandSenderManager().managerSendData( + command: GatewayConfiguringWifiCommand( + ssid: ssid, + password: password + ), + isBeforeAddUser: true, + callBack: callBack); + } + } diff --git a/lib/main/lockDetail/lockDetail/lockDetail_logic.dart b/lib/main/lockDetail/lockDetail/lockDetail_logic.dart index c8dfd0cb..a01f6214 100755 --- a/lib/main/lockDetail/lockDetail/lockDetail_logic.dart +++ b/lib/main/lockDetail/lockDetail/lockDetail_logic.dart @@ -292,6 +292,7 @@ class LockDetailLogic extends BaseGetXController { (0xff & indexList[5]) << 8 | (0xFF & indexList[6]); indexMap['date'] = '${time * 1000}'; + uploadList.add(indexMap); final int operateDate = time * 1000; diff --git a/lib/mine/gateway/addGateway/gatewayConfigurationWifi/gatewayConfigurationWifi_logic.dart b/lib/mine/gateway/addGateway/gatewayConfigurationWifi/gatewayConfigurationWifi_logic.dart index 9304d293..c00fdda5 100644 --- a/lib/mine/gateway/addGateway/gatewayConfigurationWifi/gatewayConfigurationWifi_logic.dart +++ b/lib/mine/gateway/addGateway/gatewayConfigurationWifi/gatewayConfigurationWifi_logic.dart @@ -1,8 +1,166 @@ +import 'dart:async'; + +import 'package:flutter_blue_plus/flutter_blue_plus.dart'; +import 'package:get/get.dart'; +import 'package:network_info_plus/network_info_plus.dart'; import 'package:star_lock/tools/baseGetXController.dart'; + +import '../../../../blue/blue_manage.dart'; +import '../../../../blue/io_protocol/io_gateway_configuringWifi.dart'; +import '../../../../blue/io_reply.dart'; +import '../../../../blue/io_tool/manager_event_bus.dart'; +import '../../../../blue/sender_manage.dart'; +import '../../../../login/login/entity/LoginEntity.dart'; +import '../../../../network/api_repository.dart'; import 'gatewayConfigurationWifi_state.dart'; class GatewayConfigurationWifiLogic extends BaseGetXController { - GatewayConfigurationWifiState state = GatewayConfigurationWifiState(); + final GatewayConfigurationWifiState state = GatewayConfigurationWifiState(); + Future gatewayDistributionNetwork() async{ + if(state.gatewayNamePasswardTF.text.isEmpty){ + showToast('请输入网关名称'.tr); + return; + } + + if(state.wifiNameTF.text.isEmpty){ + showToast('请输入wifi名称'.tr); + return; + } + + if(state.wifiPasswardTF.text.isEmpty){ + showToast('请输入WiFi密码'.tr); + return; + } + + + final LoginEntity entity = await ApiRepository.to.gatewayDistributionNetwork( + gatewayName: state.gatewayNamePasswardTF.text, + gatewayMac: state.macAddress, + serialNumber: DateTime.now().millisecondsSinceEpoch.toString(), + gatewayType: 2, + networkName: state.wifiNameTF.text, + networkMac: state.macAddress, + version: '1.0.0', + ); + if(entity.errorCode!.codeIsSuccessful){ + showToast('配网成功'.tr, something:(){ + // eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); + Get.close(4); + }); + } + } + + // 监听设备返回的数据 + late StreamSubscription _replySubscription; + void _initReplySubscription() { + _replySubscription = EventBusManager().eventBus!.on().listen((Reply reply) async { + // WIFI配网结果 + if(reply is GatewayConfiguringWifiReply) { + _replySenderConfiguringWifi(reply); + } + }); + } + + // WIFI配网结果 + Future _replySenderConfiguringWifi(Reply reply) async { + final int status = reply.data[5]; + + switch(status){ + case 0x00: + //成功 + state.sureBtnState.value = 0; + cancelBlueConnetctToastTimer(); + dismissEasyLoading(); + gatewayDistributionNetwork(); + break; + case 0x06: + //无权限 + IoSenderManage.gatewayConfiguringWifiCommand( + ssid: state.gatewayNamePasswardTF.text, + password: state.wifiPasswardTF.text, + ); + + break; + case 0xff: + //失败 + dismissEasyLoading(); + showToast('配网失败'.tr); + break; + default: + //失败 + dismissEasyLoading(); + break; + } + } + + // 点击配置wifi + Future senderConfiguringWifiAction() async { + if(state.gatewayNamePasswardTF.text.isEmpty){ + showToast('请输入wifi名称'.tr); + return; + } + + if(state.sureBtnState.value == 1){ + return; + } + state.sureBtnState.value = 1; + + showEasyLoading(); + showBlueConnetctToastTimer(action: (){ + dismissEasyLoading(); + state.sureBtnState.value = 0; + }); + BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected){ + IoSenderManage.gatewayConfiguringWifiCommand( + ssid: state.wifiNameTF.text, + password: state.wifiPasswardTF.text, + ); + } else if (connectionState == BluetoothConnectionState.disconnected) { + dismissEasyLoading(); + cancelBlueConnetctToastTimer(); + state.sureBtnState.value = 0; + if(state.ifCurrentScreen.value == true){ + showBlueConnetctToast(); + } + } + }, isAddEquipment: true); + } + + final NetworkInfo _networkInfo = NetworkInfo(); + Future getWifiName() async { + String ssid = ''; + ssid = (await _networkInfo.getWifiName())!; + ssid = ssid ?? ''; + ssid = ssid.replaceAll(r'"', ''); + return ssid ?? ''; + } + + @override + void onReady() { + super.onReady(); + + if(state.wifiNameTF.text.isEmpty){ + getWifiName().then((String value) { + state.wifiNameTF.text = value; + // update(); + // AppLog.log('wifiNameTF:${state.wifiNameTF.text} value:$value'); + }); + } + + _initReplySubscription(); + } + + @override + void onInit() { + super.onInit(); + } + + @override + void onClose() { + _replySubscription.cancel(); + super.onClose(); + } } \ No newline at end of file diff --git a/lib/mine/gateway/addGateway/gatewayConfigurationWifi/gatewayConfigurationWifi_page.dart b/lib/mine/gateway/addGateway/gatewayConfigurationWifi/gatewayConfigurationWifi_page.dart index 498580bc..e5f14d05 100755 --- a/lib/mine/gateway/addGateway/gatewayConfigurationWifi/gatewayConfigurationWifi_page.dart +++ b/lib/mine/gateway/addGateway/gatewayConfigurationWifi/gatewayConfigurationWifi_page.dart @@ -1,9 +1,12 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import '../../../../appRouters.dart'; import '../../../../app_settings/app_colors.dart'; +import '../../../../tools/appRouteObserver.dart'; import '../../../../tools/commonItem.dart'; import '../../../../tools/submitBtn.dart'; import '../../../../tools/titleAppBar.dart'; @@ -18,7 +21,7 @@ class GatewayConfigurationWifiPage extends StatefulWidget { _GatewayConfigurationWifiPageState(); } -class _GatewayConfigurationWifiPageState extends State { +class _GatewayConfigurationWifiPageState extends State with RouteAware { final GatewayConfigurationWifiLogic logic = Get.put(GatewayConfigurationWifiLogic()); final GatewayConfigurationWifiState state = Get.find().state; @@ -46,13 +49,13 @@ class _GatewayConfigurationWifiPageState extends State[ CommonItem( leftTitel: 'WiFi名称'.tr, - rightTitle: 'XinHongJia', - allHeight: 100.h, + rightTitle: '', + isHaveRightWidget: true, + allHeight: 80.h, isHaveLine: true, - isHaveDirection: true, - action: () { - // Navigator.pushNamed(context, Routers.minePersonInfoSetSafetyProblemPage); - }), + rightWidget: getTFWidget( + state.wifiNameTF, + '请输入wifi名称'.tr)), CommonItem( leftTitel: 'WiFi密码'.tr, rightTitle: '', @@ -77,65 +80,65 @@ class _GatewayConfigurationWifiPageState extends State Visibility( - visible: state.isUseStaticIP.value, - child: Column( - children: [ - CommonItem( - leftTitel: 'IP地址'.tr, - // rightTitle: '192.168.1.1', - isHaveLine: true, - isHaveRightWidget: true, - rightWidget: getTFWidget(state.ipAddressTF, '请输入IP地址'.tr) - ), - CommonItem( - leftTitel: '子网掩码'.tr, - // rightTitle: '255.255.255.0', - isHaveLine: true, - isHaveRightWidget: true, - rightWidget: getTFWidget(state.subnetMaskTF, '请输入子网掩码'.tr)), - CommonItem( - leftTitel: '默认网关'.tr, - // rightTitle: '192.168.1.1', - isHaveLine: true, - isHaveRightWidget: true, - rightWidget: getTFWidget(state.defaultGatewayTF, '请输入默认网关'.tr) - ), - SizedBox(height: 10.h,), - Obx(() => CommonItem( - leftTitel: '自动获取DNS服务器地址'.tr, - rightTitle: '', - isHaveLine: true, - isHaveRightWidget: true, - rightWidget: SizedBox( - width: 60.w, height: 50.h, child: _switch()))), - Visibility( - visible: !state.isAutomaticallyGetDNSServerAddress.value, - child: Column( - children: [ - CommonItem( - leftTitel: '首选DNS'.tr, - rightTitle: '', - isHaveLine: true, - isHaveRightWidget: true, - rightWidget: getTFWidget( - state.firstChoiceDNSTF, - '请输入'.tr)), - CommonItem( - leftTitel: '备选DNS'.tr, - rightTitle: '', - isHaveLine: false, - isHaveRightWidget: true, - rightWidget: getTFWidget( - state.alternativeDNSTF, - '请输入'.tr,)), - ], - )), - ], - ))), + // SizedBox( + // height: 10.h, + // ), + // Obx(() => Visibility( + // visible: state.isUseStaticIP.value, + // child: Column( + // children: [ + // CommonItem( + // leftTitel: 'IP地址'.tr, + // // rightTitle: '192.168.1.1', + // isHaveLine: true, + // isHaveRightWidget: true, + // rightWidget: getTFWidget(state.ipAddressTF, '请输入IP地址'.tr) + // ), + // CommonItem( + // leftTitel: '子网掩码'.tr, + // // rightTitle: '255.255.255.0', + // isHaveLine: true, + // isHaveRightWidget: true, + // rightWidget: getTFWidget(state.subnetMaskTF, '请输入子网掩码'.tr)), + // CommonItem( + // leftTitel: '默认网关'.tr, + // // rightTitle: '192.168.1.1', + // isHaveLine: true, + // isHaveRightWidget: true, + // rightWidget: getTFWidget(state.defaultGatewayTF, '请输入默认网关'.tr) + // ), + // SizedBox(height: 10.h,), + // Obx(() => CommonItem( + // leftTitel: '自动获取DNS服务器地址'.tr, + // rightTitle: '', + // isHaveLine: true, + // isHaveRightWidget: true, + // rightWidget: SizedBox( + // width: 60.w, height: 50.h, child: _switch()))), + // Visibility( + // visible: !state.isAutomaticallyGetDNSServerAddress.value, + // child: Column( + // children: [ + // CommonItem( + // leftTitel: '首选DNS'.tr, + // rightTitle: '', + // isHaveLine: true, + // isHaveRightWidget: true, + // rightWidget: getTFWidget( + // state.firstChoiceDNSTF, + // '请输入'.tr)), + // CommonItem( + // leftTitel: '备选DNS'.tr, + // rightTitle: '', + // isHaveLine: false, + // isHaveRightWidget: true, + // rightWidget: getTFWidget( + // state.alternativeDNSTF, + // '请输入'.tr,)), + // ], + // )), + // ], + // ))), SizedBox(height: 50.h), Container( margin: EdgeInsets.only(left: 20.w, right: 20.w), @@ -147,6 +150,7 @@ class _GatewayConfigurationWifiPageState extends State[ Expanded( child: TextField( + // 设置TextField font大小 //输入框一行 maxLines: 1, controller: controller, autofocus: false, textAlign: TextAlign.end, + style: TextStyle( + fontSize: 22.sp, // 设置字体大小 + ), decoration: InputDecoration( //输入里面输入文字内边距设置 hintText: tfStr, @@ -228,15 +236,64 @@ class _GatewayConfigurationWifiPageState extends State _replySubscription; + void _initReplySubscription() { + _replySubscription = EventBusManager().eventBus!.on().listen((Reply reply) { + if(reply is GatewayGetWifiReply) { + _replySendGetWifiParameters(reply); + } + + if(reply is GatewayGetWifiListReply) { + _replyGetWifiListParameters(reply); + } + }); + } + + // 发送获取wifi列表数据解析 + Future _replySendGetWifiParameters(Reply reply) async { + final int status = reply.data[2]; + switch(status){ + case 0x00: + //成功 + showEasyLoading(); + cancelBlueConnetctToastTimer(); + Future.delayed(5.seconds, dismissEasyLoading); + break; + case 0x06: + // 需要鉴权 + + // var token = await Storage.getStringList(saveBlueToken); + // List getTokenList = changeStringListToIntList(token!); + // + // var privateKey = await Storage.getStringList(saveBluePrivateKey); + // List getPrivateKeyList = changeStringListToIntList(privateKey!); + // + // var publicKey = await Storage.getStringList(saveBluePublicKey); + // List publicKeyDataList = changeStringListToIntList(publicKey!); + // + // IoSenderManage.getWifiListCommand( + // keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(), + // userID: await Storage.getUid(), + // token: getTokenList, + // needAuthor: 1, + // publicKey: publicKeyDataList, + // privateKey: getPrivateKeyList, + // ); + break; + default: + break; + } + } + + // 设置自动落锁数据解析 + Future _replyGetWifiListParameters(Reply reply) async { + final int status = reply.data[2]; + switch(status){ + case 0x00: + //成功 + // showEasyLoading(); + dismissEasyLoading(); + state.sureBtnState.value = 0; + + if (reply.data[6] > 0) { + reply.data.removeRange(0, 7); + // 把得到的数据按33位分割成数组 然后塞进一个新的数组里面 + final List> getList = splitList(reply.data, 33); + final List> uploadList = >[]; + for (int i = 0; i < getList.length; i++) { + final List indexList = getList[i]; + final Map indexMap = {}; + final List wifiName = indexList.sublist(0, 32); + indexMap['wifiName'] = utf8String(wifiName); + indexMap['rssi'] = (indexList.last - 255).toString(); + uploadList.add(indexMap); + state.wifiNameDataList.value = uploadList; + } + } + + break; + default: + break; + } + } + + // 获取wifi列表 + Future senderGetWifiListWifiAction() async { + if(state.sureBtnState.value == 1){ + return; + } + state.sureBtnState.value = 1; + + showEasyLoading(); + showBlueConnetctToastTimer(action: (){ + dismissEasyLoading(); + state.sureBtnState.value = 0; + }); + BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState connectionState) async { + if (connectionState == BluetoothConnectionState.connected){ + IoSenderManage.gatewayGetWifiCommand( + userID: await Storage.getUid(), + ); + } else if (connectionState == BluetoothConnectionState.disconnected) { + dismissEasyLoading(); + state.sureBtnState.value = 0; + cancelBlueConnetctToastTimer(); + if(state.ifCurrentScreen.value == true){ + showBlueConnetctToast(); + } + } + }, isAddEquipment: true); + } + + @override + void onReady() { + super.onReady(); + + _initReplySubscription(); + } + + @override + void onInit() { + super.onInit(); + + senderGetWifiListWifiAction(); + } + + @override + void onClose() { + super.onClose(); + _replySubscription.cancel(); + } + +} \ No newline at end of file diff --git a/lib/mine/gateway/addGateway/gatewayGetWifiList/gatewayGetWifiList_page.dart b/lib/mine/gateway/addGateway/gatewayGetWifiList/gatewayGetWifiList_page.dart new file mode 100644 index 00000000..8646f242 --- /dev/null +++ b/lib/mine/gateway/addGateway/gatewayGetWifiList/gatewayGetWifiList_page.dart @@ -0,0 +1,182 @@ + +import 'package:flutter/material.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; + +import '../../../../appRouters.dart'; +import '../../../../app_settings/app_colors.dart'; +import '../../../../tools/appRouteObserver.dart'; +import '../../../../tools/noData.dart'; +import '../../../../tools/submitBtn.dart'; +import '../../../../tools/titleAppBar.dart'; +import 'gatewayGetWifiList_logic.dart'; +import 'gatewayGetWifiList_state.dart'; + +class GatewayGetWifiListPage extends StatefulWidget { + const GatewayGetWifiListPage({Key? key}) : super(key: key); + + @override + State createState() => _GatewayGetWifiListPageState(); +} + +class _GatewayGetWifiListPageState extends State with RouteAware{ + final GatewayGetWifiListLogic logic = Get.put(GatewayGetWifiListLogic()); + final GatewayGetWifiListState state = Get.find().state; + + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: Colors.white, + appBar: TitleAppBar( + barTitle: 'WIFI列表'.tr, + haveBack: true, + actionsList: [ + TextButton( + child: Text( + '刷新'.tr, style: TextStyle(color: Colors.white, fontSize: 24.sp), + ), + onPressed: logic.senderGetWifiListWifiAction, + ), + ], + backgroundColor: AppColors.mainColor), + body: Column( + children: [ + Expanded( + child: Obx(() => state.wifiNameDataList.value.isNotEmpty ? ListView.builder( + itemCount: state.wifiNameDataList.value.length, + itemBuilder: (BuildContext c, int index) { + Map wifiNameStr = state.wifiNameDataList.value[index]; + return _messageListItem(wifiNameStr['wifiName'], wifiNameStr['rssi'], () { + Get.toNamed(Routers.gatewayConfigurationWifiPage, arguments: { + 'wifiName': wifiNameStr['wifiName'], + 'macAddress': state.macAddress + }); + }); + }) : NoData(noDataHeight: 1.sh - ScreenUtil().statusBarHeight - ScreenUtil().bottomBarHeight - 64.h)), + ), + SubmitBtn( + btnName: '手动配网'.tr, + fontSize: 28.sp, + borderRadius: 20.w, + padding: EdgeInsets.only(top: 25.w, bottom: 25.w), + onClick: () { + Get.toNamed(Routers.gatewayConfigurationWifiPage, arguments: { + 'wifiName': '', + 'macAddress': state.macAddress + }); + }), + SizedBox( + height: 64.h, + ) + ], + ) + ); + } + + Widget _messageListItem(String wifiName, String rssi, Function() action) { + return GestureDetector( + onTap: action, + child: Container( + height: 90.h, + width: 1.sw, + margin: EdgeInsets.only(bottom: 2.h), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(10.w), + ), + child: Container( + width: 1.sw, + height: 80.h, + margin: EdgeInsets.only(left: 20.w, right: 40.w), + child: Column( + children: [ + SizedBox( + height: 79.h, + width: 1.sw - 20.w*2, + child: Row( + // mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Flexible( + child: Text( + '$wifiName(${rssi}db)', + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontSize: 22.sp, color: AppColors.blackColor), + ), + ), + // Text( + // rssi, + // maxLines: 1, + // overflow: TextOverflow.ellipsis, + // style: TextStyle( + // fontSize: 22.sp, color: AppColors.blackColor), + // ) + ], + ), + ), + Container( + height: 1.h, + color: AppColors.greyLineColor, + ), + ], + ), + ), + ), + ); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + + /// 路由订阅 + AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!); + } + + @override + void dispose() { + /// 取消路由订阅 + AppRouteObserver().routeObserver.unsubscribe(this); + super.dispose(); + } + + /// 从上级界面进入 当前界面即将出现 + @override + void didPush() { + super.didPush(); + state.ifCurrentScreen.value = true; + } + + /// 返回上一个界面 当前界面即将消失 + @override + void didPop() { + super.didPop(); + logic.cancelBlueConnetctToastTimer(); + if (EasyLoading.isShow) { + EasyLoading.dismiss(animation: true); + } + state.ifCurrentScreen.value = false; + state.sureBtnState.value = 0; + } + + /// 从下级返回 当前界面即将出现 + @override + void didPopNext() { + super.didPopNext(); + state.ifCurrentScreen.value = true; + } + + /// 进入下级界面 当前界面即将消失 + @override + void didPushNext() { + super.didPushNext(); + logic.cancelBlueConnetctToastTimer(); + if (EasyLoading.isShow) { + EasyLoading.dismiss(animation: true); + } + state.ifCurrentScreen.value = false; + state.sureBtnState.value = 0; + } +} diff --git a/lib/mine/gateway/addGateway/gatewayGetWifiList/gatewayGetWifiList_state.dart b/lib/mine/gateway/addGateway/gatewayGetWifiList/gatewayGetWifiList_state.dart new file mode 100644 index 00000000..ad922eeb --- /dev/null +++ b/lib/mine/gateway/addGateway/gatewayGetWifiList/gatewayGetWifiList_state.dart @@ -0,0 +1,18 @@ + + +import 'package:get/get.dart'; + +class GatewayGetWifiListState{ + GatewayGetWifiListState() { + var map = Get.arguments; + if (map['macAddress'] != null && map['macAddress'] != '') { + macAddress = map['macAddress']; + } + } + + final RxList> wifiNameDataList = >[].obs; + + String macAddress = ''; + RxBool ifCurrentScreen = true.obs; // 是否是当前界面,用于判断是否需要针对当前界面进行展示 + RxInt sureBtnState = 0.obs; +} \ No newline at end of file diff --git a/lib/mine/gateway/addGateway/selectGateway/selectGatewayList_logic.dart b/lib/mine/gateway/addGateway/selectGateway/selectGatewayList_logic.dart index 16aec68f..98a1e798 100644 --- a/lib/mine/gateway/addGateway/selectGateway/selectGatewayList_logic.dart +++ b/lib/mine/gateway/addGateway/selectGateway/selectGatewayList_logic.dart @@ -32,6 +32,15 @@ class SelectGatewayListLogic extends BaseGetXController { }); } + void stopScanBlueList() { + // BlueManage().disconnect(); + BlueManage().stopScan(); + } + + void blueDisconnect() { + BlueManage().disconnect(); + } + Future getNearByLimits() async { if (!Platform.isIOS) { final bool bluetoothRequest = await PermissionDialog.requestBluetooth(); @@ -45,12 +54,19 @@ class SelectGatewayListLogic extends BaseGetXController { } // 点击连接设备 - void connect(String deviceName) { - BlueManage().blueSendData(deviceName, (BluetoothConnectionState state) async { + void connect(ScanResult device) { + showEasyLoading(); + showBlueConnetctToastTimer(action: () { + dismissEasyLoading(); + }); + BlueManage().blueSendData(device.advertisementData.advName, (BluetoothConnectionState state) async { // AppLog.log('点击要添加的设备了'); if (state == BluetoothConnectionState.connected) { - Get.toNamed(Routers.gatewayConfigurationWifiPage); - } else if (state == BluetoothConnectionState.disconnected) { + dismissEasyLoading(); + Get.toNamed(Routers.gatewayGetWifiListPage, arguments: { + 'macAddress':device.device.remoteId.str + }); + } else{ dismissEasyLoading(); } }, isAddEquipment: true); diff --git a/lib/mine/gateway/addGateway/selectGateway/selectGatewayList_page.dart b/lib/mine/gateway/addGateway/selectGateway/selectGatewayList_page.dart index 59ec1187..9db9e8f3 100755 --- a/lib/mine/gateway/addGateway/selectGateway/selectGatewayList_page.dart +++ b/lib/mine/gateway/addGateway/selectGateway/selectGatewayList_page.dart @@ -1,12 +1,15 @@ +import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/tools/noData.dart'; import '../../../../appRouters.dart'; import '../../../../app_settings/app_colors.dart'; +import '../../../../tools/appRouteObserver.dart'; import '../../../../tools/titleAppBar.dart'; import 'selectGatewayList_logic.dart'; import 'selectGatewayList_state.dart'; @@ -18,7 +21,7 @@ class SelectGatewayListPage extends StatefulWidget { State createState() => _SelectGatewayListPageState(); } -class _SelectGatewayListPageState extends State { +class _SelectGatewayListPageState extends State with RouteAware { final SelectGatewayListLogic logic = Get.put(SelectGatewayListLogic()); final SelectGatewayListState state = Get.find().state; @@ -29,7 +32,14 @@ class _SelectGatewayListPageState extends State { appBar: TitleAppBar( barTitle: '选择网关'.tr, haveBack: true, - backgroundColor: AppColors.mainColor), + backgroundColor: AppColors.mainColor, + actionsList: [ + CupertinoActivityIndicator( + radius: 18.w, + color: AppColors.whiteColor, + ), + SizedBox(width: 30.w) + ]), body: // ListView.builder( // itemCount: 10, @@ -43,15 +53,14 @@ class _SelectGatewayListPageState extends State { // }); // }) Obx(() => - state.devices.isNotEmpty? ListView.builder( itemCount: state.devices.length, itemBuilder: (BuildContext c, int index) { final ScanResult device = state.devices[index]; return _selectGatewayListListItem(device, () { - logic.connect(device.advertisementData.advName); + logic.connect(device); }); - }):NoData() + }) ), ); } @@ -131,4 +140,53 @@ class _SelectGatewayListPageState extends State { ), ); } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + + /// 路由订阅 + AppRouteObserver().routeObserver.subscribe(this, ModalRoute.of(context)!); + } + + @override + void dispose() { + /// 取消路由订阅 + AppRouteObserver().routeObserver.unsubscribe(this); + super.dispose(); + } + + /// 从上级界面进入 当前界面即将出现 + @override + void didPush() { + super.didPush(); + } + + /// 返回上一个界面 当前界面即将消失 + @override + void didPop() { + super.didPop(); + + EasyLoading.isShow ? EasyLoading.dismiss() : null; + logic.cancelBlueConnetctToastTimer(); + logic.blueDisconnect(); + logic.stopScanBlueList(); + } + + /// 从下级返回 当前界面即将出现 + @override + void didPopNext() { + super.didPopNext(); + logic.blueDisconnect(); + logic.startScanBlueList(); + } + + /// 进入下级界面 当前界面即将消失 + @override + void didPushNext() { + super.didPushNext(); + logic.cancelBlueConnetctToastTimer(); + logic.stopScanBlueList(); + } } + diff --git a/lib/mine/gateway/gatewayDetail/gatewayDetail_logic.dart b/lib/mine/gateway/gatewayDetail/gatewayDetail_logic.dart new file mode 100644 index 00000000..37f4c8d4 --- /dev/null +++ b/lib/mine/gateway/gatewayDetail/gatewayDetail_logic.dart @@ -0,0 +1,23 @@ + +import 'package:get/get.dart'; +import 'package:star_lock/tools/baseGetXController.dart'; + +import '../../../login/login/entity/LoginEntity.dart'; +import '../../../network/api_repository.dart'; +import 'gatewayDetail_state.dart'; + +class GatewayDetailLogic extends BaseGetXController{ + GatewayDetailState state = GatewayDetailState(); + + Future deletGateway() async{ + final LoginEntity entity = await ApiRepository.to.gatewayDelet( + gatewayId: state.getewayItemData.value.gatewayId ?? 0, + ); + if(entity.errorCode!.codeIsSuccessful){ + showToast('删除成功'.tr, something:(){ + // eventBus.fire(PassCurrentLockInformationEvent(state.lockSetInfoData.value)); + Get.back(); + }); + } + } +} \ No newline at end of file diff --git a/lib/mine/gateway/gatewayDetail/gatewayDetail_page.dart b/lib/mine/gateway/gatewayDetail/gatewayDetail_page.dart index 18f8d43b..0347af5c 100755 --- a/lib/mine/gateway/gatewayDetail/gatewayDetail_page.dart +++ b/lib/mine/gateway/gatewayDetail/gatewayDetail_page.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; @@ -7,8 +8,11 @@ import '../../../appRouters.dart'; import '../../../app_settings/app_colors.dart'; import '../../../tools/commonItem.dart'; import '../../../tools/showTFView.dart'; +import '../../../tools/showTipView.dart'; import '../../../tools/submitBtn.dart'; import '../../../tools/titleAppBar.dart'; +import 'gatewayDetail_logic.dart'; +import 'gatewayDetail_state.dart'; class GatewayDetailPage extends StatefulWidget { const GatewayDetailPage({Key? key}) : super(key: key); @@ -18,8 +22,9 @@ class GatewayDetailPage extends StatefulWidget { } class _GatewayDetailPageState extends State { - final TextEditingController _changeGatewayNameController = TextEditingController(); - + final GatewayDetailLogic logic = Get.put(GatewayDetailLogic()); + final GatewayDetailState state = Get.find().state; + @override Widget build(BuildContext context) { return Scaffold( @@ -28,29 +33,43 @@ class _GatewayDetailPageState extends State { barTitle: '网关'.tr, haveBack: true, backgroundColor: AppColors.mainColor), - body: ListView( + body: Obx(() => ListView( children: [ CommonItem( leftTitel: '名称'.tr, - rightTitle: '星锁网关', + rightTitle: state.getewayItemData.value.gatewayName, isHaveLine: true, isHaveDirection: true, action: () { - showCupertinoAlertDialog(context); + ShowTipView().showTFViewAlertDialog( + state.changeGatewayNameController, + '请输入姓名'.tr, + '', () { + if (state.changeGatewayNameController.text.isEmpty) { + logic.showToast('请输入姓名'.tr); + return; + } + // Get.back(); + // state.typeName.value = state.changeNameController.text; + // logic.editICCardData(); + }, inputFormatters: [ + FilteringTextInputFormatter.deny('\n'), + LengthLimitingTextInputFormatter(50), + ]); }), CommonItem( leftTitel: '状态'.tr, - rightTitle: '在线', + rightTitle: state.getewayItemData.value.isOnline == 1 ? '在线' : '离线', isHaveLine: true, isHaveDirection: false), CommonItem( leftTitel: 'WiFi名称'.tr, - rightTitle: 'XinHongJia', + rightTitle: state.getewayItemData.value.networkName, isHaveLine: true, isHaveDirection: false), CommonItem( leftTitel: '网络MAC'.tr, - rightTitle: '39:23:df:34:12', + rightTitle: state.getewayItemData.value.networkMac, isHaveLine: false, isHaveDirection: false), SizedBox( @@ -58,7 +77,7 @@ class _GatewayDetailPageState extends State { ), CommonItem( leftTitel: '附近的锁'.tr, - rightTitle: '2', + rightTitle: state.getewayItemData.value.lockNum.toString(), isHaveLine: true, isHaveDirection: true, action: () { @@ -80,21 +99,11 @@ class _GatewayDetailPageState extends State { fontSize: 32.sp, margin: EdgeInsets.only(left: 30.w, right: 30.w), padding: EdgeInsets.only(top: 15.w, bottom: 15.w), - onClick: () {}), + onClick: () { + ShowTipView().showIosTipWithContentDialog('确定要删除吗?'.tr, logic.deletGateway); + }), ], - ), + )), ); } - - // 修改名字 - void showCupertinoAlertDialog(BuildContext context) { - showDialog( - context: context, - builder: (BuildContext context) { - return ShowTFView( - title: '修改姓名'.tr, - tipTitle: '请输入'.tr, - controller: _changeGatewayNameController); - }); - } } diff --git a/lib/mine/gateway/gatewayDetail/gatewayDetail_state.dart b/lib/mine/gateway/gatewayDetail/gatewayDetail_state.dart new file mode 100644 index 00000000..0cdfbf81 --- /dev/null +++ b/lib/mine/gateway/gatewayDetail/gatewayDetail_state.dart @@ -0,0 +1,18 @@ + +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; + +import '../../mineSet/transferGateway/selectGetewayList_entity.dart'; + +class GatewayDetailState{ + GatewayDetailState() { + var map = Get.arguments; + if (map['getewayItemData'] != null && map['getewayItemData'] != '') { + getewayItemData.value = map['getewayItemData']; + } + } + + Rx getewayItemData = GetewayItemData().obs; + + final TextEditingController changeGatewayNameController = TextEditingController(); +} \ No newline at end of file diff --git a/lib/mine/gateway/gatewayList/gatewayList_page.dart b/lib/mine/gateway/gatewayList/gatewayList_page.dart index 70bca656..be80b767 100755 --- a/lib/mine/gateway/gatewayList/gatewayList_page.dart +++ b/lib/mine/gateway/gatewayList/gatewayList_page.dart @@ -1,9 +1,11 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import 'package:star_lock/tools/noData.dart'; import '../../../appRouters.dart'; import '../../../app_settings/app_colors.dart'; +import '../../../tools/EasyRefreshTool.dart'; import '../../../tools/storage.dart'; import '../../../tools/titleAppBar.dart'; import '../../mineSet/transferGateway/selectGetewayList_entity.dart'; @@ -50,7 +52,7 @@ class _GatewayListPageState extends State { actionsList: [ GestureDetector( onTap: () { - Get.toNamed(Routers.selectGatewayTypeNextTipPage); + Get.toNamed(Routers.selectGatewayTypeNextTipPage)!.then((value) => getHttpData(isRefresh: true)); }, child: Image.asset( 'images/icon_add_white.png', @@ -62,23 +64,32 @@ class _GatewayListPageState extends State { ), ], ), - body: ListView.separated( - itemCount: state.getewayListData.length, - itemBuilder: (BuildContext c, int index) { - final GetewayItemData item = state.getewayListData[index]; - return _gatewatListItem(item, () { - Get.toNamed(Routers.gatewayDetailPage); - }); - }, - separatorBuilder: (BuildContext context, int index) { - return Divider( - height: 1, - color: AppColors.greyLineColor, - indent: 20.w, - endIndent: 0, - ); - }, - ), + body: EasyRefreshTool( + onRefresh: () { + getHttpData(isRefresh: true); + }, + onLoad: () { + getHttpData(isRefresh: false); + }, + child: state.getewayListData.isNotEmpty ?ListView.separated( + itemCount: state.getewayListData.length, + itemBuilder: (BuildContext c, int index) { + final GetewayItemData item = state.getewayListData[index]; + return _gatewatListItem(item, () { + Get.toNamed(Routers.gatewayDetailPage, arguments: { + 'getewayItemData': item + })!.then((value) => getHttpData(isRefresh: true)); + }); + }, + separatorBuilder: (BuildContext context, int index) { + return Divider( + height: 1, + color: AppColors.greyLineColor, + indent: 20.w, + endIndent: 0, + ); + }, + ):NoData()), ); } diff --git a/lib/network/api.dart b/lib/network/api.dart index 080fdabc..4ca99134 100755 --- a/lib/network/api.dart +++ b/lib/network/api.dart @@ -148,7 +148,9 @@ abstract class Api { final String transferLockURL = '/room/transfer'; // 转移智能锁 final String removeBadLockURL = '/lock/removeBadLock'; // 移除坏锁 - final String gatewaykListURL = '/gateway/list'; // 转网关列表 + final String gatewaykListURL = '/gateway/list'; // 网关列表 + final String addGatewayURL = '/gateway/add'; // 添加网关 + final String deletGatewayURL = '/gateway/delete'; // 删除网关 final String transferGatewayConfirmURL = '/plug/transferPlugConfirm'; // 转移网关确认 final String transferGatewayURL = '/plug/transfer'; // 转移网关 diff --git a/lib/network/api_provider.dart b/lib/network/api_provider.dart index 38e6b439..eafda028 100755 --- a/lib/network/api_provider.dart +++ b/lib/network/api_provider.dart @@ -1720,6 +1720,36 @@ class ApiProvider extends BaseProvider { gatewaykListURL.toUrl, jsonEncode({'pageNo': pageNo, 'pageSize': pageSize})); + // 添加网关 + Future addGatewayNetwork( + String gatewayName, + String gatewayMac, + String serialNumber, + int gatewayType, + String networkName, + String networkMac, + String version, + ) => post( + addGatewayURL.toUrl, + jsonEncode({ + 'gatewayName': gatewayName, + 'gatewayMac': gatewayMac, + 'serialNumber': serialNumber, + 'gatewayType': gatewayType, + 'networkName': networkName, + 'networkMac': networkMac, + 'version': version, + })); + + // 删除网关 + Future deletGateway( + int gatewayId, + ) => post( + deletGatewayURL.toUrl, + jsonEncode({ + 'gatewayId': gatewayId, + })); + // 转移网关确认 Future transferGatewayConfirmInfoData( String receiverUsername, String type, String countryCode) => diff --git a/lib/network/api_repository.dart b/lib/network/api_repository.dart index 3fcd3aed..b3f34a41 100755 --- a/lib/network/api_repository.dart +++ b/lib/network/api_repository.dart @@ -1903,6 +1903,28 @@ class ApiRepository { return GetewayDataEntity.fromJson(res.body); } + // 添加网关 + Future gatewayDistributionNetwork({ + required String gatewayName, + required String gatewayMac, + required String serialNumber, + required int gatewayType, + required String networkName, + required String networkMac, + required String version, + }) async { + final res = await apiProvider.addGatewayNetwork(gatewayName, gatewayMac, serialNumber, gatewayType, networkName, networkMac, version); + return LoginEntity.fromJson(res.body); + } + + // 删除网关 + Future gatewayDelet({ + required int gatewayId, + }) async { + final res = await apiProvider.deletGateway(gatewayId); + return LoginEntity.fromJson(res.body); + } + // 转移网关确认 Future transferGatewayConfirmInfoData( {required String receiverUsername, diff --git a/pubspec.yaml b/pubspec.yaml index 31cd0c60..d3179731 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -91,8 +91,9 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # 1.0.78+2024082701:测试国际化功能 # 1.0.79+2024083001:测试所有国家国际化功能 # 1.0.79+2024083001:测试开完锁数据上传功能 +# 1.0.80+2024091901:添加网关功能给谢敬调试 -version: 1.0.79+2024090201 +version: 1.0.80+2024091901 environment: sdk: '>=2.12.0 <3.0.0'