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 21764cc0..8fcf87ad 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 @@ -54,23 +54,23 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { //自定义 } else if (passwordType == 4) { //循环 - if (state.cyclicModeStr.value == '每日') { + if (state.loopModeStr.value == '每日') { getKeyType = '6'; - } else if (state.cyclicModeStr.value == '工作日') { + } else if (state.loopModeStr.value == '工作日') { getKeyType = '7'; - } else if (state.cyclicModeStr.value == '星期一') { + } else if (state.loopModeStr.value == '星期一') { getKeyType = '8'; - } else if (state.cyclicModeStr.value == '星期二') { + } else if (state.loopModeStr.value == '星期二') { getKeyType = '9'; - } else if (state.cyclicModeStr.value == '星期三') { + } else if (state.loopModeStr.value == '星期三') { getKeyType = '10'; - } else if (state.cyclicModeStr.value == '星期四') { + } else if (state.loopModeStr.value == '星期四') { getKeyType = '11'; - } else if (state.cyclicModeStr.value == '星期五') { + } else if (state.loopModeStr.value == '星期五') { getKeyType = '12'; - } else if (state.cyclicModeStr.value == '星期六') { + } else if (state.loopModeStr.value == '星期六') { getKeyType = '13'; - } else if (state.cyclicModeStr.value == '星期日') { + } else if (state.loopModeStr.value == '星期日') { getKeyType = '14'; } } else if (passwordType == 5) { @@ -95,8 +95,8 @@ class PasswordKeyPerpetualLogic extends BaseGetXController { '0', getEffectiveDateTime, '0', - state.startHours.value, - state.endHours.value, + state.loopStartHours.value, + state.loopEndHours.value, 1); if (entity.errorCode!.codeIsSuccessful) { print('获取密码成功'); 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 98fd1356..e8757112 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 @@ -9,8 +9,6 @@ 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/passwordKey/passwordKey_perpetual/passwordKey_perpetual_logic.dart'; -import 'package:star_lock/network/api_repository.dart'; -import 'package:star_lock/tools/baseGetXController.dart'; import 'package:star_lock/tools/storage.dart'; import 'package:star_lock/tools/toast.dart'; @@ -40,80 +38,33 @@ class _PasswordKeyPerpetualPageState extends 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; - - @override - Widget build(BuildContext context) { - return SingleChildScrollView( - child: indexChangeWidget(), - ); - } - @override void initState() { super.initState(); - state.keyInfo.value = widget.getKeyInfo; - state.widgetType.value = widget.type; + initData(); + } - // _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) { - // 自定义 - state.selectEffectiveDate.value = formatDate( - dateTime, [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); //默认为当前时间 - state.selectFailureDate.value = formatDate( - dateTime, [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); //默认为当前时间 - } else { - state.selectEffectiveDate.value = "${formatDate(dateTime, [ - yyyy, - '-', - mm, - '-', - dd, - ' ', - HH - ])}:00"; //默认为当前时间 - state.selectFailureDate.value = "${formatDate(dateTime, [ - yyyy, - '-', - mm, - '-', - dd, - ' ', - HH - ])}:00"; //默认为当前时间 + void initData() { + if (!state.isInitialized.value) { + state.isInitialized.value = true; + state.keyInfo.value = widget.getKeyInfo; + state.widgetType.value = widget.type; } } + @override + Widget build(BuildContext context) { + return SingleChildScrollView( + child: Obx(() => indexChangeWidget()), + ); + } + Widget indexChangeWidget() { - if (state.isSendSuccess.value) { + if (state.isSendSuccess.value == true) { return sendElectronicKeySucceed(); } else { - switch (int.parse(state.widgetType.value)) { + switch (int.parse(widget.type)) { case 0: { // 永久 @@ -212,14 +163,11 @@ class _PasswordKeyPerpetualPageState extends State { return Column( children: [ SizedBox(height: 10.h), - Container( - // margin: EdgeInsets.only(left: 20.w, right: 20.w), - child: CommonItem( - leftTitel: titleStr, - rightTitle: "", - isHaveRightWidget: true, - rightWidget: getTFWidget(rightTitle, controller)), - ), + CommonItem( + leftTitel: titleStr, + rightTitle: "", + isHaveRightWidget: true, + rightWidget: getTFWidget(rightTitle, controller)), SizedBox(height: 10.h), ], ); @@ -235,24 +183,29 @@ class _PasswordKeyPerpetualPageState extends State { isHaveLine: true, isHaveDirection: true, action: () { - Pickers.showDatePicker(context, mode: DateMode.YMDHM, + Pickers.showDatePicker(context, mode: DateMode.YMDH, 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]); //默认为当前时间 - } - }); + if (int.parse(widget.type) == 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 + ])}:00"; //默认为当前时间 + } }); }), CommonItem( @@ -260,24 +213,29 @@ class _PasswordKeyPerpetualPageState extends State { rightTitle: state.selectFailureDate.value, isHaveDirection: true, action: () { - Pickers.showDatePicker(context, mode: DateMode.YMDHM, + Pickers.showDatePicker(context, mode: DateMode.YMDH, 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]); - } - }); + if (int.parse(widget.type) == 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 + ])}:00"; + } }); }), Container(height: 10.h), @@ -287,22 +245,18 @@ class _PasswordKeyPerpetualPageState extends State { // 自定义是否永久 Widget keyIfPerpetualWidget() { - return Container( - // margin: EdgeInsets.only(left: 20.w, right: 20.w), - child: Column( - children: [ - CommonItem( - leftTitel: TranslationLoader.lanKeys!.permanent!.tr, - rightTitle: "", - isHaveRightWidget: true, - rightWidget: - SizedBox(width: 60.w, height: 50.h, child: _switch()), - action: () {}), - state.isPermanent.value == true - ? Container(height: 10.h) - : Container(height: 1.h), - ], - ), + return Column( + children: [ + CommonItem( + leftTitel: TranslationLoader.lanKeys!.permanent!.tr, + rightTitle: "", + isHaveRightWidget: true, + rightWidget: SizedBox(width: 60.w, height: 50.h, child: _switch()), + action: () {}), + state.isPermanent.value == true + ? Container(height: 10.h) + : Container(height: 1.h), + ], ); } @@ -312,7 +266,7 @@ class _PasswordKeyPerpetualPageState extends State { children: [ CommonItem( leftTitel: TranslationLoader.lanKeys!.recursiveDevice!.tr, - rightTitle: state.cyclicModeStr.value, + rightTitle: state.loopModeStr.value, isHaveLine: true, isHaveDirection: true, action: () { @@ -332,33 +286,31 @@ class _PasswordKeyPerpetualPageState extends State { }), CommonItem( leftTitel: TranslationLoader.lanKeys!.effectiveTime!.tr, - rightTitle: state.selectEffectiveDate.value, + rightTitle: state.loopEffectiveDate.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!; - }); + state.effectiveDateTime.value = + DateTime.parse('${intToStr(p.hour!)}:00'); + state.loopEffectiveDate.value = + "${formatDate(state.effectiveDateTime.value, [HH])}:00"; + state.loopStartHours.value = p.hour!; + state.selectEffectiveDate.value = state.loopEffectiveDate.value; }); }), CommonItem( leftTitel: TranslationLoader.lanKeys!.failureTime!.tr, - rightTitle: state.selectFailureDate.value, + rightTitle: state.loopFailureDate.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!; - }); + state.failureDateTime.value = + DateTime.parse('${intToStr(p.hour!)}:00'); + state.loopEffectiveDate.value = + "${formatDate(state.failureDateTime.value, [HH])}:00"; + state.loopEndHours.value = p.hour!; + state.selectFailureDate.value = state.loopFailureDate.value; }); }), ], @@ -370,12 +322,8 @@ class _PasswordKeyPerpetualPageState extends State { Pickers.showSinglePicker(context, data: dataList, pickerStyle: DefaultPickerStyle(), onConfirm: (p, position) { - setState(() { - state.cyclicModeStr.value = p; - }); - }, onChanged: (p, position) { - setState(() {}); - }); + state.loopModeStr.value = p; + }, onChanged: (p, position) {}); } Widget keyBottomWidget(String tipStr) { @@ -401,46 +349,45 @@ class _PasswordKeyPerpetualPageState extends State { SubmitBtn( btnName: TranslationLoader.lanKeys!.getPassword!.tr, onClick: () async { - // logic.senderCustomPasswords(); - - /* - int getWidgetNumber = int.parse(widget.type); - - if (_nameController.text.isEmpty) { - Toast.show(msg: '请输入密码姓名'); - return; - } - if (getWidgetNumber != 0 || - getWidgetNumber != 2 || - getWidgetNumber != 5) { - if (getWidgetNumber == 3 && _pwdController.text.isEmpty) { - Toast.show(msg: '请输入密码'); - return; - } - if (_failureDateTime.compareTo(_effectiveDateTime) != 1) { - Toast.show(msg: '失效时间需大于生效时间'); - return; - } - } - */ var isDemoMode = await Storage.getBool(ifIsDemoModeOrNot); if (isDemoMode == false) { - if (state.nameController.text.isNotEmpty) { - logic.getStartDate(state.effectiveDateTime.value); - int passwordType = int.parse(state.widgetType.value); - if (passwordType == 3) { - if (state.pwdController.text.isNotEmpty) { - //自定义密码 - logic.addKeyboardPwdRequest(); - } else { - Toast.show(msg: '请输入密码'); - } - } else { - logic.getKeyboardPwdRequest(); - } - } else { - Toast.show(msg: '请给密码命名'); + int getWidgetNumber = int.parse(widget.type); + if (state.nameController.text.isEmpty) { + Toast.show(msg: '请输入姓名'); + return; } + + //限时||循环 + if (getWidgetNumber == 1 || getWidgetNumber == 4) { + if (state.failureDateTime.value + .compareTo(state.effectiveDateTime.value) != + 1) { + Toast.show(msg: '失效时间需大于生效时间'); + return; + } + } + + //自定义密码 + if (getWidgetNumber == 3) { + logic.getStartDate(state.effectiveDateTime.value); + if (state.pwdController.text.isEmpty) { + Toast.show(msg: '请输入密码'); + return; + } + //非永久 须有时限 + if (state.isPermanent.value == false) { + if (state.failureDateTime.value + .compareTo(state.effectiveDateTime.value) != + 1) { + Toast.show(msg: '失效时间需大于生效时间'); + return; + } + } + + logic.addKeyboardPwdRequest(); + } + + logic.getKeyboardPwdRequest(); } else { Toast.show(msg: '演示模式'); } @@ -548,16 +495,14 @@ class _PasswordKeyPerpetualPageState extends State { ); } - CupertinoSwitch _switch() { + _switch() { return CupertinoSwitch( activeColor: CupertinoColors.activeBlue, trackColor: CupertinoColors.systemGrey5, thumbColor: CupertinoColors.white, value: state.isPermanent.value, onChanged: (value) { - setState(() { - state.isPermanent.value = value; - }); + state.isPermanent.value = value; }, ); } 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 index 80a40fbe..0ca4bc45 100644 --- 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 @@ -1,3 +1,4 @@ +import 'package:date_format/date_format.dart'; import 'package:flutter/widgets.dart'; import 'package:get/get.dart'; import 'package:star_lock/main/lockMian/entity/lockListInfo_entity.dart'; @@ -6,19 +7,42 @@ class PasswordKeyPerpetualState { final TextEditingController nameController = TextEditingController(); final TextEditingController pwdController = TextEditingController(); + final isInitialized = false.obs; 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; + + var selectEffectiveDate = "${formatDate(DateTime.now(), [ + yyyy, + '-', + mm, + '-', + dd, + ' ', + HH, + ])}:00" + .obs; //生效时间 + + var selectFailureDate = "${formatDate(DateTime.now(), [ + yyyy, + '-', + mm, + '-', + dd, + ' ', + HH, + ])}:00" + .obs; //失效时间 + + var loopEffectiveDate = "${formatDate(DateTime.now(), [HH])}:00".obs; //生效时间 + var loopFailureDate = "${formatDate(DateTime.now(), [HH])}:00".obs; //失效时间 + var loopStartHours = DateTime.now().hour.obs; + var loopEndHours = DateTime.now().hour.obs; + var loopModeStr = '周末'.obs; //循环模式 + final widgetType = ''.obs; final keyInfo = LockListInfoItemEntity().obs; }