diff --git a/images/lan/lan_en.json b/images/lan/lan_en.json index d2f6f144..1e08ee34 100755 --- a/images/lan/lan_en.json +++ b/images/lan/lan_en.json @@ -856,5 +856,6 @@ "视频事件":"Video event", "请开启蓝牙":"Please turn on Bluetooth", "请选择有效日":"Please select the effective day", - "公司名字长度不能小于 6 ": "The length of the company name cannot be less than 6" + "公司名字长度不能小于 6 ": "The length of the company name cannot be less than 6", + "已是最新版本": "It is the latest version" } diff --git a/images/lan/lan_keys.json b/images/lan/lan_keys.json index d293e3b9..67174980 100755 --- a/images/lan/lan_keys.json +++ b/images/lan/lan_keys.json @@ -885,5 +885,6 @@ "视频事件":"视频事件", "请开启蓝牙":"请开启蓝牙", "请选择有效日":"请选择有效日", - "公司名字长度不能小于 6 ": "公司名字长度不能小于 6 " + "公司名字长度不能小于 6 ": "公司名字长度不能小于 6 ", + "已是最新版本": "已是最新版本" } diff --git a/images/lan/lan_zh.json b/images/lan/lan_zh.json index 5e3192e1..bd48b813 100755 --- a/images/lan/lan_zh.json +++ b/images/lan/lan_zh.json @@ -855,5 +855,6 @@ "视频事件": "视频事件", "请开启蓝牙": "请开启蓝牙", "请选择有效日": "请选择有效日", - "公司名字长度不能小于 6 ": "公司名字长度不能小于 6 " + "公司名字长度不能小于 6 ": "公司名字长度不能小于 6 ", + "已是最新版本": "已是最新版本" } diff --git a/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_logic.dart b/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_logic.dart index e1850e7a..4a34e67a 100755 --- a/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_logic.dart +++ b/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_logic.dart @@ -8,15 +8,15 @@ import 'package:file_picker/file_picker.dart'; import 'package:flutter_blue_plus/flutter_blue_plus.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:get/get.dart'; -import 'package:permission_handler/permission_handler.dart'; +import 'package:http/http.dart' as http; import 'package:star_lock/blue/blue_manage.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_reply.dart'; import 'package:star_lock/blue/io_tool/io_tool.dart'; import 'package:star_lock/blue/io_tool/manager_event_bus.dart'; -import 'package:star_lock/blue/sender_manage.dart'; -import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSet_logic.dart'; +import 'package:star_lock/main/lockDetail/lockSet/lockEscalation/version_entity.dart'; +import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import 'package:star_lock/tools/commonDataManage.dart'; import 'package:star_lock/tools/showTipView.dart'; @@ -34,17 +34,8 @@ class LockEscalationLogic extends BaseGetXController { int otaIndex = 0; Uint8List? otaBin; int startSecond = 0; - Map? headJson = null; - - // 锁升级 - Future setLockSetGeneralSetting() async { - // var entity = await ApiRepository.to.getLockVersionInfoData( - // lockId: state.getKeyInfosData.value.lockId.toString(), - // ); - // if(entity.errorCode!.codeIsSuccessful){ - // - // } - } + Map? headJson; + FwVersionEntity? entity; //手动升级 Future otaUpdate() async { @@ -58,6 +49,10 @@ class LockEscalationLogic extends BaseGetXController { } final File file = File(result.files.single.path!); final Uint8List data = await file.readAsBytes(); + stateUpData(data); + } + + Future stateUpData(Uint8List data) async { headJson = await getHeadFile(data); if (headJson is! Map) { return; @@ -69,10 +64,10 @@ class LockEscalationLogic extends BaseGetXController { final String md5Str = md5.convert(otaBin!).toString(); headJson!['fwMd5'] = md5Str; ShowTipView().showIosTipWithContentDialog('未避免异常情况,请在门打开时升级'.tr, () async { - blueOTAUpgrade(headJson!, [0, 0, 0, 0]); + blueOTAUpgrade(headJson!, [0, 0, 0, 0]); EasyLoading.show( status: '设备连接中...'.tr, maskType: EasyLoadingMaskType.black); - Future.delayed(const Duration(seconds: 4), EasyLoading.dismiss); + Future.delayed(const Duration(seconds: 4), EasyLoading.dismiss); }); } @@ -81,9 +76,12 @@ class LockEscalationLogic extends BaseGetXController { BlueManage().blueSendData(BlueManage().connectDeviceName, (BluetoothConnectionState deviceConnectionState) async { if (deviceConnectionState == BluetoothConnectionState.connected) { - final privateKey = await Storage.getStringList(saveBluePrivateKey); - final List getPrivateKeyList = changeStringListToIntList(privateKey!); - final signKey = await Storage.getStringList(saveBlueSignKey); + final List? privateKey = + await Storage.getStringList(saveBluePrivateKey); + final List getPrivateKeyList = + changeStringListToIntList(privateKey!); + final List? signKey = + await Storage.getStringList(saveBlueSignKey); final List signKeyDataList = changeStringListToIntList(signKey!); final String uid = await Storage.getUid() ?? ''; BlueManage().writeCharacteristicWithResponse(OTAUpgradeCommand( @@ -236,17 +234,47 @@ class LockEscalationLogic extends BaseGetXController { return bin; } + //检查最新版本 + Future checkUpData() async { + final String model = CommonDataManage().currentKeyInfo.model ?? ''; + String currentVersion = CommonDataManage().currentKeyInfo.fwVersion ?? ''; + if (currentVersion.split('.').length >= 3) { + currentVersion = currentVersion.split('.')[0] + + '.' + + currentVersion.split('.')[1] + + '.' + + currentVersion.split('.')[2]; + } + state.showVersion.value = currentVersion; + entity = await ApiRepository.to + .getFwVersion(model: model, currentVersion: currentVersion); + state.isShowUpDataBtn.value = entity?.data?.isUpdate == 1; + state.showNewVersion.value = entity?.data?.version??''; + } + + //下载升级 + Future downloadTheFile() async { + if (entity?.data?.downloadUrl == null) { + return; + } + final String url = entity!.data!.downloadUrl!; + final http.Response response = await http.get(Uri.parse(url)); + if (response.statusCode == 200) { + stateUpData(response.bodyBytes); + } + } + @override void onReady() { super.onReady(); - setLockSetGeneralSetting(); + checkUpData(); } @override void onInit() { super.onInit(); _replySubscription = - EventBusManager().eventBus!.on().listen((reply) { + EventBusManager().eventBus!.on().listen((Reply reply) { if (reply is OTAUpgradeReply) { if (reply.status == 0x00) { //验证通过,开始发送数据包 diff --git a/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_page.dart b/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_page.dart index e2dc59d7..949a7e3d 100755 --- a/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_page.dart +++ b/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_page.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import 'package:star_lock/tools/commonDataManage.dart'; import '../../../../app_settings/app_colors.dart'; import '../../../../tools/submitBtn.dart'; @@ -63,29 +64,46 @@ class _LockEscalationPageState extends State { SizedBox( width: 10.w, ), - Text( - // TranslationLoader.lanKeys!.haveNewVersion!.tr, - "未发现新版本", - style: TextStyle(fontSize: 24.sp, fontWeight: FontWeight.w600), - ) + Obx(() { + if (logic.state.isShowUpDataBtn.value) { + return Text( + TranslationLoader.lanKeys!.haveNewVersion!.tr + logic.state.showNewVersion.value, + style: + TextStyle(fontSize: 24.sp, fontWeight: FontWeight.w600), + ); + } else { + return Text( + '已是最新版本'.tr, + style: + TextStyle(fontSize: 24.sp, fontWeight: FontWeight.w600), + ); + } + }) ], ), SizedBox( height: 30.h, ), - Text( - "${TranslationLoader.lanKeys!.currentVersion!.tr}:1.0.0", - style: TextStyle(fontSize: 18.sp, color: AppColors.darkGrayTextColor), - ), + Obx(() { + return Text( + '${TranslationLoader.lanKeys!.currentVersion!.tr}:${logic.state.showVersion.value}', + style: + TextStyle(fontSize: 18.sp, color: AppColors.darkGrayTextColor), + ); + }), SizedBox( height: 40.h, ), Obx(() { - return !logic.state.otaUpdateIng.value + final bool show = !logic.state.otaUpdateIng.value && + logic.state.isShowUpDataBtn.value; + return show ? SubmitBtn( btnName: TranslationLoader.lanKeys!.upgrade!.tr, - onClick: () {}) - : SizedBox(); + onClick: () { + logic.downloadTheFile(); + }) + : const SizedBox(); }), SizedBox( height: 10.h, diff --git a/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_state.dart b/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_state.dart index a53bd383..a182c23a 100755 --- a/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_state.dart +++ b/lib/main/lockDetail/lockSet/lockEscalation/lockEscalation_state.dart @@ -1,6 +1,9 @@ import 'package:get/get.dart'; class LockEscalationState { - var otaUpdateIng = false.obs; - var otaProgress = 0.00.obs; + RxBool otaUpdateIng = false.obs; + RxDouble otaProgress = 0.00.obs; + RxBool isShowUpDataBtn = false.obs; + RxString showVersion = '1.0.0'.obs; + RxString showNewVersion = '1.0.0'.obs; } diff --git a/lib/main/lockDetail/lockSet/lockEscalation/version_entity.dart b/lib/main/lockDetail/lockSet/lockEscalation/version_entity.dart new file mode 100644 index 00000000..74e6d8e0 --- /dev/null +++ b/lib/main/lockDetail/lockSet/lockEscalation/version_entity.dart @@ -0,0 +1,48 @@ +class FwVersionEntity { + FwVersionEntity({this.errorCode, this.description, this.errorMsg, this.data}); + + FwVersionEntity.fromJson(Map json) { + errorCode = json['errorCode']; + description = json['description']; + errorMsg = json['errorMsg']; + if (json['data'] is Map) { + data = Data.fromJson(json['data']); + } + } + + int? errorCode; + String? description; + String? errorMsg; + Data? data; + + Map toJson() { + final Map data = {}; + data['errorCode'] = errorCode; + data['description'] = description; + data['errorMsg'] = errorMsg; + data['data'] = this.data; + return data; + } +} + +class Data { + Data.fromJson(Map json) { + isUpdate = json['isUpdate']; + downloadUrl = json['downloadUrl']; + description = json['description']; + } + + int? isUpdate; + String? downloadUrl; + String? description; + String? version; + + Map toJson() { + final Map data = {}; + data['isUpdate'] = isUpdate; + data['downloadUrl'] = downloadUrl; + data['description'] = description; + data['version'] = version; + return data; + } +} diff --git a/lib/network/api.dart b/lib/network/api.dart index 7901353e..af2786e3 100755 --- a/lib/network/api.dart +++ b/lib/network/api.dart @@ -240,4 +240,5 @@ abstract class Api { final String lockDataUploadUrl = '/lockRecords/lockDataUpload'; // 锁数据上传 final String getNoticeTemplateURL = '/key/getNoticeTemplate'; //获取短信或者邮箱模板 final String appGetAppInfoURL = '/app/getAppInfo'; //获取APP基本信息 + final String appGetFwVersionURL = '/app/getFwVersion'; //获取固件信息 } diff --git a/lib/network/api_provider.dart b/lib/network/api_provider.dart index 21bd6b91..0b6d352d 100755 --- a/lib/network/api_provider.dart +++ b/lib/network/api_provider.dart @@ -2127,6 +2127,17 @@ class ApiProvider extends BaseProvider { Future> getAppInfo() => post(appGetAppInfoURL.toUrl, jsonEncode({}), isShowErrMsg: false); + + // 获取App固件信息 + Future> getFwVersion(String model, String currentVersion) => + post( + appGetFwVersionURL.toUrl, + jsonEncode({ + 'model': model, + 'currentVersion': currentVersion, + }), + isUnShowLoading: true, + ); } extension ExtensionString on String { diff --git a/lib/network/api_repository.dart b/lib/network/api_repository.dart index 20f5f7ca..46b6202b 100755 --- a/lib/network/api_repository.dart +++ b/lib/network/api_repository.dart @@ -9,6 +9,7 @@ import 'package:star_lock/main/lockDetail/electronicKey/massSendElectronicKey/ma import 'package:star_lock/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendLockGroupListEntity.dart'; import 'package:star_lock/main/lockDetail/face/addFace/addFace_entity.dart'; import 'package:star_lock/main/lockDetail/lockSet/basicInformation/basicInformation/KeyDetailEntity.dart'; +import 'package:star_lock/main/lockDetail/lockSet/lockEscalation/version_entity.dart'; import 'package:star_lock/main/lockDetail/messageWarn/lockUser/lockUser_entity.dart'; import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/coerceOpenDoor/coerceFingerprintList/coerceFingerprintList_entity.dart'; import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart'; @@ -2154,8 +2155,15 @@ class ApiRepository { // 电子钥匙获取短信模板 Future getAppInfo() async { - final Response res = - await apiProvider.getAppInfo(); + final Response res = await apiProvider.getAppInfo(); return GetAppInfo.fromJson(res.body); } + + // 获取最新固件 + Future getFwVersion( + {required String model, required String currentVersion}) async { + final Response res = + await apiProvider.getFwVersion(model, currentVersion); + return FwVersionEntity.fromJson(res.body); + } }