From 3cfceece5b1fe7fac727ee49c1bd90a72f4fd273 Mon Sep 17 00:00:00 2001 From: Daisy <> Date: Tue, 12 Dec 2023 15:57:30 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=8F=91=E9=80=81?= =?UTF-8?q?=E7=94=B5=E5=AD=90=E9=92=A5=E5=8C=99=E5=8F=8A=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E9=83=A8=E5=88=86=E8=BE=93=E5=85=A5=E6=A1=86?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E9=97=AE=E9=A2=98=202=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=8F=91=E9=80=81=E7=94=B5=E5=AD=90=E9=92=A5=E5=8C=99?= =?UTF-8?q?-=E5=BE=AA=E7=8E=AF=E7=B1=BB=E5=9E=8B=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=8A=A5=E7=BA=A2=E9=97=AE=E9=A2=98=203=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E4=B8=8D=E8=83=BD=E7=BB=99=E9=82=AE=E7=AE=B1=E5=8F=91?= =?UTF-8?q?=E9=80=81=E7=94=B5=E5=AD=90=E9=92=A5=E5=8C=99=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../electronicKeyList_page.dart | 29 +- .../electronicKeyPeriodValidity_logic.dart | 7 + .../electronicKeyPeriodValidity_page.dart | 162 +++--- .../electronicKeyPeriodValidity_state.dart | 34 ++ .../sendElectronicKey_logic.dart | 104 +++- .../sendElectronicKey_page.dart | 12 +- .../passwordKeyList/passwordKeyList_page.dart | 29 +- .../passwordKey_perpetual_logic.dart | 132 +++++ .../passwordKey_perpetual_page.dart | 474 +++++++----------- .../passwordKey_perpetual_state.dart | 24 + 10 files changed, 599 insertions(+), 408 deletions(-) create mode 100644 star_lock/lib/main/lockDetail/electronicKey/electronicKeyPeriodValidity/electronicKeyPeriodValidity_logic.dart create mode 100644 star_lock/lib/main/lockDetail/electronicKey/electronicKeyPeriodValidity/electronicKeyPeriodValidity_state.dart create mode 100644 star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart diff --git a/star_lock/lib/main/lockDetail/electronicKey/electronicKeyList/electronicKeyList_page.dart b/star_lock/lib/main/lockDetail/electronicKey/electronicKeyList/electronicKeyList_page.dart index c779f6a4..04a90021 100644 --- a/star_lock/lib/main/lockDetail/electronicKey/electronicKeyList/electronicKeyList_page.dart +++ b/star_lock/lib/main/lockDetail/electronicKey/electronicKeyList/electronicKeyList_page.dart @@ -85,10 +85,11 @@ class _ElectronicKeyListPageState extends State { btnName: TranslationLoader.lanKeys!.sendKey!.tr, onClick: () { Navigator.pushNamed( - context, Routers.sendElectronicKeyManagePage, arguments: { - // "lockMainEntity": state.lockMainEntity.value, - "keyInfo": state.keyInfo.value - }).then((val) { + context, Routers.sendElectronicKeyManagePage, + arguments: { + // "lockMainEntity": state.lockMainEntity.value, + "keyInfo": state.keyInfo.value + }).then((val) { if (val != null) { logic.mockNetworkDataRequest(); setState(() {}); @@ -145,7 +146,7 @@ class _ElectronicKeyListPageState extends State { decoration: InputDecoration( //输入里面输入文字内边距设置 contentPadding: const EdgeInsets.only( - top: 12.0, left: -19.0, right: -15.0, bottom: 8.0), + top: 18.0, left: -19.0, right: -15.0, bottom: 2), hintText: TranslationLoader.lanKeys!.pleaseEnter!.tr, hintStyle: TextStyle(fontSize: 22.sp, height: 3.0), //不需要输入框下划线 @@ -161,6 +162,8 @@ class _ElectronicKeyListPageState extends State { ), ), ), + style: + TextStyle(fontSize: 22.sp, textBaseline: TextBaseline.alphabetic), ), ); } @@ -201,14 +204,14 @@ class _ElectronicKeyListPageState extends State { ), child: _electronicKeyItem('images/controls_user.png', indexEntity.keyName!, useDateStr, keyStatus, isAdminKey, () { - Navigator.pushNamed(context, Routers.electronicKeyDetailPage, - arguments: {"itemData": indexEntity}).then((val) { - if (val != null) { - logic.mockNetworkDataRequest(); - setState(() {}); - } - }); - }), + Navigator.pushNamed(context, Routers.electronicKeyDetailPage, + arguments: {"itemData": indexEntity}).then((val) { + if (val != null) { + logic.mockNetworkDataRequest(); + setState(() {}); + } + }); + }), ); } return const SizedBox.shrink(); diff --git a/star_lock/lib/main/lockDetail/electronicKey/electronicKeyPeriodValidity/electronicKeyPeriodValidity_logic.dart b/star_lock/lib/main/lockDetail/electronicKey/electronicKeyPeriodValidity/electronicKeyPeriodValidity_logic.dart new file mode 100644 index 00000000..858802a3 --- /dev/null +++ b/star_lock/lib/main/lockDetail/electronicKey/electronicKeyPeriodValidity/electronicKeyPeriodValidity_logic.dart @@ -0,0 +1,7 @@ +import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyPeriodValidity/electronicKeyPeriodValidity_state.dart'; +import 'package:star_lock/tools/baseGetXController.dart'; + +class ElectronicKeyPeriodValidityLogic extends BaseGetXController { + final ElectronicKeyPeriodValidityState state = + ElectronicKeyPeriodValidityState(); +} diff --git a/star_lock/lib/main/lockDetail/electronicKey/electronicKeyPeriodValidity/electronicKeyPeriodValidity_page.dart b/star_lock/lib/main/lockDetail/electronicKey/electronicKeyPeriodValidity/electronicKeyPeriodValidity_page.dart index 80666b96..f9faa8da 100644 --- a/star_lock/lib/main/lockDetail/electronicKey/electronicKeyPeriodValidity/electronicKeyPeriodValidity_page.dart +++ b/star_lock/lib/main/lockDetail/electronicKey/electronicKeyPeriodValidity/electronicKeyPeriodValidity_page.dart @@ -5,6 +5,8 @@ import 'package:flutter_pickers/time_picker/model/date_mode.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyPeriodValidity/KeyPeriodValidityModel.dart'; +import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyPeriodValidity/electronicKeyPeriodValidity_logic.dart'; +import 'package:star_lock/tools/toast.dart'; import '../../../../app_settings/app_colors.dart'; import '../../../../tools/commonItem.dart'; @@ -22,35 +24,38 @@ class ElectronicKeyPeriodValidityPage extends StatefulWidget { class _ElectronicKeyPeriodValidityPageState extends State { - List validityTextList = [ - TranslationLoader.lanKeys!.sundayShort!.tr, - TranslationLoader.lanKeys!.mondayShort!.tr, - TranslationLoader.lanKeys!.tuesdayShort!.tr, - TranslationLoader.lanKeys!.wednesdayShort!.tr, - TranslationLoader.lanKeys!.thursdayShort!.tr, - TranslationLoader.lanKeys!.fridayShort!.tr, - TranslationLoader.lanKeys!.saturdayShort!.tr - ]; - List validityDataList = []; //自定义数据块 - List selectIndexList = []; //选中的有效期数组 - String _selectEffectiveDate = ''; //生效时间 - String _selectFailureDate = ''; //失效时间 - late DateTime _effectiveDateTime; - late DateTime _failureDateTime; + final logic = Get.put(ElectronicKeyPeriodValidityLogic()); + final state = Get.find().state; + + // List validityTextList = [ + // TranslationLoader.lanKeys!.sundayShort!.tr, + // TranslationLoader.lanKeys!.mondayShort!.tr, + // TranslationLoader.lanKeys!.tuesdayShort!.tr, + // TranslationLoader.lanKeys!.wednesdayShort!.tr, + // TranslationLoader.lanKeys!.thursdayShort!.tr, + // TranslationLoader.lanKeys!.fridayShort!.tr, + // TranslationLoader.lanKeys!.saturdayShort!.tr + // ]; + // List validityDataList = []; //自定义数据块 + // List selectIndexList = []; //选中的有效期数组 + // String _selectEffectiveDate = ''; //生效时间 + // String _selectFailureDate = ''; //失效时间 + // late DateTime _effectiveDateTime; + // late DateTime _failureDateTime; @override void initState() { super.initState(); - for (var i = 0; i < validityTextList.length; i++) { + for (var i = 0; i < state.validityTextList.value.length; i++) { int validityValue = 0; if (i == 0) { validityValue = 7; } else { validityValue = i; } - KeyPeriodValidityModel model = - KeyPeriodValidityModel(validityTextList[i], i, false, validityValue); - validityDataList.add(model); + KeyPeriodValidityModel model = KeyPeriodValidityModel( + state.validityTextList.value[i], i, false, validityValue); + state.validityDataList.value.add(model); } } @@ -101,7 +106,8 @@ class _ElectronicKeyPeriodValidityPageState itemCount: 7, physics: const NeverScrollableScrollPhysics(), itemBuilder: (context, index) { - KeyPeriodValidityModel model = validityDataList[index]; + KeyPeriodValidityModel model = + state.validityDataList.value[index]; return btnItem(model); })) ], @@ -110,38 +116,40 @@ class _ElectronicKeyPeriodValidityPageState } Widget btnItem(KeyPeriodValidityModel model) { - return GestureDetector( - onTap: () { - model.isValidity = !model.isValidity; - if (model.isValidity) { - selectIndexList.add(model.validityValue); - } else { - selectIndexList.remove(model.validityValue); - } - setState(() {}); - }, - child: Container( - width: 40.w, - height: 40.w, - margin: EdgeInsets.all(10.w), - decoration: BoxDecoration( - color: selectIndexList.contains(model.validityValue) - ? Colors.blue - : Colors.white, - border: Border.all(width: 1, color: AppColors.greyBackgroundColor), - borderRadius: BorderRadius.circular(30.w), - ), - child: Center( - child: Text( - model.validityText, - style: TextStyle( - fontSize: 20.sp, - color: selectIndexList.contains(model.validityValue) - ? Colors.white - : AppColors.darkGrayTextColor), - )), - ), - ); + return Obx(() => GestureDetector( + onTap: () { + model.isValidity = !model.isValidity; + if (model.isValidity) { + state.selectIndexList.value.add(model.validityValue); + } else { + state.selectIndexList.value.remove(model.validityValue); + } + setState(() {}); + }, + child: Container( + width: 40.w, + height: 40.w, + margin: EdgeInsets.all(10.w), + decoration: BoxDecoration( + color: state.selectIndexList.value.contains(model.validityValue) + ? Colors.blue + : Colors.white, + border: + Border.all(width: 1, color: AppColors.greyBackgroundColor), + borderRadius: BorderRadius.circular(30.w), + ), + child: Center( + child: Text( + model.validityText, + style: TextStyle( + fontSize: 20.sp, + color: + state.selectIndexList.value.contains(model.validityValue) + ? Colors.white + : AppColors.darkGrayTextColor), + )), + ), + )); } Widget bottomWidget() { @@ -173,49 +181,59 @@ class _ElectronicKeyPeriodValidityPageState // }); // }), // Container(height: 10.h), - CommonItem( + Obx(() => CommonItem( leftTitel: TranslationLoader.lanKeys!.effectiveDate!.tr, - rightTitle: _selectEffectiveDate, + rightTitle: state.selectEffectiveDate.value, isHaveDirection: true, isHaveLine: true, action: () { Pickers.showDatePicker(context, mode: DateMode.YMDHM, onConfirm: (p) { - _effectiveDateTime = DateTime.parse( + state.isHaveEffectiveDate.value = true; + state.effectiveDateTime.value = DateTime.parse( '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); - _selectEffectiveDate = formatDate(_effectiveDateTime, + state.selectEffectiveDate.value = formatDate( + state.effectiveDateTime.value, [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); - - setState(() {}); }); - }), - CommonItem( + })), + Obx(() => CommonItem( leftTitel: TranslationLoader.lanKeys!.failureDate!.tr, - rightTitle: _selectFailureDate, + rightTitle: state.selectFailureDate.value, isHaveDirection: true, action: () { Pickers.showDatePicker(context, mode: DateMode.YMDHM, onConfirm: (p) { - _failureDateTime = DateTime.parse( + state.isHaveFailureDate.value = true; + state.failureDateTime.value = DateTime.parse( '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); - _selectFailureDate = formatDate(_failureDateTime, + state.selectFailureDate.value = formatDate( + state.failureDateTime.value, [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); - setState(() {}); }); - }), + })), Container(height: 40.h), - SubmitBtn( + Obx(() => SubmitBtn( btnName: TranslationLoader.lanKeys!.sure!.tr, borderRadius: 20.w, margin: EdgeInsets.only(left: 30.w, right: 30.w, top: 30.w), padding: EdgeInsets.only(top: 25.w, bottom: 25.w), + isDisabled: (state.selectIndexList.value.isNotEmpty && + state.isHaveEffectiveDate.value == true && + state.isHaveFailureDate.value == true) + ? true + : false, onClick: () { - Map resultMap = {}; - resultMap['validityValue'] = selectIndexList; - resultMap['starDate'] = _effectiveDateTime; - resultMap['endDate'] = _failureDateTime; - Navigator.pop(context, resultMap); - }), + if ((state.selectIndexList.value.isNotEmpty && + state.isHaveEffectiveDate.value == true && + state.isHaveFailureDate.value == true)) { + Map resultMap = {}; + resultMap['validityValue'] = state.selectIndexList.value; + resultMap['starDate'] = state.effectiveDateTime.value; + resultMap['endDate'] = state.failureDateTime.value; + Navigator.pop(context, resultMap); + } + })), ], ); } diff --git a/star_lock/lib/main/lockDetail/electronicKey/electronicKeyPeriodValidity/electronicKeyPeriodValidity_state.dart b/star_lock/lib/main/lockDetail/electronicKey/electronicKeyPeriodValidity/electronicKeyPeriodValidity_state.dart new file mode 100644 index 00000000..8e4027c6 --- /dev/null +++ b/star_lock/lib/main/lockDetail/electronicKey/electronicKeyPeriodValidity/electronicKeyPeriodValidity_state.dart @@ -0,0 +1,34 @@ +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyList/entity/ElectronicKeyListEntity.dart'; +import 'package:star_lock/translations/trans_lib.dart'; + +import '../../../lockMian/entity/lockListInfo_entity.dart'; + +class ElectronicKeyPeriodValidityState { + TextEditingController searchController = TextEditingController(); //邮箱/手机号输入框 + final keyInfo = LockListInfoItemEntity().obs; + // final lockMainEntity = LockMainEntity().obs; + var pageNum = 1.obs; //请求页码 + final pageSize = 20.obs; //请求每页数据条数 + final itemDataList = [].obs; + + final validityTextList = [ + TranslationLoader.lanKeys!.sundayShort!.tr, + TranslationLoader.lanKeys!.mondayShort!.tr, + TranslationLoader.lanKeys!.tuesdayShort!.tr, + TranslationLoader.lanKeys!.wednesdayShort!.tr, + TranslationLoader.lanKeys!.thursdayShort!.tr, + TranslationLoader.lanKeys!.fridayShort!.tr, + TranslationLoader.lanKeys!.saturdayShort!.tr + ].obs; + final validityDataList = [].obs; //自定义数据块 + final selectIndexList = [].obs; //选中的有效期数组 + final selectEffectiveDate = ''.obs; //生效时间 + final selectFailureDate = ''.obs; //失效时间 + DateTime dateTime = DateTime.now(); + final effectiveDateTime = DateTime.now().obs; + final failureDateTime = DateTime.now().obs; + var isHaveEffectiveDate = false.obs; + var isHaveFailureDate = false.obs; +} diff --git a/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_logic.dart b/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_logic.dart index d77924e2..44c18665 100644 --- a/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_logic.dart +++ b/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_logic.dart @@ -2,6 +2,8 @@ import 'package:flutter/cupertino.dart'; import 'package:get/get.dart'; import 'package:get/get_utils/get_utils.dart'; import 'package:star_lock/appRouters.dart'; +import 'package:star_lock/app_settings/app_colors.dart'; +import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart'; import 'package:star_lock/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_state.dart'; import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/tools/baseGetXController.dart'; @@ -14,18 +16,38 @@ class SendElectronicKeyLogic extends BaseGetXController { //发送钥匙请求 Future sendElectronicKeyRequest(BuildContext widgetContext) async { String lockID = state.keyInfo.value.lockId.toString(); - String getKeyType = (int.parse(state.type.value) + 1).toString(); - if (state.type.value == '0') { - state.failureTimestamp.value = - state.failureDateTime.value.millisecondsSinceEpoch; - state.effectiveTimestamp.value = - state.effectiveDateTime.value.millisecondsSinceEpoch; + int typeValue = int.parse(state.type.value); + switch (typeValue) { + case 0: + { + typeValue = XSConstantMacro.keyTypeTime; + state.failureTimestamp.value = + state.failureDateTime.value.millisecondsSinceEpoch; + state.effectiveTimestamp.value = + state.effectiveDateTime.value.millisecondsSinceEpoch; + } + break; + case 1: + typeValue = XSConstantMacro.keyTypeLong; + break; + case 2: + typeValue = XSConstantMacro.keyTypeOnce; + break; + case 3: + typeValue = XSConstantMacro.keyTypeLoop; + break; + default: + typeValue = XSConstantMacro.keyTypeTime; + break; } + String getKeyType = typeValue.toString(); var entity = await ApiRepository.to.sendElectronicKey( createUser: state.isCreateUser.value ? "1" : "0", countryCode: state.countryCode.value, - usernameType: '1', + usernameType: isPhoneNumber(state.emailOrPhoneController.text) == true + ? '1' + : '2', endDate: state.failureTimestamp.value.toString(), faceAuthentication: state.isAuthentication.value == true ? '1' : '2', isCameraEnable: '2', @@ -38,20 +60,37 @@ class SendElectronicKeyLogic extends BaseGetXController { receiverUsername: state.emailOrPhoneController.text, remarks: '', startDate: state.effectiveTimestamp.value.toString(), - weekDays: state.weekdaysList); + weekDays: state.weekdaysList.value); if (entity.errorCode!.codeIsSuccessful) { print('发送电子钥匙成功'); state.isSendSuccess.value = true; } else { if (entity.errorCode == 425) { //用户未注册 - _showDialog(widgetContext, '${entity.errorMsg}'); + if (isPhoneNumber(state.emailOrPhoneController.text) == true) { + _showPhoneDialog(widgetContext, '${entity.errorMsg}'); + } else { + _showEmailDialog(widgetContext); + } } } } + bool isPhoneNumber(String input) { + // 手机号正则表达式,这里简化为11位数字 + final RegExp phoneRegExp = RegExp(r'^\d{11}$'); + return phoneRegExp.hasMatch(input); + } + + bool isEmail(String input) { + // 邮箱正则表达式,这里简化为常见格式 + final RegExp emailRegExp = + RegExp(r'^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$'); + return emailRegExp.hasMatch(input); + } + //用户未注册确认弹窗 - void _showDialog(widgetContext, String errMsg) { + void _showPhoneDialog(widgetContext, String errMsg) { showCupertinoDialog( context: widgetContext, builder: (context) { @@ -59,13 +98,19 @@ class SendElectronicKeyLogic extends BaseGetXController { title: const Text('接收者号码未注册,请选择号码所在的国家并重新发送'), actions: [ CupertinoDialogAction( - child: Text(TranslationLoader.lanKeys!.cancel!.tr), + child: Text( + TranslationLoader.lanKeys!.cancel!.tr, + style: TextStyle(color: AppColors.mainColor), + ), onPressed: () { Navigator.of(context).pop(); }, ), CupertinoDialogAction( - child: Text(TranslationLoader.lanKeys!.selet!.tr), + child: Text( + TranslationLoader.lanKeys!.selet!.tr, + style: TextStyle(color: AppColors.mainColor), + ), onPressed: () async { //选择国家代码 state.isCreateUser.value = true; @@ -84,4 +129,39 @@ class SendElectronicKeyLogic extends BaseGetXController { }, ); } + + //用户未注册确认弹窗---邮箱 + void _showEmailDialog(widgetContext) { + showCupertinoDialog( + context: widgetContext, + builder: (context) { + return CupertinoAlertDialog( + title: Text('是否发送电子钥匙给未注册账号\n${state.emailOrPhoneController.text}'), + actions: [ + CupertinoDialogAction( + child: Text( + TranslationLoader.lanKeys!.cancel!.tr, + style: TextStyle(color: AppColors.mainColor), + ), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + CupertinoDialogAction( + child: Text( + TranslationLoader.lanKeys!.sure!.tr, + style: TextStyle(color: AppColors.mainColor), + ), + onPressed: () { + state.isCreateUser.value = true; + Navigator.of(context).pop(); + + sendElectronicKeyRequest(widgetContext); + }, + ), + ], + ); + }, + ); + } } diff --git a/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_page.dart b/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_page.dart index 83805758..6c7e22e3 100644 --- a/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_page.dart +++ b/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_page.dart @@ -217,11 +217,9 @@ class _SendElectronicKeyPageState extends State { children: [ Obx(() => CommonItem( leftTitel: TranslationLoader.lanKeys!.periodValidity!.tr, - rightTitle: state.weekdaysList.isEmpty + rightTitle: state.weekdaysList.value.isEmpty ? '' - : state.weekdaysList - .reduce((value, element) => value + ',' + element) - .toString(), + : state.weekdaysList.value.join(','), isHaveDirection: true, action: () async { var result = await Navigator.pushNamed( @@ -406,9 +404,9 @@ class _SendElectronicKeyPageState extends State { var entity = await ApiRepository.to.setRoomStatusData( lockId: state.keyInfo.value.lockId!, - roomStatus:1, + roomStatus: 1, ); - if(entity.errorCode!.codeIsSuccessful){ + if (entity.errorCode!.codeIsSuccessful) { print("标记为已入住成功啦啦啦啦啦"); Toast.show(msg: "标记成功"); setState(() {}); @@ -440,6 +438,8 @@ class _SendElectronicKeyPageState extends State { //不需要输入框下划线 border: InputBorder.none, ), + style: TextStyle( + fontSize: 22.sp, textBaseline: TextBaseline.alphabetic), ), ), SizedBox( diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_page.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_page.dart index 7bbdd9de..d278719a 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_page.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKeyList/passwordKeyList_page.dart @@ -86,9 +86,7 @@ class _PasswordKeyListPageState extends State { btnName: TranslationLoader.lanKeys!.getPassword!.tr, onClick: () { Navigator.pushNamed(context, Routers.passwordKeyManagePage, - arguments: { - "keyInfo": state.keyInfo.value - }).then((val) { + arguments: {"keyInfo": state.keyInfo.value}).then((val) { if (val != null) { logic.mockNetworkDataRequest(); } @@ -143,7 +141,7 @@ class _PasswordKeyListPageState extends State { decoration: InputDecoration( //输入里面输入文字内边距设置 contentPadding: const EdgeInsets.only( - top: 12.0, left: -19.0, right: -15.0, bottom: 8.0), + top: 18.0, left: -19.0, right: -15.0, bottom: 2), hintText: TranslationLoader.lanKeys!.pleaseEnter!.tr, hintStyle: TextStyle(fontSize: 22.sp, height: 3.0), //不需要输入框下划线 @@ -186,13 +184,13 @@ class _PasswordKeyListPageState extends State { ), child: _electronicKeyItem('images/icon_password.png', passwordKeyListItem.keyboardPwdName!, useDateStr, () { - Navigator.pushNamed(context, Routers.passwordKeyDetailPage, - arguments: {"itemData": passwordKeyListItem}).then((val) { - if (val != null) { - logic.mockNetworkDataRequest(); - } - }); - }), + Navigator.pushNamed(context, Routers.passwordKeyDetailPage, + arguments: {"itemData": passwordKeyListItem}).then((val) { + if (val != null) { + logic.mockNetworkDataRequest(); + } + }); + }), ); } return const SizedBox.shrink(); @@ -229,7 +227,8 @@ class _PasswordKeyListPageState extends State { ); } - void showIosTipViewDialog(BuildContext context, PasswordKeyListItem passwordKeyListItem) { + void showIosTipViewDialog( + BuildContext context, PasswordKeyListItem passwordKeyListItem) { showDialog( context: context, builder: (BuildContext context) { @@ -238,14 +237,14 @@ class _PasswordKeyListPageState extends State { tipTitle: "确定要删除吗?", sureClick: () { Get.back(); - logic.deletePwdRequest(passwordKeyListItem.lockId.toString(), passwordKeyListItem.keyboardPwdId.toString(), 1); + logic.deletePwdRequest(passwordKeyListItem.lockId.toString(), + passwordKeyListItem.keyboardPwdId.toString(), 1); }, cancelClick: () { Get.back(); }, ); - } - ); + }); } //使用期限 diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart index 41e448ca..21764cc0 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart @@ -2,6 +2,9 @@ import 'dart:async'; import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'; import 'package:star_lock/blue/io_type.dart'; +import 'package:star_lock/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart'; +import 'package:star_lock/network/api_repository.dart'; +import 'package:star_lock/tools/toast.dart'; import '../../../../blue/blue_manage.dart'; import '../../../../blue/io_reply.dart'; @@ -13,6 +16,135 @@ import '../../../../tools/baseGetXController.dart'; import '../../../../tools/storage.dart'; class PasswordKeyPerpetualLogic extends BaseGetXController { + final PasswordKeyPerpetualState state = PasswordKeyPerpetualState(); + + /** +单次 1 只能在开始时间后6小时内使用一次 +永久 2 从开始时间开始永久有效,必需在开始时间24小时内使用一次,否则将失效 +限期 3 在开始和结束时间内有效,必需在开始时间24小时内使用一次,否则将失效 +删除 4 在锁上使用后会删除之前在锁上使用过的密码 +周未循环 5 在周未开始和结束时间指定时间段内有效 +每日循环 6 每天开始和结束时间指定时间段内有效 +工作日循环 7 工作日开始和结束时间指定的时间段内有效 +周一循环 8 每周一开始和结束时间指定时间段内有效 +周二循环 9 每周二开始和结束时间指定时间段内有效 +周三循环 10 每周三开始和结束时间指定时间段内有效 +周四循环 11 每周四开始和结束时间指定时间段内有效 +周五循环 12 每周五开始和结束时间指定时间段内有效 +周六循环 13 每周六开始和结束时间指定时间段内有效 +周天循环 14 每周日开始和结束时间指定时间段内有效 + */ + //获取密码请求 + Future getKeyboardPwdRequest() async { + String getFailureDateTime = '0'; + String getEffectiveDateTime = '0'; + String lockId = state.keyInfo.value.lockId.toString(); + int passwordType = int.parse(state.widgetType.value); + String getKeyType = passwordType.toString(); + if (passwordType == 0) { + //永久 + getKeyType = '2'; + } else if (passwordType == 1) { + //限时 + getKeyType = '3'; + } else if (passwordType == 2) { + //单次 + getKeyType = '1'; + } else if (passwordType == 3) { + //自定义 + } else if (passwordType == 4) { + //循环 + if (state.cyclicModeStr.value == '每日') { + getKeyType = '6'; + } else if (state.cyclicModeStr.value == '工作日') { + getKeyType = '7'; + } else if (state.cyclicModeStr.value == '星期一') { + getKeyType = '8'; + } else if (state.cyclicModeStr.value == '星期二') { + getKeyType = '9'; + } else if (state.cyclicModeStr.value == '星期三') { + getKeyType = '10'; + } else if (state.cyclicModeStr.value == '星期四') { + getKeyType = '11'; + } else if (state.cyclicModeStr.value == '星期五') { + getKeyType = '12'; + } else if (state.cyclicModeStr.value == '星期六') { + getKeyType = '13'; + } else if (state.cyclicModeStr.value == '星期日') { + getKeyType = '14'; + } + } else if (passwordType == 5) { + //清空码 + getKeyType = '4'; + } + if (state.widgetType.value != '0' && + state.widgetType.value != '2' && + state.widgetType.value != '5') { + getFailureDateTime = + state.failureDateTime.value.millisecondsSinceEpoch.toString(); + getEffectiveDateTime = + state.effectiveDateTime.value.millisecondsSinceEpoch.toString(); + } + var entity = await ApiRepository.to.getPasswordKey( + getFailureDateTime, + '0', + state.nameController.text, + getKeyType, + '0', + lockId, + '0', + getEffectiveDateTime, + '0', + state.startHours.value, + state.endHours.value, + 1); + if (entity.errorCode!.codeIsSuccessful) { + print('获取密码成功'); + state.isSendSuccess.value = true; + if (entity.data != null) { + state.getPwdStr.value = entity.data!.keyboardPwd!; + } + } else { + Toast.show(msg: '${entity.errorMsg}'); + } + } + + //自定义密码请求 + Future addKeyboardPwdRequest() async { + String getFailureDateTime = '0'; + String getEffectiveDateTime = '0'; + String lockId = state.keyInfo.value.lockId.toString(); + String getKeyType = '3'; + //是否为永久 + if (state.isPermanent.value == false) { + getKeyType = '3'; + getFailureDateTime = DateTime.parse(state.selectFailureDate.value) + .millisecondsSinceEpoch + .toString(); + getEffectiveDateTime = DateTime.parse(state.selectEffectiveDate.value) + .millisecondsSinceEpoch + .toString(); + } else { + getKeyType = '2'; + } + var entity = await ApiRepository.to.addPasswordKey( + lockId, + state.nameController.text, + state.pwdController.text, + getKeyType, + getEffectiveDateTime, + getFailureDateTime, + '0'); + if (entity.errorCode!.codeIsSuccessful) { + print('获取密码成功'); + state.isSendSuccess.value = true; + if (entity.data != null) { + state.getPwdStr.value = entity.data!.keyboardPwd!; + } + } else { + Toast.show(msg: '${entity.errorMsg}'); + } + } late DateTime getStartDateTime; // 监听设备返回的数据 diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart index 4b2f271b..98fd1356 100644 --- a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_page.dart @@ -35,23 +35,23 @@ class PasswordKeyPerpetualPage extends StatefulWidget { } class _PasswordKeyPerpetualPageState extends State { - final TextEditingController _nameController = TextEditingController(); - final TextEditingController _pwdController = TextEditingController(); final logic = Get.put(PasswordKeyPerpetualLogic()); + final state = Get.find().state; + static const methodChannel = MethodChannel('talkPlugin'); - late bool _isSendSuccess; //是否发送成功 - late bool _isPermanent; //是否永久 - late String _getPwdStr; - String _selectEffectiveDate = ''; //生效时间 - String _selectFailureDate = ''; //失效时间 - late DateTime _effectiveDateTime; - late DateTime _failureDateTime; - late String cyclicModeStr; //循环模式 - late String effectiveHourStr; - late String failureHourStr; - int startHours = 0; - int endHours = 0; + // late bool _isSendSuccess; //是否发送成功 + // late bool _isPermanent; //是否永久 + // late String _getPwdStr; + // String _selectEffectiveDate = ''; //生效时间 + // String _selectFailureDate = ''; //失效时间 + // late DateTime _effectiveDateTime; + // late DateTime _failureDateTime; + // late String cyclicModeStr; //循环模式 + // late String effectiveHourStr; + // late String failureHourStr; + // int startHours = 0; + // int endHours = 0; @override Widget build(BuildContext context) { @@ -64,37 +64,56 @@ class _PasswordKeyPerpetualPageState extends State { void initState() { super.initState(); - _isSendSuccess = false; - _isPermanent = false; - DateTime dateTime = DateTime.now(); - _effectiveDateTime = dateTime; - _failureDateTime = dateTime; - if (int.parse(widget.type) == 4) { - cyclicModeStr = '周末'; + state.keyInfo.value = widget.getKeyInfo; + state.widgetType.value = widget.type; - _selectEffectiveDate = "${formatDate(dateTime, [HH])}:00"; //默认为当前时间 - _selectFailureDate = "${formatDate(dateTime, [HH])}:00"; //默认为当前时间 - startHours = _effectiveDateTime.hour; - endHours = _failureDateTime.hour; - } else if (int.parse(widget.type) == 3) { + // _isSendSuccess = false; + // _isPermanent = false; + DateTime dateTime = DateTime.now(); + // _effectiveDateTime = dateTime; + // _failureDateTime = dateTime; + if (int.parse(state.widgetType.value) == 4) { + state.cyclicModeStr.value = '周末'; + + state.selectEffectiveDate.value = + "${formatDate(dateTime, [HH])}:00"; //默认为当前时间 + state.selectFailureDate.value = + "${formatDate(dateTime, [HH])}:00"; //默认为当前时间 + state.startHours.value = state.effectiveDateTime.value.hour; + state.endHours.value = state.failureDateTime.value.hour; + } else if (int.parse(state.widgetType.value) == 3) { // 自定义 - _selectEffectiveDate = formatDate( + state.selectEffectiveDate.value = formatDate( dateTime, [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); //默认为当前时间 - _selectFailureDate = formatDate( + state.selectFailureDate.value = formatDate( dateTime, [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); //默认为当前时间 } else { - _selectEffectiveDate = "${formatDate( - dateTime, [yyyy, '-', mm, '-', dd, ' ', HH])}:00"; //默认为当前时间 - _selectFailureDate = "${formatDate( - dateTime, [yyyy, '-', mm, '-', dd, ' ', HH])}:00"; //默认为当前时间 + state.selectEffectiveDate.value = "${formatDate(dateTime, [ + yyyy, + '-', + mm, + '-', + dd, + ' ', + HH + ])}:00"; //默认为当前时间 + state.selectFailureDate.value = "${formatDate(dateTime, [ + yyyy, + '-', + mm, + '-', + dd, + ' ', + HH + ])}:00"; //默认为当前时间 } } Widget indexChangeWidget() { - if (_isSendSuccess) { + if (state.isSendSuccess.value) { return sendElectronicKeySucceed(); } else { - switch (int.parse(widget.type)) { + switch (int.parse(state.widgetType.value)) { case 0: { // 永久 @@ -103,7 +122,7 @@ class _PasswordKeyPerpetualPageState extends State { perpetualKeyWidget( TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, - _nameController), + state.nameController), keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip1!.tr) ], ); @@ -117,7 +136,7 @@ class _PasswordKeyPerpetualPageState extends State { perpetualKeyWidget( TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, - _nameController), + state.nameController), keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip2!.tr) ], ); @@ -130,7 +149,7 @@ class _PasswordKeyPerpetualPageState extends State { perpetualKeyWidget( TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, - _nameController), + state.nameController), keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip3!.tr) ], ); @@ -141,13 +160,15 @@ class _PasswordKeyPerpetualPageState extends State { return Column( children: [ keyIfPerpetualWidget(), - _isPermanent == false ? keyTimeLimitWidget() : Container(), + state.isPermanent.value == false + ? keyTimeLimitWidget() + : Container(), perpetualKeyWidget( TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, - _nameController), + state.nameController), perpetualKeyWidget(TranslationLoader.lanKeys!.password!.tr, - "请输入6-9位数字", _pwdController), + "请输入6-9位数字", state.pwdController), keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip4!.tr) ], ); @@ -161,7 +182,7 @@ class _PasswordKeyPerpetualPageState extends State { perpetualKeyWidget( TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, - _nameController), + state.nameController), keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip5!.tr) ], ); @@ -174,7 +195,7 @@ class _PasswordKeyPerpetualPageState extends State { perpetualKeyWidget( TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.pleaseNameYourPassword!.tr, - _nameController), + state.nameController), keyBottomWidget(TranslationLoader.lanKeys!.getPasswordTip6!.tr) ], ); @@ -206,60 +227,61 @@ class _PasswordKeyPerpetualPageState extends State { // 限时顶部选择日期 Widget keyTimeLimitWidget() { - return Container( - // margin: EdgeInsets.only(left: 20.w, right: 20.w), - child: Column( - children: [ - CommonItem( - leftTitel: TranslationLoader.lanKeys!.effectiveTime!.tr, - rightTitle: _selectEffectiveDate, - isHaveLine: true, - isHaveDirection: true, - action: () { - Pickers.showDatePicker(context, mode: DateMode.YMDHM, - onConfirm: (p) { - setState(() { - if (int.parse(widget.type) == 3) { - // 自定义 - _effectiveDateTime = DateTime.parse( - '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); - _selectEffectiveDate = formatDate(_effectiveDateTime, - [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); //默认为当前时间 - } else { - _effectiveDateTime = DateTime.parse( - '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}'); - _selectEffectiveDate = "${formatDate(_effectiveDateTime, - [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn])}00"; //默认为当前时间 - } - }); + return Column( + children: [ + CommonItem( + leftTitel: TranslationLoader.lanKeys!.effectiveTime!.tr, + rightTitle: state.selectEffectiveDate.value, + isHaveLine: true, + isHaveDirection: true, + action: () { + Pickers.showDatePicker(context, mode: DateMode.YMDHM, + onConfirm: (p) { + setState(() { + if (int.parse(state.widgetType.value) == 3) { + // 自定义 + state.effectiveDateTime.value = DateTime.parse( + '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); + state.selectEffectiveDate.value = formatDate( + state.effectiveDateTime.value, + [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); //默认为当前时间 + } else { + state.effectiveDateTime.value = DateTime.parse( + '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}'); + state.selectEffectiveDate.value = formatDate( + state.effectiveDateTime.value, + [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); //默认为当前时间 + } }); - }), - CommonItem( - leftTitel: TranslationLoader.lanKeys!.failureTime!.tr, - rightTitle: _selectFailureDate, - isHaveDirection: true, - action: () { - Pickers.showDatePicker(context, mode: DateMode.YMDHM, - onConfirm: (p) { - setState(() { - if (int.parse(widget.type) == 3) { - // 自定义 - _failureDateTime = DateTime.parse( - '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); - _selectFailureDate = formatDate(_failureDateTime, - [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); //默认为当前时间 - } else { - _failureDateTime = DateTime.parse( - '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}'); - _selectFailureDate = "${formatDate(_failureDateTime, - [yyyy, '-', mm, '-', dd, ' ', HH])}:00"; - } - }); + }); + }), + CommonItem( + leftTitel: TranslationLoader.lanKeys!.failureTime!.tr, + rightTitle: state.selectFailureDate.value, + isHaveDirection: true, + action: () { + Pickers.showDatePicker(context, mode: DateMode.YMDHM, + onConfirm: (p) { + setState(() { + if (int.parse(state.widgetType.value) == 3) { + // 自定义 + state.failureDateTime.value = DateTime.parse( + '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); + state.selectFailureDate.value = formatDate( + state.failureDateTime.value, + [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); //默认为当前时间 + } else { + state.failureDateTime.value = DateTime.parse( + '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}'); + state.selectFailureDate.value = formatDate( + state.failureDateTime.value, + [yyyy, '-', mm, '-', dd, ' ', HH]); + } }); - }), - Container(height: 10.h), - ], - ), + }); + }), + Container(height: 10.h), + ], ); } @@ -276,7 +298,7 @@ class _PasswordKeyPerpetualPageState extends State { rightWidget: SizedBox(width: 60.w, height: 50.h, child: _switch()), action: () {}), - _isPermanent == true + state.isPermanent.value == true ? Container(height: 10.h) : Container(height: 1.h), ], @@ -286,72 +308,70 @@ class _PasswordKeyPerpetualPageState extends State { // 循环 Widget keyCirculationWidget() { - return Container( - // margin: EdgeInsets.only(left: 20.w, right: 20.w), - child: Column( - children: [ - CommonItem( - leftTitel: TranslationLoader.lanKeys!.recursiveDevice!.tr, - rightTitle: cyclicModeStr, - isHaveLine: true, - isHaveDirection: true, - action: () { - List pickerDataList = [ - '周末', - '每日', - '工作日', - '星期一', - '星期二', - '星期三', - '星期四', - '星期五', - '星期六', - '星期日' - ]; - showPickerView(context, pickerDataList); - }), - CommonItem( - leftTitel: TranslationLoader.lanKeys!.effectiveTime!.tr, - rightTitle: _selectEffectiveDate, - isHaveLine: true, - isHaveDirection: true, - action: () { - Pickers.showDatePicker(context, mode: DateMode.H, - onConfirm: (p) { - setState(() { - _effectiveDateTime = DateTime.parse( - '${_effectiveDateTime.year}-${intToStr(_effectiveDateTime.month)}-${intToStr(_effectiveDateTime.day)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); - _selectEffectiveDate = - formatDate(_effectiveDateTime, [HH, ':', nn]); - startHours = p.hour!; - }); + return Column( + children: [ + CommonItem( + leftTitel: TranslationLoader.lanKeys!.recursiveDevice!.tr, + rightTitle: state.cyclicModeStr.value, + isHaveLine: true, + isHaveDirection: true, + action: () { + List pickerDataList = [ + '周末', + '每日', + '工作日', + '星期一', + '星期二', + '星期三', + '星期四', + '星期五', + '星期六', + '星期日' + ]; + showPickerView(context, pickerDataList); + }), + CommonItem( + leftTitel: TranslationLoader.lanKeys!.effectiveTime!.tr, + rightTitle: state.selectEffectiveDate.value, + isHaveLine: true, + isHaveDirection: true, + action: () { + Pickers.showDatePicker(context, mode: DateMode.H, onConfirm: (p) { + setState(() { + state.effectiveDateTime.value = DateTime.parse( + '${state.effectiveDateTime.value.year}-${intToStr(state.effectiveDateTime.value.month)}-${intToStr(state.effectiveDateTime.value.day)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); + state.selectEffectiveDate.value = + formatDate(state.effectiveDateTime.value, [HH, ':', nn]); + state.startHours.value = p.hour!; }); - }), - CommonItem( - leftTitel: TranslationLoader.lanKeys!.failureTime!.tr, - rightTitle: _selectFailureDate, - isHaveDirection: true, - action: () { - Pickers.showDatePicker(context, mode: DateMode.H, onConfirm: (p) { - setState(() { - _failureDateTime = DateTime.parse( - '${_failureDateTime.year}-${intToStr(_failureDateTime.month)}-${intToStr(_failureDateTime.day)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); - _selectFailureDate = - formatDate(_failureDateTime, [HH, ':', nn]); - endHours = p.hour!; - }); + }); + }), + CommonItem( + leftTitel: TranslationLoader.lanKeys!.failureTime!.tr, + rightTitle: state.selectFailureDate.value, + isHaveDirection: true, + action: () { + Pickers.showDatePicker(context, mode: DateMode.H, onConfirm: (p) { + setState(() { + state.failureDateTime.value = DateTime.parse( + '${state.failureDateTime.value.year}-${intToStr(state.failureDateTime.value.month)}-${intToStr(state.failureDateTime.value.day)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); + state.selectFailureDate.value = + formatDate(state.failureDateTime.value, [HH, ':', nn]); + state.endHours.value = p.hour!; }); - }), - ], - ), + }); + }), + ], ); } //底部选择pickerView showPickerView(BuildContext context, List dataList) { - Pickers.showSinglePicker(context, data: dataList, pickerStyle: DefaultPickerStyle(), onConfirm: (p, position) { + Pickers.showSinglePicker(context, + data: dataList, + pickerStyle: DefaultPickerStyle(), onConfirm: (p, position) { setState(() { - cyclicModeStr = p; + state.cyclicModeStr.value = p; }); }, onChanged: (p, position) { setState(() {}); @@ -405,18 +425,18 @@ class _PasswordKeyPerpetualPageState extends State { */ var isDemoMode = await Storage.getBool(ifIsDemoModeOrNot); if (isDemoMode == false) { - if (_nameController.text.isNotEmpty) { - logic.getStartDate(_effectiveDateTime); - int passwordType = int.parse(widget.type); + if (state.nameController.text.isNotEmpty) { + logic.getStartDate(state.effectiveDateTime.value); + int passwordType = int.parse(state.widgetType.value); if (passwordType == 3) { - if (_pwdController.text.isNotEmpty) { + if (state.pwdController.text.isNotEmpty) { //自定义密码 - addKeyboardPwdRequest(); + logic.addKeyboardPwdRequest(); } else { Toast.show(msg: '请输入密码'); } } else { - getKeyboardPwdRequest(); + logic.getKeyboardPwdRequest(); } } else { Toast.show(msg: '请给密码命名'); @@ -429,132 +449,6 @@ class _PasswordKeyPerpetualPageState extends State { ); } - /** -单次 1 只能在开始时间后6小时内使用一次 -永久 2 从开始时间开始永久有效,必需在开始时间24小时内使用一次,否则将失效 -限期 3 在开始和结束时间内有效,必需在开始时间24小时内使用一次,否则将失效 -删除 4 在锁上使用后会删除之前在锁上使用过的密码 -周未循环 5 在周未开始和结束时间指定时间段内有效 -每日循环 6 每天开始和结束时间指定时间段内有效 -工作日循环 7 工作日开始和结束时间指定的时间段内有效 -周一循环 8 每周一开始和结束时间指定时间段内有效 -周二循环 9 每周二开始和结束时间指定时间段内有效 -周三循环 10 每周三开始和结束时间指定时间段内有效 -周四循环 11 每周四开始和结束时间指定时间段内有效 -周五循环 12 每周五开始和结束时间指定时间段内有效 -周六循环 13 每周六开始和结束时间指定时间段内有效 -周天循环 14 每周日开始和结束时间指定时间段内有效 - */ - //获取密码请求 - Future getKeyboardPwdRequest() async { - String getFailureDateTime = '0'; - String getEffectiveDateTime = '0'; - String lockId = widget.getKeyInfo.lockId.toString(); - int passwordType = int.parse(widget.type); - String getKeyType = passwordType.toString(); - if (passwordType == 0) { - //永久 - getKeyType = '2'; - } else if (passwordType == 1) { - //限时 - getKeyType = '3'; - } else if (passwordType == 2) { - //单次 - getKeyType = '1'; - } else if (passwordType == 3) { - //自定义 - } else if (passwordType == 4) { - //循环 - if (cyclicModeStr == '每日') { - getKeyType = '6'; - } else if (cyclicModeStr == '工作日') { - getKeyType = '7'; - } else if (cyclicModeStr == '星期一') { - getKeyType = '8'; - } else if (cyclicModeStr == '星期二') { - getKeyType = '9'; - } else if (cyclicModeStr == '星期三') { - getKeyType = '10'; - } else if (cyclicModeStr == '星期四') { - getKeyType = '11'; - } else if (cyclicModeStr == '星期五') { - getKeyType = '12'; - } else if (cyclicModeStr == '星期六') { - getKeyType = '13'; - } else if (cyclicModeStr == '星期日') { - getKeyType = '14'; - } - } else if (passwordType == 5) { - //清空码 - getKeyType = '4'; - } - if (widget.type != '0' && widget.type != '2' && widget.type != '5') { - getFailureDateTime = _failureDateTime.millisecondsSinceEpoch.toString(); - getEffectiveDateTime = - _effectiveDateTime.millisecondsSinceEpoch.toString(); - } - var entity = await ApiRepository.to.getPasswordKey( - getFailureDateTime, - '0', - _nameController.text, - getKeyType, - '0', - lockId, - '0', - getEffectiveDateTime, - '0', - startHours, - endHours, - 1); - if (entity.errorCode!.codeIsSuccessful) { - print('获取密码成功'); - _isSendSuccess = true; - if (entity.data != null) { - _getPwdStr = entity.data!.keyboardPwd!; - setState(() {}); - } - } else { - Toast.show(msg: '${entity.errorMsg}'); - } - } - - //自定义密码请求 - Future addKeyboardPwdRequest() async { - String getFailureDateTime = '0'; - String getEffectiveDateTime = '0'; - String lockId = widget.getKeyInfo.lockId.toString(); - String getKeyType = '3'; - //是否为永久 - if (_isPermanent == false) { - getKeyType = '3'; - getFailureDateTime = - DateTime.parse(_selectFailureDate).millisecondsSinceEpoch.toString(); - getEffectiveDateTime = DateTime.parse(_selectEffectiveDate) - .millisecondsSinceEpoch - .toString(); - } else { - getKeyType = '2'; - } - var entity = await ApiRepository.to.addPasswordKey( - lockId, - _nameController.text, - _pwdController.text, - getKeyType, - getEffectiveDateTime, - getFailureDateTime, - '0'); - if (entity.errorCode!.codeIsSuccessful) { - print('获取密码成功'); - _isSendSuccess = true; - if (entity.data != null) { - _getPwdStr = entity.data!.keyboardPwd!; - setState(() {}); - } - } else { - Toast.show(msg: '${entity.errorMsg}'); - } - } - // 发送电子钥匙成功 Widget sendElectronicKeySucceed() { return Column( @@ -584,7 +478,7 @@ class _PasswordKeyPerpetualPageState extends State { height: 10.h, ), Text( - _getPwdStr, + state.getPwdStr.value, style: TextStyle( fontSize: 40.sp, color: Colors.black, @@ -599,7 +493,7 @@ class _PasswordKeyPerpetualPageState extends State { SubmitBtn( btnName: '完成', onClick: () { - _isSendSuccess = false; + state.isSendSuccess.value = false; Navigator.pop(context, true); }), SizedBox( @@ -659,10 +553,10 @@ class _PasswordKeyPerpetualPageState extends State { activeColor: CupertinoColors.activeBlue, trackColor: CupertinoColors.systemGrey5, thumbColor: CupertinoColors.white, - value: _isPermanent, + value: state.isPermanent.value, onChanged: (value) { setState(() { - _isPermanent = value; + state.isPermanent.value = value; }); }, ); @@ -758,7 +652,7 @@ class _PasswordKeyPerpetualPageState extends State { case 0: //微信好友 { - String pwdShareStr = '您好,您的密码是:$_getPwdStr'; + String pwdShareStr = '您好,您的密码是:${state.getPwdStr.value}'; tokNative('flutter_sharePassword_to_ios', arguments: {'pwdShareStr': pwdShareStr}).then((result) { print('$result'); diff --git a/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart new file mode 100644 index 00000000..80a40fbe --- /dev/null +++ b/star_lock/lib/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKey_perpetual_state.dart @@ -0,0 +1,24 @@ +import 'package:flutter/widgets.dart'; +import 'package:get/get.dart'; +import 'package:star_lock/main/lockMian/entity/lockListInfo_entity.dart'; + +class PasswordKeyPerpetualState { + final TextEditingController nameController = TextEditingController(); + final TextEditingController pwdController = TextEditingController(); + + final isSendSuccess = false.obs; //是否发送成功 + final isPermanent = false.obs; //是否永久 + var getPwdStr = ''.obs; + var selectEffectiveDate = ''.obs; //生效时间 + var selectFailureDate = ''.obs; //失效时间 + DateTime dateTime = DateTime.now(); + final effectiveDateTime = DateTime.now().obs; + final failureDateTime = DateTime.now().obs; + var cyclicModeStr = ''.obs; //循环模式 + var effectiveHourStr = ''.obs; + var failureHourStr = ''.obs; + var startHours = 0.obs; + var endHours = 0.obs; + final widgetType = ''.obs; + final keyInfo = LockListInfoItemEntity().obs; +}