1,修复发送电子钥匙及密码模块部分输入框格式问题

2,修复发送电子钥匙-循环类型页面报红问题
3,修复不能给邮箱发送电子钥匙问题
This commit is contained in:
Daisy 2023-12-12 15:57:30 +08:00
parent 1a8d726e2f
commit 3cfceece5b
10 changed files with 599 additions and 408 deletions

View File

@ -85,10 +85,11 @@ class _ElectronicKeyListPageState extends State<ElectronicKeyListPage> {
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<ElectronicKeyListPage> {
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<ElectronicKeyListPage> {
),
),
),
style:
TextStyle(fontSize: 22.sp, textBaseline: TextBaseline.alphabetic),
),
);
}
@ -201,14 +204,14 @@ class _ElectronicKeyListPageState extends State<ElectronicKeyListPage> {
),
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();

View File

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

View File

@ -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<ElectronicKeyPeriodValidityPage> {
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<ElectronicKeyPeriodValidityLogic>().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<String, dynamic> 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<String, dynamic> resultMap = {};
resultMap['validityValue'] = state.selectIndexList.value;
resultMap['starDate'] = state.effectiveDateTime.value;
resultMap['endDate'] = state.failureDateTime.value;
Navigator.pop(context, resultMap);
}
})),
],
);
}

View File

@ -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 = <ElectronicKeyListItem>[].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;
}

View File

@ -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<void> 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);
},
),
],
);
},
);
}
}

View File

@ -217,11 +217,9 @@ class _SendElectronicKeyPageState extends State<SendElectronicKeyPage> {
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<SendElectronicKeyPage> {
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<SendElectronicKeyPage> {
//线
border: InputBorder.none,
),
style: TextStyle(
fontSize: 22.sp, textBaseline: TextBaseline.alphabetic),
),
),
SizedBox(

View File

@ -86,9 +86,7 @@ class _PasswordKeyListPageState extends State<PasswordKeyListPage> {
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<PasswordKeyListPage> {
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<PasswordKeyListPage> {
),
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<PasswordKeyListPage> {
);
}
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<PasswordKeyListPage> {
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();
},
);
}
);
});
}
//使

View File

@ -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<void> 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<void> 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;
//

View File

@ -35,23 +35,23 @@ class PasswordKeyPerpetualPage extends StatefulWidget {
}
class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
final TextEditingController _nameController = TextEditingController();
final TextEditingController _pwdController = TextEditingController();
final logic = Get.put(PasswordKeyPerpetualLogic());
final state = Get.find<PasswordKeyPerpetualLogic>().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<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
//
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<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
//
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<String> 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<String> 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<PasswordKeyPerpetualPage> {
*/
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<PasswordKeyPerpetualPage> {
);
}
/**
1 6使
2 24使
3 24使
4 使使
5
6
7
8
9
10
11
12
13
14
*/
//
Future<void> 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<void> 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<PasswordKeyPerpetualPage> {
height: 10.h,
),
Text(
_getPwdStr,
state.getPwdStr.value,
style: TextStyle(
fontSize: 40.sp,
color: Colors.black,
@ -599,7 +493,7 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
SubmitBtn(
btnName: '完成',
onClick: () {
_isSendSuccess = false;
state.isSendSuccess.value = false;
Navigator.pop(context, true);
}),
SizedBox(
@ -659,10 +553,10 @@ class _PasswordKeyPerpetualPageState extends State<PasswordKeyPerpetualPage> {
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<PasswordKeyPerpetualPage> {
case 0:
//
{
String pwdShareStr = '您好,您的密码是:$_getPwdStr';
String pwdShareStr = '您好,您的密码是:${state.getPwdStr.value}';
tokNative('flutter_sharePassword_to_ios',
arguments: {'pwdShareStr': pwdShareStr}).then((result) {
print('$result');

View File

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