From 28554dd0e48d5054d3ba82e1a734681011837ad8 Mon Sep 17 00:00:00 2001 From: Daisy <> Date: Mon, 8 Apr 2024 11:01:24 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=8C=E6=96=B0=E5=A2=9E=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=9D=A2=E5=AE=B9=E5=BC=80=E9=94=81=E6=8E=A5=E5=8F=A3=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5=202=EF=BC=8C=E6=96=B0=E5=A2=9E=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E9=9D=A2=E5=AE=B9=E6=84=9F=E5=BA=94=E8=B7=9D=E7=A6=BB=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=AF=B9=E6=8E=A5=203=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=9D=A2=E5=AE=B9=E9=98=B2=E8=AF=AF=E5=BC=80?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AF=B9=E6=8E=A5=204=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=AE=BE=E7=BD=AE=E9=9D=A2=E5=AE=B9=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E4=BA=AE=E5=B1=8F=E6=8E=A5=E5=8F=A3=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../catEyeSet/videoSlot/videoSlot_logic.dart | 3 - .../lockSet/faceUnlock/faceUnlock_logic.dart | 67 ++++++++++ .../lockSet/faceUnlock/faceUnlock_page.dart | 120 ++++++++++-------- .../lockSet/faceUnlock/faceUnlock_state.dart | 35 ++++- .../lockSet/lockSet/lockSet_page.dart | 4 +- star_lock/lib/network/api_provider.dart | 5 +- star_lock/lib/network/api_repository.dart | 6 +- 7 files changed, 174 insertions(+), 66 deletions(-) diff --git a/star_lock/lib/main/lockDetail/lockSet/catEyeSet/videoSlot/videoSlot_logic.dart b/star_lock/lib/main/lockDetail/lockSet/catEyeSet/videoSlot/videoSlot_logic.dart index 6465697b..e746a4f5 100644 --- a/star_lock/lib/main/lockDetail/lockSet/catEyeSet/videoSlot/videoSlot_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/catEyeSet/videoSlot/videoSlot_logic.dart @@ -51,9 +51,6 @@ class VideoSlotLogic extends BaseGetXController { .add(const Duration(days: 1)); // 获取明天时间的时间戳 state.recordEndTime.value = tomorrow.millisecondsSinceEpoch; - - // state.recordEndTime.value = - // DateTool().dateToTimestamp(state.endDate.value, 0); } var entity = await ApiRepository.to.updateCatEyeModeConfig( lockId: state.lockSetInfoData.value.lockId!, diff --git a/star_lock/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_logic.dart b/star_lock/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_logic.dart index 05fe5acf..a8acd635 100644 --- a/star_lock/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_logic.dart +++ b/star_lock/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_logic.dart @@ -1,6 +1,73 @@ import 'package:star_lock/main/lockDetail/lockSet/faceUnlock/faceUnlock_state.dart'; +import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart'; +import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/tools/baseGetXController.dart'; class FaceUnlockLogic extends BaseGetXController { final FaceUnlockState state = FaceUnlockState(); + + // 获取锁设置信息 + Future getLockSettingInfoData() async { + LockSetInfoEntity entity = await ApiRepository.to.getLockSettingInfoData( + lockId: state.lockSetInfoData.value.lockId.toString(), + ); + if (entity.errorCode!.codeIsSuccessful) { + state.lockSetInfoData.value = entity.data!; + state.faceOn.value = + entity.data!.lockSettingInfo!.faceSwitch == 0 ? false : true; + state.autoBright.value = + entity.data!.lockSettingInfo!.faceAutoLightScreen == 0 ? false : true; + state.senseDistance.value = + entity.data!.lockSettingInfo!.faceInductionDistance! == 0 + ? '远距离' + : '近距离'; + state.antiMisoperation.value = + entity.data!.lockSettingInfo!.faceAntiMistakeOpen!; + } + return entity; + } + + //设置面容开锁开关 + void updateFaceSwitch() async { + var entity = await ApiRepository.to.updateFaceSwitch( + lockId: state.lockSetInfoData.value.lockId ?? 0, + faceSwitch: state.faceOn.value == false ? 0 : 1, + ); + if (entity.errorCode!.codeIsSuccessful) { + showToast('设置成功'); + } + } + + //设置自动亮屏开关 + void updateFaceConfig() async { + var entity = await ApiRepository.to.updateFaceAutoLightScreen( + lockId: state.lockSetInfoData.value.lockId ?? 0, + faceAutoLightScreen: state.autoBright.value == false ? 0 : 1, + ); + if (entity.errorCode!.codeIsSuccessful) { + showToast('设置成功'); + } + } + + //设置面容感应距离 + void updateFaceSenseDistance() async { + var entity = await ApiRepository.to.updateFaceSenseDistance( + lockId: state.lockSetInfoData.value.lockId ?? 0, + faceInductionDistance: state.senseDistance.value == '远距离' ? 0 : 1, + ); + if (entity.errorCode!.codeIsSuccessful) { + showToast('设置成功'); + } + } + + //设置面容防误开 + void updateFacePreventMisrun() async { + var entity = await ApiRepository.to.updateFacePreventMisrun( + lockId: state.lockSetInfoData.value.lockId ?? 0, + faceAntiMistakeOpen: state.antiMisoperation.value, + ); + if (entity.errorCode!.codeIsSuccessful) { + showToast('设置成功'); + } + } } diff --git a/star_lock/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_page.dart b/star_lock/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_page.dart index 7732de2b..63803c7f 100644 --- a/star_lock/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_page.dart +++ b/star_lock/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_page.dart @@ -21,6 +21,12 @@ class _FaceUnlockPageState extends State { final logic = Get.put(FaceUnlockLogic()); final state = Get.find().state; + @override + void initState() { + super.initState(); + logic.getLockSettingInfoData(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -29,45 +35,57 @@ class _FaceUnlockPageState extends State { barTitle: TranslationLoader.lanKeys!.faceUnlocksSet!.tr, haveBack: true, backgroundColor: AppColors.mainColor), - body: Column( - children: [ - CommonItem( - leftTitel: TranslationLoader.lanKeys!.faceUnlocks!.tr, - rightTitle: "", - allHeight: 70.h, - isHaveLine: true, - isHaveRightWidget: true, - rightWidget: - SizedBox(width: 60.w, height: 50.h, child: _switch(1))), - CommonItem( - leftTitel: TranslationLoader.lanKeys!.automaticBrighteningScreen!.tr, - rightTitle: "", - isHaveLine: true, - isHaveRightWidget: true, - rightWidget: - SizedBox(width: 60.w, height: 50.h, child: _switch(2))), - _buildSubTitleItem( - TranslationLoader.lanKeys!.sensingDistance!.tr, TranslationLoader.lanKeys!.sensingDistanceTip!.tr, state.senseDistance.value, - () { - _openBottomItemSheet(state.senseDistanceList.value, 0); - }), - SizedBox( - height: 30.h, - ), - _buildSubTitleItem( - TranslationLoader.lanKeys!.preventWrongOpening!.tr, TranslationLoader.lanKeys!.preventWrongOpeningTip!.tr, state.antiMisoperation.value, () { - _openBottomItemSheet(state.antiMisoperationList.value, 1); - }), - Expanded( - child: SizedBox( - height: 30.h, - )), - _buildTipsView(), - SizedBox( - height: 60.h, - ) - ], - )); + body: Obx(() => Column( + children: [ + Container( + margin: EdgeInsets.only(left: 20.w), + child: CommonItem( + leftTitel: TranslationLoader.lanKeys!.faceUnlocks!.tr, + rightTitle: "", + allHeight: 70.h, + isHaveLine: true, + isHaveRightWidget: true, + rightWidget: SizedBox( + width: 60.w, height: 50.h, child: _switch(1))), + ), + Container( + margin: EdgeInsets.only(left: 20.w), + child: CommonItem( + leftTitel: TranslationLoader + .lanKeys!.automaticBrighteningScreen!.tr, + rightTitle: "", + isHaveLine: true, + isHaveRightWidget: true, + rightWidget: SizedBox( + width: 60.w, height: 50.h, child: _switch(2))), + ), + _buildSubTitleItem( + TranslationLoader.lanKeys!.sensingDistance!.tr, + TranslationLoader.lanKeys!.sensingDistanceTip!.tr, + state.senseDistance.value, () { + _openBottomItemSheet(state.senseDistanceList.value, 0); + }), + SizedBox( + height: 30.h, + ), + _buildSubTitleItem( + TranslationLoader.lanKeys!.preventWrongOpening!.tr, + TranslationLoader.lanKeys!.preventWrongOpeningTip!.tr, + state.antiMisoperation.value == 0 + ? '关闭' + : '${state.antiMisoperation.value}秒', () { + _openBottomItemSheet(state.antiMisoperationStrList.value, 1); + }), + Expanded( + child: SizedBox( + height: 30.h, + )), + _buildTipsView(), + SizedBox( + height: 60.h, + ) + ], + ))); } Widget _buildSubTitleItem( @@ -76,6 +94,7 @@ class _FaceUnlockPageState extends State { onTap: action, child: Container( margin: EdgeInsets.only(left: 20.sp, right: 20.sp, top: 20.h), + color: Colors.white, child: Row( mainAxisAlignment: MainAxisAlignment.start, children: [ @@ -152,19 +171,20 @@ class _FaceUnlockPageState extends State { thumbColor: CupertinoColors.white, value: getIndex == 1 ? state.faceOn.value : state.autoBright.value, onChanged: (value) { - setState(() { - if (getIndex == 1) { - state.faceOn.value = value; - } else { - state.autoBright.value = value; - } - }); + if (getIndex == 1) { + //设置面容开锁开关 + state.faceOn.value = value; + logic.updateFaceSwitch(); + } else { + //设置自动亮屏开关 + state.autoBright.value = value; + logic.updateFaceConfig(); + } }, ); } - Future _openBottomItemSheet( - List bottomItemList, int clickIndex) async { + Future _openBottomItemSheet(List bottomItemList, int clickIndex) async { showModalBottomSheet( context: context, shape: RoundedRectangleBorder( @@ -178,13 +198,13 @@ class _FaceUnlockPageState extends State { //感应距离 state.senseDistance.value = state.senseDistanceList.value[value]; + logic.updateFaceSenseDistance(); } else if (clickIndex == 1) { //防误开 state.antiMisoperation.value = state.antiMisoperationList.value[value]; + logic.updateFacePreventMisrun(); } - - setState(() {}); }, ); }); diff --git a/star_lock/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_state.dart b/star_lock/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_state.dart index 4b17e17f..e62267d1 100644 --- a/star_lock/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_state.dart +++ b/star_lock/lib/main/lockDetail/lockSet/faceUnlock/faceUnlock_state.dart @@ -1,20 +1,32 @@ -import 'dart:ui'; - import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/app_settings/app_colors.dart'; +import 'package:star_lock/main/lockDetail/lockSet/lockSet/lockSetInfo_entity.dart'; import '../../../../translations/trans_lib.dart'; class FaceUnlockState { + var lockSetInfoData = LockSetInfoData().obs; + var isCheck = false.obs; var faceOn = false.obs; //面容开锁 var autoBright = false.obs; //自动亮屏 var senseDistance = TranslationLoader.lanKeys!.remote!.tr.obs; //感应距离 - var antiMisoperation = TranslationLoader.lanKeys!.close!.tr.obs; //防误开 - var senseDistanceList = [TranslationLoader.lanKeys!.remote!.tr, TranslationLoader.lanKeys!.closeRange!.tr].obs; - var antiMisoperationList = [TranslationLoader.lanKeys!.close!.tr, '5${TranslationLoader.lanKeys!.second!.tr}', '10${TranslationLoader.lanKeys!.second!.tr}', '15${TranslationLoader.lanKeys!.second!.tr}', '30${TranslationLoader.lanKeys!.second!.tr}', '60${TranslationLoader.lanKeys!.second!.tr}'].obs; + var antiMisoperation = 0.obs; //防误开 + var senseDistanceList = [ + TranslationLoader.lanKeys!.remote!.tr, + TranslationLoader.lanKeys!.closeRange!.tr + ].obs; + var antiMisoperationList = [0, 5, 10, 15, 30, 60].obs; + var antiMisoperationStrList = [ + TranslationLoader.lanKeys!.close!.tr, + '5${TranslationLoader.lanKeys!.second!.tr}', + '10${TranslationLoader.lanKeys!.second!.tr}', + '15${TranslationLoader.lanKeys!.second!.tr}', + '30${TranslationLoader.lanKeys!.second!.tr}', + '60${TranslationLoader.lanKeys!.second!.tr}' + ].obs; //高亮样式 final TextStyle titleStyle = TextStyle( color: Colors.black, fontSize: 24.sp, fontWeight: FontWeight.w500); @@ -23,9 +35,18 @@ class FaceUnlockState { TextStyle(color: AppColors.placeholderTextColor, fontSize: 22.sp); late InlineSpan tipsPreviewSpan = TextSpan(children: [ - TextSpan(text: '${TranslationLoader.lanKeys!.addAndUseFaceWhenUnlocking!.tr}:\n', style: titleStyle), TextSpan( - text:TranslationLoader.lanKeys!.addAndUseFaceWhenUnlockingTip!.tr, + text: '${TranslationLoader.lanKeys!.addAndUseFaceWhenUnlocking!.tr}:\n', + style: titleStyle), + TextSpan( + text: TranslationLoader.lanKeys!.addAndUseFaceWhenUnlockingTip!.tr, style: subTipsStyle), ]); + + FaceUnlockState() { + Map map = Get.arguments; + if (map['lockSetInfoData'] != null) { + lockSetInfoData.value = map['lockSetInfoData']; + } + } } diff --git a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart index 56415d4c..f923f88d 100644 --- a/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart +++ b/star_lock/lib/main/lockDetail/lockSet/lockSet/lockSet_page.dart @@ -357,7 +357,9 @@ class _LockSetPageState extends State with RouteAware { isHaveLine: true, isHaveDirection: true, action: () { - Get.toNamed(Routers.faceUnlockPage); + Get.toNamed(Routers.faceUnlockPage, arguments: { + 'lockSetInfoData': state.lockSetInfoData.value + }); })), // ), // 消息提醒 diff --git a/star_lock/lib/network/api_provider.dart b/star_lock/lib/network/api_provider.dart index eaf7c499..fb4b5f74 100644 --- a/star_lock/lib/network/api_provider.dart +++ b/star_lock/lib/network/api_provider.dart @@ -1718,8 +1718,9 @@ class ApiProvider extends BaseProvider { 'faceSwitch': faceSwitch, })); - // 设置面容开锁 - Future updateFaceConfig(int lockId, int faceInductionDistance) => + // 设置面容感应距离 + Future updateFaceSenseDistance( + int lockId, int faceInductionDistance) => post( updateFaceConfigURL.toUrl, jsonEncode({ diff --git a/star_lock/lib/network/api_repository.dart b/star_lock/lib/network/api_repository.dart index b96dcbbb..1c8b799e 100644 --- a/star_lock/lib/network/api_repository.dart +++ b/star_lock/lib/network/api_repository.dart @@ -1757,10 +1757,10 @@ class ApiRepository { } // 设置面容感应距离 - Future updateFaceConfig( + Future updateFaceSenseDistance( {required int lockId, required int faceInductionDistance}) async { - final res = - await apiProvider.updateFaceConfig(lockId, faceInductionDistance); + final res = await apiProvider.updateFaceSenseDistance( + lockId, faceInductionDistance); return VersionUndateEntity.fromJson(res.body); }