梳理获取密码逻辑,修复密码相关问题及细节处理,对自定义密码进行逻辑完善

This commit is contained in:
Daisy 2023-12-13 11:32:11 +08:00
parent 3cfceece5b
commit efaad95fd6
3 changed files with 175 additions and 206 deletions

View File

@ -54,23 +54,23 @@ class PasswordKeyPerpetualLogic extends BaseGetXController {
// //
} else if (passwordType == 4) { } else if (passwordType == 4) {
// //
if (state.cyclicModeStr.value == '每日') { if (state.loopModeStr.value == '每日') {
getKeyType = '6'; getKeyType = '6';
} else if (state.cyclicModeStr.value == '工作日') { } else if (state.loopModeStr.value == '工作日') {
getKeyType = '7'; getKeyType = '7';
} else if (state.cyclicModeStr.value == '星期一') { } else if (state.loopModeStr.value == '星期一') {
getKeyType = '8'; getKeyType = '8';
} else if (state.cyclicModeStr.value == '星期二') { } else if (state.loopModeStr.value == '星期二') {
getKeyType = '9'; getKeyType = '9';
} else if (state.cyclicModeStr.value == '星期三') { } else if (state.loopModeStr.value == '星期三') {
getKeyType = '10'; getKeyType = '10';
} else if (state.cyclicModeStr.value == '星期四') { } else if (state.loopModeStr.value == '星期四') {
getKeyType = '11'; getKeyType = '11';
} else if (state.cyclicModeStr.value == '星期五') { } else if (state.loopModeStr.value == '星期五') {
getKeyType = '12'; getKeyType = '12';
} else if (state.cyclicModeStr.value == '星期六') { } else if (state.loopModeStr.value == '星期六') {
getKeyType = '13'; getKeyType = '13';
} else if (state.cyclicModeStr.value == '星期日') { } else if (state.loopModeStr.value == '星期日') {
getKeyType = '14'; getKeyType = '14';
} }
} else if (passwordType == 5) { } else if (passwordType == 5) {
@ -95,8 +95,8 @@ class PasswordKeyPerpetualLogic extends BaseGetXController {
'0', '0',
getEffectiveDateTime, getEffectiveDateTime,
'0', '0',
state.startHours.value, state.loopStartHours.value,
state.endHours.value, state.loopEndHours.value,
1); 1);
if (entity.errorCode!.codeIsSuccessful) { if (entity.errorCode!.codeIsSuccessful) {
print('获取密码成功'); print('获取密码成功');

View File

@ -9,8 +9,6 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/app_settings/app_colors.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/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/storage.dart';
import 'package:star_lock/tools/toast.dart'; import 'package:star_lock/tools/toast.dart';
@ -40,80 +38,33 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
static const methodChannel = MethodChannel('talkPlugin'); 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 @override
void initState() { void initState() {
super.initState(); super.initState();
state.keyInfo.value = widget.getKeyInfo; initData();
state.widgetType.value = widget.type; }
// _isSendSuccess = false; void initData() {
// _isPermanent = false; if (!state.isInitialized.value) {
DateTime dateTime = DateTime.now(); state.isInitialized.value = true;
// _effectiveDateTime = dateTime; state.keyInfo.value = widget.getKeyInfo;
// _failureDateTime = dateTime; state.widgetType.value = widget.type;
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"; //默认为当前时间
} }
} }
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Obx(() => indexChangeWidget()),
);
}
Widget indexChangeWidget() { Widget indexChangeWidget() {
if (state.isSendSuccess.value) { if (state.isSendSuccess.value == true) {
return sendElectronicKeySucceed(); return sendElectronicKeySucceed();
} else { } else {
switch (int.parse(state.widgetType.value)) { switch (int.parse(widget.type)) {
case 0: case 0:
{ {
// //
@ -212,14 +163,11 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
return Column( return Column(
children: [ children: [
SizedBox(height: 10.h), SizedBox(height: 10.h),
Container( CommonItem(
// margin: EdgeInsets.only(left: 20.w, right: 20.w), leftTitel: titleStr,
child: CommonItem( rightTitle: "",
leftTitel: titleStr, isHaveRightWidget: true,
rightTitle: "", rightWidget: getTFWidget(rightTitle, controller)),
isHaveRightWidget: true,
rightWidget: getTFWidget(rightTitle, controller)),
),
SizedBox(height: 10.h), SizedBox(height: 10.h),
], ],
); );
@ -235,24 +183,29 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
isHaveLine: true, isHaveLine: true,
isHaveDirection: true, isHaveDirection: true,
action: () { action: () {
Pickers.showDatePicker(context, mode: DateMode.YMDHM, Pickers.showDatePicker(context, mode: DateMode.YMDH,
onConfirm: (p) { onConfirm: (p) {
setState(() { if (int.parse(widget.type) == 3) {
if (int.parse(state.widgetType.value) == 3) { //
// state.effectiveDateTime.value = DateTime.parse(
state.effectiveDateTime.value = DateTime.parse( '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}');
'${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); state.selectEffectiveDate.value = formatDate(
state.selectEffectiveDate.value = formatDate( state.effectiveDateTime.value,
state.effectiveDateTime.value, [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); //
[yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); // } else {
} else { state.effectiveDateTime.value = DateTime.parse(
state.effectiveDateTime.value = DateTime.parse( '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}');
'${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}'); state.selectEffectiveDate.value =
state.selectEffectiveDate.value = formatDate( "${formatDate(state.effectiveDateTime.value, [
state.effectiveDateTime.value, yyyy,
[yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); // '-',
} mm,
}); '-',
dd,
' ',
HH
])}:00"; //默认为当前时间
}
}); });
}), }),
CommonItem( CommonItem(
@ -260,24 +213,29 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
rightTitle: state.selectFailureDate.value, rightTitle: state.selectFailureDate.value,
isHaveDirection: true, isHaveDirection: true,
action: () { action: () {
Pickers.showDatePicker(context, mode: DateMode.YMDHM, Pickers.showDatePicker(context, mode: DateMode.YMDH,
onConfirm: (p) { onConfirm: (p) {
setState(() { if (int.parse(widget.type) == 3) {
if (int.parse(state.widgetType.value) == 3) { //
// state.failureDateTime.value = DateTime.parse(
state.failureDateTime.value = DateTime.parse( '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}');
'${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); state.selectFailureDate.value = formatDate(
state.selectFailureDate.value = formatDate( state.failureDateTime.value,
state.failureDateTime.value, [yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); //
[yyyy, '-', mm, '-', dd, ' ', HH, ':', nn]); // } else {
} else { state.failureDateTime.value = DateTime.parse(
state.failureDateTime.value = DateTime.parse( '${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}');
'${p.year}-${intToStr(p.month!)}-${intToStr(p.day!)} ${intToStr(p.hour!)}'); state.selectFailureDate.value =
state.selectFailureDate.value = formatDate( "${formatDate(state.failureDateTime.value, [
state.failureDateTime.value, yyyy,
[yyyy, '-', mm, '-', dd, ' ', HH]); '-',
} mm,
}); '-',
dd,
' ',
HH
])}:00";
}
}); });
}), }),
Container(height: 10.h), Container(height: 10.h),
@ -287,22 +245,18 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
// //
Widget keyIfPerpetualWidget() { Widget keyIfPerpetualWidget() {
return Container( return Column(
// margin: EdgeInsets.only(left: 20.w, right: 20.w), children: [
child: Column( CommonItem(
children: [ leftTitel: TranslationLoader.lanKeys!.permanent!.tr,
CommonItem( rightTitle: "",
leftTitel: TranslationLoader.lanKeys!.permanent!.tr, isHaveRightWidget: true,
rightTitle: "", rightWidget: SizedBox(width: 60.w, height: 50.h, child: _switch()),
isHaveRightWidget: true, action: () {}),
rightWidget: state.isPermanent.value == true
SizedBox(width: 60.w, height: 50.h, child: _switch()), ? Container(height: 10.h)
action: () {}), : Container(height: 1.h),
state.isPermanent.value == true ],
? Container(height: 10.h)
: Container(height: 1.h),
],
),
); );
} }
@ -312,7 +266,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
children: [ children: [
CommonItem( CommonItem(
leftTitel: TranslationLoader.lanKeys!.recursiveDevice!.tr, leftTitel: TranslationLoader.lanKeys!.recursiveDevice!.tr,
rightTitle: state.cyclicModeStr.value, rightTitle: state.loopModeStr.value,
isHaveLine: true, isHaveLine: true,
isHaveDirection: true, isHaveDirection: true,
action: () { action: () {
@ -332,33 +286,31 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
}), }),
CommonItem( CommonItem(
leftTitel: TranslationLoader.lanKeys!.effectiveTime!.tr, leftTitel: TranslationLoader.lanKeys!.effectiveTime!.tr,
rightTitle: state.selectEffectiveDate.value, rightTitle: state.loopEffectiveDate.value,
isHaveLine: true, isHaveLine: true,
isHaveDirection: true, isHaveDirection: true,
action: () { action: () {
Pickers.showDatePicker(context, mode: DateMode.H, onConfirm: (p) { Pickers.showDatePicker(context, mode: DateMode.H, onConfirm: (p) {
setState(() { state.effectiveDateTime.value =
state.effectiveDateTime.value = DateTime.parse( DateTime.parse('${intToStr(p.hour!)}:00');
'${state.effectiveDateTime.value.year}-${intToStr(state.effectiveDateTime.value.month)}-${intToStr(state.effectiveDateTime.value.day)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); state.loopEffectiveDate.value =
state.selectEffectiveDate.value = "${formatDate(state.effectiveDateTime.value, [HH])}:00";
formatDate(state.effectiveDateTime.value, [HH, ':', nn]); state.loopStartHours.value = p.hour!;
state.startHours.value = p.hour!; state.selectEffectiveDate.value = state.loopEffectiveDate.value;
});
}); });
}), }),
CommonItem( CommonItem(
leftTitel: TranslationLoader.lanKeys!.failureTime!.tr, leftTitel: TranslationLoader.lanKeys!.failureTime!.tr,
rightTitle: state.selectFailureDate.value, rightTitle: state.loopFailureDate.value,
isHaveDirection: true, isHaveDirection: true,
action: () { action: () {
Pickers.showDatePicker(context, mode: DateMode.H, onConfirm: (p) { Pickers.showDatePicker(context, mode: DateMode.H, onConfirm: (p) {
setState(() { state.failureDateTime.value =
state.failureDateTime.value = DateTime.parse( DateTime.parse('${intToStr(p.hour!)}:00');
'${state.failureDateTime.value.year}-${intToStr(state.failureDateTime.value.month)}-${intToStr(state.failureDateTime.value.day)} ${intToStr(p.hour!)}:${intToStr(p.minute!)}'); state.loopEffectiveDate.value =
state.selectFailureDate.value = "${formatDate(state.failureDateTime.value, [HH])}:00";
formatDate(state.failureDateTime.value, [HH, ':', nn]); state.loopEndHours.value = p.hour!;
state.endHours.value = p.hour!; state.selectFailureDate.value = state.loopFailureDate.value;
});
}); });
}), }),
], ],
@ -370,12 +322,8 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
Pickers.showSinglePicker(context, Pickers.showSinglePicker(context,
data: dataList, data: dataList,
pickerStyle: DefaultPickerStyle(), onConfirm: (p, position) { pickerStyle: DefaultPickerStyle(), onConfirm: (p, position) {
setState(() { state.loopModeStr.value = p;
state.cyclicModeStr.value = p; }, onChanged: (p, position) {});
});
}, onChanged: (p, position) {
setState(() {});
});
} }
Widget keyBottomWidget(String tipStr) { Widget keyBottomWidget(String tipStr) {
@ -401,46 +349,45 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
SubmitBtn( SubmitBtn(
btnName: TranslationLoader.lanKeys!.getPassword!.tr, btnName: TranslationLoader.lanKeys!.getPassword!.tr,
onClick: () async { 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); var isDemoMode = await Storage.getBool(ifIsDemoModeOrNot);
if (isDemoMode == false) { if (isDemoMode == false) {
if (state.nameController.text.isNotEmpty) { int getWidgetNumber = int.parse(widget.type);
logic.getStartDate(state.effectiveDateTime.value); if (state.nameController.text.isEmpty) {
int passwordType = int.parse(state.widgetType.value); Toast.show(msg: '请输入姓名');
if (passwordType == 3) { return;
if (state.pwdController.text.isNotEmpty) {
//
logic.addKeyboardPwdRequest();
} else {
Toast.show(msg: '请输入密码');
}
} else {
logic.getKeyboardPwdRequest();
}
} else {
Toast.show(msg: '请给密码命名');
} }
//||
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 { } else {
Toast.show(msg: '演示模式'); Toast.show(msg: '演示模式');
} }
@ -548,16 +495,14 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
); );
} }
CupertinoSwitch _switch() { _switch() {
return CupertinoSwitch( return CupertinoSwitch(
activeColor: CupertinoColors.activeBlue, activeColor: CupertinoColors.activeBlue,
trackColor: CupertinoColors.systemGrey5, trackColor: CupertinoColors.systemGrey5,
thumbColor: CupertinoColors.white, thumbColor: CupertinoColors.white,
value: state.isPermanent.value, value: state.isPermanent.value,
onChanged: (value) { onChanged: (value) {
setState(() { state.isPermanent.value = value;
state.isPermanent.value = value;
});
}, },
); );
} }

View File

@ -1,3 +1,4 @@
import 'package:date_format/date_format.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/main/lockMian/entity/lockListInfo_entity.dart'; import 'package:star_lock/main/lockMian/entity/lockListInfo_entity.dart';
@ -6,19 +7,42 @@ class PasswordKeyPerpetualState {
final TextEditingController nameController = TextEditingController(); final TextEditingController nameController = TextEditingController();
final TextEditingController pwdController = TextEditingController(); final TextEditingController pwdController = TextEditingController();
final isInitialized = false.obs;
final isSendSuccess = false.obs; // final isSendSuccess = false.obs; //
final isPermanent = false.obs; // final isPermanent = false.obs; //
var getPwdStr = ''.obs; var getPwdStr = ''.obs;
var selectEffectiveDate = ''.obs; //
var selectFailureDate = ''.obs; //
DateTime dateTime = DateTime.now();
final effectiveDateTime = DateTime.now().obs; final effectiveDateTime = DateTime.now().obs;
final failureDateTime = DateTime.now().obs; final failureDateTime = DateTime.now().obs;
var cyclicModeStr = ''.obs; //
var effectiveHourStr = ''.obs; var selectEffectiveDate = "${formatDate(DateTime.now(), [
var failureHourStr = ''.obs; yyyy,
var startHours = 0.obs; '-',
var endHours = 0.obs; 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 widgetType = ''.obs;
final keyInfo = LockListInfoItemEntity().obs; final keyInfo = LockListInfoItemEntity().obs;
} }