diff --git a/star_lock/lib/main/lockDetail/card/addCardType/addCardType_page.dart b/star_lock/lib/main/lockDetail/card/addCardType/addCardType_page.dart index 3c6c2829..e57b5e14 100644 --- a/star_lock/lib/main/lockDetail/card/addCardType/addCardType_page.dart +++ b/star_lock/lib/main/lockDetail/card/addCardType/addCardType_page.dart @@ -1,4 +1,3 @@ - import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -42,7 +41,7 @@ class _AddCardPageState extends State { Widget build(BuildContext context) { state.selectType.value = widget.selectType; state.lockId.value = widget.lockId; - if(widget.fromTypeTwoStaffName.isNotEmpty){ + if (widget.fromTypeTwoStaffName.isNotEmpty) { state.nameController.text = widget.fromTypeTwoStaffName; } state.fromType.value = widget.fromType; @@ -56,12 +55,14 @@ class _AddCardPageState extends State { super.initState(); WidgetsBinding.instance.addPostFrameCallback((_) { - if(state.selectType.value == "1"){ - state.beginTime.value = DateTool().dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString()); //默认为当前时间 - state.endTime.value = DateTool().dateToYMDHNString(DateTime.now().millisecondsSinceEpoch.toString());//默认为当前时间 - }else{ + if (state.selectType.value == "1") { + state.beginTime.value = DateTool().dateToYMDHNString( + DateTime.now().millisecondsSinceEpoch.toString()); //默认为当前时间 + state.endTime.value = DateTool().dateToYMDHNString( + DateTime.now().millisecondsSinceEpoch.toString()); //默认为当前时间 + } else { state.beginTime.value = ""; //默认为当前时间 - state.endTime.value = "";//默认为当前时间 + state.endTime.value = ""; //默认为当前时间 } }); } @@ -141,7 +142,8 @@ class _AddCardPageState extends State { isHaveLine: true, isHaveDirection: true, action: () async { - Pickers.showDatePicker(context, mode: DateMode.YMDHM, onConfirm: (p) { + Pickers.showDatePicker(context, mode: DateMode.YMDHM, + onConfirm: (p) { state.beginTime.value = DateTool().getYMDHNDateString(p, 1); }); })), @@ -150,7 +152,8 @@ class _AddCardPageState extends State { rightTitle: state.endTime.value, isHaveDirection: true, action: () { - Pickers.showDatePicker(context, mode: DateMode.YMDHM, onConfirm: (p) { + Pickers.showDatePicker(context, mode: DateMode.YMDHM, + onConfirm: (p) { state.endTime.value = DateTool().getYMDHNDateString(p, 1); }); })), @@ -160,7 +163,7 @@ class _AddCardPageState extends State { } // 循环顶部选择日期 - Widget keyCyclicDate(){ + Widget keyCyclicDate() { return Column( children: [ Obx(() => CommonItem( @@ -169,21 +172,22 @@ class _AddCardPageState extends State { isHaveDirection: true, isHaveLine: true, action: () async { - var result = await Get.toNamed(Routers.seletKeyCyclicDatePage, - arguments: { - 'validityValue': state.weekdaysList.value, - 'starDate': state.beginTime.value, - 'endDate': state.endTime.value, - 'starTime': state.effectiveDateTime.value, - 'endTime': state.failureDateTime.value - }); - if(result != null && result.isNotEmpty){ + var result = + await Get.toNamed(Routers.seletKeyCyclicDatePage, arguments: { + 'validityValue': state.weekdaysList.value, + 'starDate': state.beginTime.value, + 'endDate': state.endTime.value, + 'starTime': state.effectiveDateTime.value, + 'endTime': state.failureDateTime.value + }); + if (result != null && result.isNotEmpty) { state.weekdaysList.value = result['validityValue']; state.beginTime.value = result['starDate']; state.endTime.value = result['endDate']; state.effectiveDateTime.value = result['starTime']; state.failureDateTime.value = result['endTime']; - Get.log('得到的有效期数据:${state.weekdaysList.value} == ${state.beginTime.value} == ${state.endTime.value}== ${state.effectiveDateTime.value} == ${state.failureDateTime.value}'); + Get.log( + '得到的有效期数据:${state.weekdaysList.value} == ${state.beginTime.value} == ${state.endTime.value}== ${state.effectiveDateTime.value} == ${state.failureDateTime.value}'); } })), Obx(() => Visibility( @@ -202,20 +206,20 @@ class _AddCardPageState extends State { 'starTime': state.effectiveDateTime.value, 'endTime': state.failureDateTime.value }); - if(result != null && result.isNotEmpty){ + if (result != null && result.isNotEmpty) { state.weekdaysList.value = result['validityValue']; state.beginTime.value = result['starDate']; state.endTime.value = result['endDate']; state.effectiveDateTime.value = result['starTime']; state.failureDateTime.value = result['endTime']; } - }) - )), + }))), Obx(() => Visibility( visible: state.effectiveDateTime.value.isNotEmpty, child: CommonItem( leftTitel: "有效时间".tr, - rightTitle: "${state.effectiveDateTime.value}-${state.failureDateTime.value}", + rightTitle: + "${state.effectiveDateTime.value}-${state.failureDateTime.value}", isHaveDirection: true, action: () async { var result = await Get.toNamed(Routers.seletKeyCyclicDatePage, @@ -226,7 +230,7 @@ class _AddCardPageState extends State { 'starTime': state.effectiveDateTime.value, 'endTime': state.failureDateTime.value }); - if(result != null && result.isNotEmpty){ + if (result != null && result.isNotEmpty) { state.weekdaysList.value = result['validityValue']; state.beginTime.value = result['starDate']; state.endTime.value = result['endDate']; @@ -234,8 +238,7 @@ class _AddCardPageState extends State { state.failureDateTime.value = result['endTime']; Get.back(result: result); } - }) - )), + }))), ], ); } @@ -248,8 +251,8 @@ class _AddCardPageState extends State { rightTitle: "", isTipsImg: false, isHaveRightWidget: true, - rightWidget: SizedBox( - width: 60.w, height: 50.h, child: _isAdmin()))), + rightWidget: + SizedBox(width: 60.w, height: 50.h, child: _isAdmin()))), SizedBox(height: 10.h), Obx(() => CommonItem( leftTitel: TranslationLoader.lanKeys!.stressCard!.tr, @@ -318,7 +321,8 @@ class _AddCardPageState extends State { FilteringTextInputFormatter.deny('\n'), LengthLimitingTextInputFormatter(18), ], - style: TextStyle(fontSize: 22.sp, color: AppColors.darkGrayTextColor), + style: TextStyle( + fontSize: 22.sp, color: AppColors.darkGrayTextColor), controller: state.nameController, autofocus: false, textAlign: TextAlign.end, @@ -327,10 +331,18 @@ class _AddCardPageState extends State { // contentPadding: const EdgeInsets.only(top: 12.0, bottom: 8.0), hintText: tfStr, hintStyle: TextStyle(fontSize: 22.sp), - focusedBorder: const OutlineInputBorder(borderSide: BorderSide(width: 0, color: Colors.transparent)), - disabledBorder: const OutlineInputBorder(borderSide: BorderSide(width: 0, color: Colors.transparent)), - enabledBorder: const OutlineInputBorder(borderSide: BorderSide(width: 0, color: Colors.transparent)), - border: const OutlineInputBorder(borderSide: BorderSide(width: 0, color: Colors.transparent)), + focusedBorder: const OutlineInputBorder( + borderSide: + BorderSide(width: 0, color: Colors.transparent)), + disabledBorder: const OutlineInputBorder( + borderSide: + BorderSide(width: 0, color: Colors.transparent)), + enabledBorder: const OutlineInputBorder( + borderSide: + BorderSide(width: 0, color: Colors.transparent)), + border: const OutlineInputBorder( + borderSide: + BorderSide(width: 0, color: Colors.transparent)), contentPadding: const EdgeInsets.symmetric(vertical: 0), ), ), @@ -368,5 +380,4 @@ class _AddCardPageState extends State { }, ); } - } diff --git a/star_lock/lib/main/lockDetail/face/addFaceType/addFaceType_logic.dart b/star_lock/lib/main/lockDetail/face/addFaceType/addFaceType_logic.dart index 539e0651..3d66e39a 100644 --- a/star_lock/lib/main/lockDetail/face/addFaceType/addFaceType_logic.dart +++ b/star_lock/lib/main/lockDetail/face/addFaceType/addFaceType_logic.dart @@ -1,6 +1,7 @@ import 'package:get/get.dart'; import 'package:star_lock/main/lockDetail/face/addFaceType/addFaceType_state.dart'; import 'package:star_lock/tools/baseGetXController.dart'; +import 'package:star_lock/tools/dateTool.dart'; import '../../../../appRouters.dart'; import '../../../../network/api_repository.dart'; @@ -12,18 +13,28 @@ class AddFaceTypeLogic extends BaseGetXController { var faceType = 0; // 永久:1;限时2,单次3,循环:4 var startDate = ""; var endDate = ""; - if (state.seletType.value == "0") { + var startTime = ""; + var endTime = ""; + if (state.selectType.value == "0") { faceType = 1; startDate = "0"; endDate = "0"; - } else if (state.seletType.value == "1") { + startTime = "0"; + endTime = "0"; + } else if (state.selectType.value == "1") { faceType = 2; - if (state.beginTimeTimestamp.value.isEmpty) { - showToast("请选择开始时间"); + startDate = + DateTool().dateToTimestamp(state.beginTime.value, 1).toString(); + endDate = DateTool().dateToTimestamp(state.endTime.value, 1).toString(); + startTime = "0"; + endTime = "0"; + + if (startDate.isEmpty) { + showToast("请选择开始时间".tr); return; } - if (state.endTimeTimestamp.value.isEmpty) { - showToast("请选择结束时间"); + if (endDate.isEmpty) { + showToast("请选择结束时间".tr); return; } @@ -32,45 +43,25 @@ class AddFaceTypeLogic extends BaseGetXController { // return; // } - if (int.parse(state.beginTimeTimestamp.value) >= - int.parse(state.endTimeTimestamp.value)) { - showToast("失效时间要大于生效时间"); + if (int.parse(startDate) >= int.parse(endDate)) { + showToast("失效时间要大于生效时间".tr); return; } - - startDate = state.beginTimeTimestamp.value; - endDate = state.endTimeTimestamp.value; - } else if (state.seletType.value == "2") { - if (state.effectiveDateTime.value <= 0) { - showToast("请选择生效时间"); + } else if (state.selectType.value == "2") { + if (state.beginTime.value.isEmpty) { + showToast("请选择有效期".tr); return; } - if (state.failureDateTime.value <= 0) { - showToast("请选择失效时间"); - return; - } - - if (state.weekdaysList.value.isEmpty) { - showToast("请选择有效日"); - return; - } - - // if(DateTime.now().millisecondsSinceEpoch >= state.effectiveDateTime.value){ - // Toast.show(msg: "生效时间要大于当前时间"); - // return; - // } - - if (state.effectiveDateTime.value >= state.failureDateTime.value) { - showToast("失效时间要大于生效时间"); - return; - } - startDate = state.effectiveDateTime.value.toString(); - endDate = state.failureDateTime.value.toString(); + startDate = + DateTool().dateToTimestamp(state.beginTime.value, 1).toString(); + endDate = DateTool().dateToTimestamp(state.endTime.value, 1).toString(); + startTime = DateTool() + .dateToTimestamp(state.effectiveDateTime.value, 0) + .toString(); + endTime = + DateTool().dateToTimestamp(state.failureDateTime.value, 0).toString(); faceType = 4; } - - print( - "传出去的给你限时人脸开始时间:${int.parse(startDate) ~/ 1000} 限时人脸结束时间:${int.parse(endDate) ~/ 1000}"); // 人脸 Get.toNamed(Routers.addFacePage, arguments: { "lockId": state.lockId.value, diff --git a/star_lock/lib/main/lockDetail/face/addFaceType/addFaceType_page.dart b/star_lock/lib/main/lockDetail/face/addFaceType/addFaceType_page.dart index 712113bb..2b3bf38e 100644 --- a/star_lock/lib/main/lockDetail/face/addFaceType/addFaceType_page.dart +++ b/star_lock/lib/main/lockDetail/face/addFaceType/addFaceType_page.dart @@ -1,7 +1,9 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import 'package:star_lock/tools/dateTool.dart'; import 'package:star_lock/tools/pickers/pickers.dart'; import 'package:star_lock/tools/pickers/time_picker/model/date_mode.dart'; @@ -37,9 +39,9 @@ class _AddFaceTypePageState extends State { @override Widget build(BuildContext context) { - state.seletType.value = widget.selectType; + state.selectType.value = widget.selectType; state.lockId.value = widget.lockId; - if(widget.fromTypeTwoStaffName.isNotEmpty){ + if (widget.fromTypeTwoStaffName.isNotEmpty) { state.nameController.text = widget.fromTypeTwoStaffName; } state.fromType.value = widget.fromType; @@ -47,12 +49,29 @@ class _AddFaceTypePageState extends State { return indexChangeWidget(); } + @override + void initState() { + // TODO: implement initState + super.initState(); + + WidgetsBinding.instance.addPostFrameCallback((_) { + if (state.selectType.value == "1") { + state.beginTime.value = DateTool().dateToYMDHNString( + DateTime.now().millisecondsSinceEpoch.toString()); //默认为当前时间 + state.endTime.value = DateTool().dateToYMDHNString( + DateTime.now().millisecondsSinceEpoch.toString()); //默认为当前时间 + } else { + state.beginTime.value = ""; //默认为当前时间 + state.endTime.value = ""; //默认为当前时间 + } + }); + } + Widget indexChangeWidget() { switch (int.parse(widget.selectType)) { case 0: { // 永久 - // return sendElectronicKeySucceed(); return Column( children: [ perpetualKeyWidget( @@ -86,21 +105,7 @@ class _AddFaceTypePageState extends State { TranslationLoader.lanKeys!.name!.tr, TranslationLoader.lanKeys!.pleaseEnter!.tr, state.nameController), - CommonItem( - leftTitel: TranslationLoader.lanKeys!.periodValidity!.tr, - rightTitle: "", - isHaveDirection: true, - action: () async { - Map result = await Get.toNamed( - Routers.electronicKeyPeriodValidityPage); - state.weekdaysList.value = result['validityValue']; - state.effectiveDateTime.value = - result['starDate'].millisecondsSinceEpoch; - state.failureDateTime.value = - result['endDate'].millisecondsSinceEpoch; - print( - '得到的有效期数据:${state.weekdaysList.value} == ${state.effectiveDateTime.value} == ${state.failureDateTime.value}'); - }), + keyCyclicDate(), SizedBox(height: 10.h), keyBottomWidget() ], @@ -139,12 +144,7 @@ class _AddFaceTypePageState extends State { action: () async { Pickers.showDatePicker(context, mode: DateMode.YMDHM, onConfirm: (p) { - state.beginTime.value = - '${p.year}-${p.month!.toString().padLeft(2, '0')}-${p.day!.toString().padLeft(2, '0')} ${p.hour!.toString().padLeft(2, '0')}:${p.minute!.toString().padLeft(2, '0')}'; - state.beginTimeTimestamp.value = - DateTime.parse(state.beginTime.value) - .millisecondsSinceEpoch - .toString(); + state.beginTime.value = DateTool().getYMDHNDateString(p, 1); }); })), Obx(() => CommonItem( @@ -154,12 +154,7 @@ class _AddFaceTypePageState extends State { action: () { Pickers.showDatePicker(context, mode: DateMode.YMDHM, onConfirm: (p) { - state.endTime.value = - '${p.year}-${p.month!.toString().padLeft(2, '0')}-${p.day!.toString().padLeft(2, '0')} ${p.hour!.toString().padLeft(2, '0')}:${p.minute!.toString().padLeft(2, '0')}'; - state.endTimeTimestamp.value = - DateTime.parse(state.endTime.value) - .millisecondsSinceEpoch - .toString(); + state.endTime.value = DateTool().getYMDHNDateString(p, 1); }); })), Container(height: 10.h), @@ -167,16 +162,90 @@ class _AddFaceTypePageState extends State { ); } + // 循环顶部选择日期 + Widget keyCyclicDate() { + return Column( + children: [ + Obx(() => CommonItem( + leftTitel: TranslationLoader.lanKeys!.periodValidity!.tr, + rightTitle: "${state.beginTime.value}\n${state.endTime.value}", + isHaveDirection: true, + isHaveLine: true, + action: () async { + var result = + await Get.toNamed(Routers.seletKeyCyclicDatePage, arguments: { + 'validityValue': state.weekdaysList.value, + 'starDate': state.beginTime.value, + 'endDate': state.endTime.value, + 'starTime': state.effectiveDateTime.value, + 'endTime': state.failureDateTime.value + }); + if (result != null && result.isNotEmpty) { + state.weekdaysList.value = result['validityValue']; + state.beginTime.value = result['starDate']; + state.endTime.value = result['endDate']; + state.effectiveDateTime.value = result['starTime']; + state.failureDateTime.value = result['endTime']; + Get.log( + '得到的有效期数据:${state.weekdaysList.value} == ${state.beginTime.value} == ${state.endTime.value}== ${state.effectiveDateTime.value} == ${state.failureDateTime.value}'); + } + })), + Obx(() => Visibility( + visible: state.weekdaysList.isNotEmpty ? true : false, + child: CommonItem( + leftTitel: "有效日", + rightTitle: state.weekdaysList.value.join(",").toString(), + isHaveDirection: true, + isHaveLine: true, + action: () async { + var result = await Get.toNamed(Routers.seletKeyCyclicDatePage, + arguments: { + 'validityValue': state.weekdaysList.value, + 'starDate': state.beginTime.value, + 'endDate': state.endTime.value, + 'starTime': state.effectiveDateTime.value, + 'endTime': state.failureDateTime.value + }); + if (result != null && result.isNotEmpty) { + state.weekdaysList.value = result['validityValue']; + state.beginTime.value = result['starDate']; + state.endTime.value = result['endDate']; + state.effectiveDateTime.value = result['starTime']; + state.failureDateTime.value = result['endTime']; + } + }))), + Obx(() => Visibility( + visible: state.effectiveDateTime.value.isNotEmpty, + child: CommonItem( + leftTitel: "有效时间".tr, + rightTitle: + "${state.effectiveDateTime.value}-${state.failureDateTime.value}", + isHaveDirection: true, + action: () async { + var result = await Get.toNamed(Routers.seletKeyCyclicDatePage, + arguments: { + 'validityValue': state.weekdaysList.value, + 'starDate': state.beginTime.value, + 'endDate': state.endTime.value, + 'starTime': state.effectiveDateTime.value, + 'endTime': state.failureDateTime.value + }); + if (result != null && result.isNotEmpty) { + state.weekdaysList.value = result['validityValue']; + state.beginTime.value = result['starDate']; + state.endTime.value = result['endDate']; + state.effectiveDateTime.value = result['starTime']; + state.failureDateTime.value = result['endTime']; + Get.back(result: result); + } + }))), + ], + ); + } + Widget keyBottomWidget() { return Column( children: [ - // CommonItem( - // leftTitel: TranslationLoader.lanKeys!.face!.tr, - // rightTitle: "", - // isTipsImg: false, - // isHaveRightWidget: true, - // rightWidget: SizedBox( - // width: 60.w, height: 50.h, child: _isStressFingerprint())), CommonItem( leftTitel: "是否是管理员", rightTitle: "", @@ -205,97 +274,48 @@ class _AddFaceTypePageState extends State { ); } - // 发送电子钥匙成功 - Widget sendElectronicKeySucceed() { - return Column( - children: [ - Container( - height: 300.h, - width: 1.sw, - color: Colors.white, - child: Column( - children: [ - SizedBox( - height: 30.h, - ), - Image.asset( - 'images/main/icon_main_addLock.png', - width: 150.w, - height: 150.w, - color: AppColors.mainColor, - ), - SizedBox( - height: 20.h, - ), - Text( - "操作成功,密码为", - style: TextStyle( - fontSize: 32.sp, - color: Colors.black, - fontWeight: FontWeight.w500), - ), - SizedBox( - height: 10.h, - ), - Text( - "62689876", - style: TextStyle( - fontSize: 60.sp, - color: Colors.black, - fontWeight: FontWeight.w500), - ), - ], - ), - ), - SizedBox( - height: 20.h, - ), - SubmitBtn( - btnName: '完成'.tr, - fontSize: 28.sp, - borderRadius: 20.w, - margin: EdgeInsets.only(left: 30.w, right: 30.w, top: 30.w), - padding: EdgeInsets.only(top: 25.w, bottom: 25.w), - onClick: () {}), - SubmitBtn( - btnName: '分享', - fontSize: 28.sp, - borderRadius: 20.w, - margin: EdgeInsets.only(left: 30.w, right: 30.w, top: 30.w), - padding: EdgeInsets.only(top: 25.w, bottom: 25.w), - onClick: () {}), - SubmitBtn( - btnName: '标记为:已入住', - fontSize: 28.sp, - borderRadius: 20.w, - margin: EdgeInsets.only(left: 30.w, right: 30.w, top: 30.w), - padding: EdgeInsets.only(top: 25.w, bottom: 25.w), - onClick: () {}), - ], - ); - } - // 接受者信息输入框 Widget getTFWidget(String tfStr) { return Container( - height: 50.h, + // color: Colors.red, + height: 65.h, width: 300.w, + padding: EdgeInsets.only(top: 5.h), child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, children: [ Expanded( child: TextField( //输入框一行 maxLines: 1, + inputFormatters: [ + FilteringTextInputFormatter.deny('\n'), + LengthLimitingTextInputFormatter(18), + ], + style: TextStyle( + fontSize: 22.sp, color: AppColors.darkGrayTextColor), controller: state.nameController, autofocus: false, textAlign: TextAlign.end, decoration: InputDecoration( //输入里面输入文字内边距设置 - contentPadding: const EdgeInsets.only(top: 12.0, bottom: 8.0), + // contentPadding: const EdgeInsets.only(top: 12.0, bottom: 8.0), hintText: tfStr, - hintStyle: TextStyle(fontSize: 24.sp), - //不需要输入框下划线 - border: InputBorder.none, + hintStyle: TextStyle(fontSize: 22.sp), + focusedBorder: const OutlineInputBorder( + borderSide: + BorderSide(width: 0, color: Colors.transparent)), + disabledBorder: const OutlineInputBorder( + borderSide: + BorderSide(width: 0, color: Colors.transparent)), + enabledBorder: const OutlineInputBorder( + borderSide: + BorderSide(width: 0, color: Colors.transparent)), + border: const OutlineInputBorder( + borderSide: + BorderSide(width: 0, color: Colors.transparent)), + contentPadding: const EdgeInsets.symmetric(vertical: 0), ), ), ), diff --git a/star_lock/lib/main/lockDetail/face/addFaceType/addFaceType_state.dart b/star_lock/lib/main/lockDetail/face/addFaceType/addFaceType_state.dart index 412ed2d0..3ee24ba5 100644 --- a/star_lock/lib/main/lockDetail/face/addFaceType/addFaceType_state.dart +++ b/star_lock/lib/main/lockDetail/face/addFaceType/addFaceType_state.dart @@ -3,7 +3,7 @@ import 'package:get/get.dart'; class AddFaceTypeState { final lockId = 0.obs; - final seletType = "0".obs; // 0永久 1显示 2循环 + final selectType = "0".obs; // 0永久 1显示 2循环 final fromType = 1.obs; // // 1从添加钥匙列表进入 2从考勤添加员工入口进入 var fromTypeTwoStaffName = "".obs; // 考勤添加人脸员工名字 final isStressFingerprint = false.obs; @@ -11,11 +11,8 @@ class AddFaceTypeState { var beginTime = "".obs; // 开始时间 var endTime = "".obs; // 结束时间 - var beginTimeTimestamp = "".obs; // 开始时间时间戳 - var endTimeTimestamp = "".obs; // 结束时间时间戳 - - var effectiveDateTime = 0.obs; // 生效时间 - var failureDateTime = 0.obs; // 失效时间 + var effectiveDateTime = "".obs; // 生效时间 + var failureDateTime = "".obs; // 失效时间 var weekdaysList = [].obs; final TextEditingController nameController = TextEditingController();