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

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) {
//
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('获取密码成功');

View File

@ -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<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
//
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<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
}),
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<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
);
}
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;
},
);
}

View File

@ -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;
}