This commit is contained in:
魏少阳 2024-04-24 13:39:52 +08:00
commit 1740eeadaf
12 changed files with 293 additions and 87 deletions

View File

@ -771,5 +771,6 @@
"邮件提醒":"Email reminder", "邮件提醒":"Email reminder",
"关锁":"关锁", "关锁":"关锁",
"功能":"功能", "功能":"功能",
"配件":"配件" "配件":"配件",
"N天未开门提醒":"N days did not open the door reminder"
} }

View File

@ -770,5 +770,6 @@
"邮件提醒":"邮件提醒", "邮件提醒":"邮件提醒",
"关锁":"Close Lock", "关锁":"Close Lock",
"功能":"Function", "功能":"Function",
"配件":"Parts" "配件":"Parts",
"N天未开门提醒":"N天未开门提醒"
} }

View File

@ -773,5 +773,6 @@
"邮件提醒":"邮件提醒", "邮件提醒":"邮件提醒",
"关锁":"关锁", "关锁":"关锁",
"功能":"功能", "功能":"功能",
"配件":"配件" "配件":"配件",
"N天未开门提醒":"N天未开门提醒"
} }

View File

@ -1,3 +1,5 @@
import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart';
class MsgNotificationEntity { class MsgNotificationEntity {
int? errorCode; int? errorCode;
String? description; String? description;
@ -27,21 +29,19 @@ class MsgNotificationEntity {
} }
class MsgNoticeData { class MsgNoticeData {
List? openDoorNoticeList;
int? dayNotOpenDoorState; int? dayNotOpenDoorState;
int? dayNotOpenDoorValue; int? dayNotOpenDoorValue;
List? dayNotOpenDoorNoticeWayList; List<NoticeWay>? dayNotOpenDoorNoticeWayList;
int? doorNotCloseState; int? doorNotCloseState;
int? tamperAlarmState; int? tamperAlarmState;
int? lowElecNoticeState; int? lowElecNoticeState;
List<void>? lowElecNoticeWayList; List? lowElecNoticeWayList;
List<void>? coercionOpenDoorNoticeList; List? coercionOpenDoorNoticeList;
int? doorbellNoticeState; int? doorbellNoticeState;
int? someoneAtDoorNoticeState; int? someoneAtDoorNoticeState;
MsgNoticeData( MsgNoticeData(
{this.openDoorNoticeList, {this.dayNotOpenDoorState,
this.dayNotOpenDoorState,
this.dayNotOpenDoorValue, this.dayNotOpenDoorValue,
this.dayNotOpenDoorNoticeWayList, this.dayNotOpenDoorNoticeWayList,
this.doorNotCloseState, this.doorNotCloseState,
@ -53,18 +53,12 @@ class MsgNoticeData {
this.someoneAtDoorNoticeState}); this.someoneAtDoorNoticeState});
MsgNoticeData.fromJson(Map<String, dynamic> json) { MsgNoticeData.fromJson(Map<String, dynamic> json) {
if (json['openDoorNoticeList'] != null) {
openDoorNoticeList = [];
json['openDoorNoticeList'].forEach((v) {
openDoorNoticeList!.add(v);
});
}
dayNotOpenDoorState = json['dayNotOpenDoorState']; dayNotOpenDoorState = json['dayNotOpenDoorState'];
dayNotOpenDoorValue = json['dayNotOpenDoorValue']; dayNotOpenDoorValue = json['dayNotOpenDoorValue'];
if (json['dayNotOpenDoorNoticeWayList'] != null) { if (json['dayNotOpenDoorNoticeWayList'] != null) {
dayNotOpenDoorNoticeWayList = []; dayNotOpenDoorNoticeWayList = <NoticeWay>[];
json['dayNotOpenDoorNoticeWayList'].forEach((v) { json['dayNotOpenDoorNoticeWayList'].forEach((v) {
dayNotOpenDoorNoticeWayList!.add(v); dayNotOpenDoorNoticeWayList!.add(NoticeWay.fromJson(v));
}); });
} }
doorNotCloseState = json['doorNotCloseState']; doorNotCloseState = json['doorNotCloseState'];
@ -88,10 +82,6 @@ class MsgNoticeData {
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{}; final Map<String, dynamic> data = <String, dynamic>{};
if (openDoorNoticeList != null) {
data['openDoorNoticeList'] =
openDoorNoticeList!.map((v) => v.toJson()).toList();
}
data['dayNotOpenDoorState'] = dayNotOpenDoorState; data['dayNotOpenDoorState'] = dayNotOpenDoorState;
data['dayNotOpenDoorValue'] = dayNotOpenDoorValue; data['dayNotOpenDoorValue'] = dayNotOpenDoorValue;
if (dayNotOpenDoorNoticeWayList != null) { if (dayNotOpenDoorNoticeWayList != null) {
@ -103,11 +93,11 @@ class MsgNoticeData {
data['lowElecNoticeState'] = lowElecNoticeState; data['lowElecNoticeState'] = lowElecNoticeState;
if (lowElecNoticeWayList != null) { if (lowElecNoticeWayList != null) {
data['lowElecNoticeWayList'] = data['lowElecNoticeWayList'] =
lowElecNoticeWayList!.map((v) => v).toList(); lowElecNoticeWayList!.map((v) => v.toJson()).toList();
} }
if (coercionOpenDoorNoticeList != null) { if (coercionOpenDoorNoticeList != null) {
data['coercionOpenDoorNoticeList'] = data['coercionOpenDoorNoticeList'] =
coercionOpenDoorNoticeList!.map((v) => v).toList(); coercionOpenDoorNoticeList!.map((v) => v.toJson()).toList();
} }
data['doorbellNoticeState'] = doorbellNoticeState; data['doorbellNoticeState'] = doorbellNoticeState;
data['someoneAtDoorNoticeState'] = someoneAtDoorNoticeState; data['someoneAtDoorNoticeState'] = someoneAtDoorNoticeState;

View File

@ -89,7 +89,14 @@ class _MsgNotificationPageState extends State<MsgNotificationPage> {
isHaveLine: true, isHaveLine: true,
isHaveDirection: true, isHaveDirection: true,
action: () { action: () {
Get.toNamed(Routers.nDaysUnopenedPage); Get.toNamed(Routers.nDaysUnopenedPage, arguments: {
'lockSetInfoData': state.msgNoticeInfo.value,
'lockId': state.getLockId.value
})?.then((value) {
if (value != null) {
logic.getLockNoticeSetting();
}
});
}, },
)), )),
// SizedBox( // SizedBox(

View File

@ -1,7 +1,120 @@
import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart';
import 'package:star_lock/main/lockDetail/messageWarn/notificationMode/notificationMode_data.dart';
import 'package:star_lock/network/api_repository.dart';
import 'package:star_lock/tools/baseGetXController.dart'; import 'package:star_lock/tools/baseGetXController.dart';
import 'nDaysUnopened_state.dart'; import 'nDaysUnopened_state.dart';
class NDaysUnopenedLogic extends BaseGetXController { class NDaysUnopenedLogic extends BaseGetXController {
NDaysUnopenedState state = NDaysUnopenedState(); NDaysUnopenedState state = NDaysUnopenedState();
void lockNoticeSettingAccountList() async {
var entity = await ApiRepository.to.updateNdaysNotCloseDoorNoticeSetting(
lockId: state.getLockId.value,
dayNotOpenDoorState: state.isUnOpenNotice.value == true ? 1 : 0,
dayNotOpenDoorValue: state.unOpenDoorTime.value,
dayNotOpenDoorNoticeWayList: [
{'type': 'mail', 'accounts': getEmailAndSMSAccountList(true)},
{'type': 'sms', 'accounts': getEmailAndSMSAccountList(false)}
]);
if (entity.errorCode!.codeIsSuccessful) {
showToast('设置成功'.tr);
Get.back(result: true);
}
}
//
List getEmailAndSMSAccountList(bool isEmail) {
List list = [];
List accountList = [];
isEmail
? accountList = state.emailReceiverList.value
: accountList = state.phoneReceiverList.value;
for (int i = 0; i < accountList.length; i++) {
MsgNoticeModeData item = accountList[i];
Map map = {};
map['countryCode'] = isEmail ? 0 : item.countryCode;
map['account'] = isEmail ? item.receiveEmail : item.receivePhone;
list.add(map);
}
return list;
}
String getEmailListStr(Map val) {
String emailListStr = '';
if (val['emailReceiverList'] != null) {
state.emailReceiverList.value = val['emailReceiverList'];
List emailReceiverList = state.emailReceiverList.value;
for (int i = 0; i < emailReceiverList.length; i++) {
MsgNoticeModeData item = emailReceiverList[i];
emailListStr += item.receiveEmail;
//
if (i < emailReceiverList.length - 1) {
emailListStr += ',';
}
}
}
return emailListStr;
}
String getPhoneListStr(Map val) {
String phoneListStr = '';
if (val['phoneReceiverList'] != null) {
state.phoneReceiverList.value = val['phoneReceiverList'];
List phoneReceiverList = state.phoneReceiverList.value;
for (int i = 0; i < phoneReceiverList.length; i++) {
MsgNoticeModeData item = phoneReceiverList[i];
phoneListStr += item.receivePhone;
//
if (i < phoneReceiverList.length - 1) {
phoneListStr += ',';
}
}
}
return phoneListStr;
}
//
Map<String, List<MsgNoticeModeData>> getAccountsMap() {
List<MsgNoticeModeData> mailAccounts = [];
List<MsgNoticeModeData> smsAccounts = [];
if (state.msgNoticeInfo.value.dayNotOpenDoorNoticeWayList != null) {
for (NoticeWay item
in state.msgNoticeInfo.value.dayNotOpenDoorNoticeWayList!) {
if (item.type == 'mail' && item.accounts != null) {
for (Accounts account in item.accounts!) {
if (account.account != null) {
MsgNoticeModeData msgNoticeModeData = MsgNoticeModeData();
msgNoticeModeData.receiveEmail = account.account!;
mailAccounts.add(msgNoticeModeData);
}
}
} else if (item.type == 'sms' && item.accounts != null) {
for (Accounts account in item.accounts!) {
if (account.account != null && account.countryCode != null) {
MsgNoticeModeData msgNoticeModeData = MsgNoticeModeData();
msgNoticeModeData.receivePhone = account.account!;
msgNoticeModeData.countryCode = account.countryCode!;
smsAccounts.add(msgNoticeModeData);
}
}
}
}
}
return {
'emailReceiverList': mailAccounts,
'phoneReceiverList': smsAccounts,
};
}
@override
onInit() {
super.onInit();
state.emailListStr.value = getEmailListStr(getAccountsMap());
state.phontListStr.value = getPhoneListStr(getAccountsMap());
}
} }

View File

@ -1,10 +1,9 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
// import 'package:flutter_pickers/pickers.dart';
// import 'package:flutter_pickers/style/default_style.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/appRouters.dart'; import 'package:star_lock/appRouters.dart';
import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart';
import 'package:star_lock/tools/commonItem.dart'; import 'package:star_lock/tools/commonItem.dart';
import 'package:star_lock/tools/pickers/pickers.dart'; import 'package:star_lock/tools/pickers/pickers.dart';
import 'package:star_lock/tools/pickers/style/default_style.dart'; import 'package:star_lock/tools/pickers/style/default_style.dart';
@ -30,7 +29,7 @@ class _NDaysUnopenedPageState extends State<NDaysUnopenedPage> {
return Scaffold( return Scaffold(
backgroundColor: AppColors.mainBackgroundColor, backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar( appBar: TitleAppBar(
barTitle: 'N天未开门', barTitle: 'N天未开门'.tr,
haveBack: true, haveBack: true,
backgroundColor: AppColors.mainColor), backgroundColor: AppColors.mainColor),
body: Container( body: Container(
@ -52,7 +51,7 @@ class _NDaysUnopenedPageState extends State<NDaysUnopenedPage> {
height: 20.h, height: 20.h,
), ),
CommonItem( CommonItem(
leftTitel: 'N天未开门提醒', leftTitel: 'N天未开门提醒'.tr,
rightTitle: '', rightTitle: '',
isHaveLine: true, isHaveLine: true,
isHaveDirection: false, isHaveDirection: false,
@ -60,12 +59,12 @@ class _NDaysUnopenedPageState extends State<NDaysUnopenedPage> {
rightWidget: _unOpenDoorSwitch(), rightWidget: _unOpenDoorSwitch(),
action: () {}), action: () {}),
Visibility( Visibility(
visible: state.isunOpenNotice.value, visible: state.isUnOpenNotice.value,
child: Column( child: Column(
children: [ children: [
Obx(() => CommonItem( Obx(() => CommonItem(
leftTitel: '门未开时间', leftTitel: '门未开时间',
rightTitle: state.unOpenDoorTime.value, rightTitle: '${state.unOpenDoorTime.value}',
isHaveLine: true, isHaveLine: true,
isHaveRightWidget: false, isHaveRightWidget: false,
isHaveDirection: true, isHaveDirection: true,
@ -77,41 +76,46 @@ class _NDaysUnopenedPageState extends State<NDaysUnopenedPage> {
SizedBox( SizedBox(
height: 20.h, height: 20.h,
), ),
Container( GestureDetector(
color: Colors.white, onTap: () {
margin: EdgeInsets.only(bottom: 10.h), Get.toNamed(Routers.notificationModePage, arguments: {
child: Column( 'msgNoticeInfo': state.msgNoticeInfo.value
children: [ })?.then((val) {
CommonItem( if (val != null) {
leftTitel: '提醒方式'.tr, state.emailListStr.value =
rightTitle: "", logic.getEmailListStr(val);
isHaveLine: false, state.phontListStr.value =
isHaveRightWidget: false, logic.getPhoneListStr(val);
isHaveDirection: true, print(
action: () { 'emailListStr:${state.emailListStr.value},phontListStr:${state.phontListStr.value}');
Get.toNamed(Routers.notificationModePage); }
}, });
), },
Container( child: Container(
padding: EdgeInsets.only( color: Colors.white,
left: 10.w, margin: EdgeInsets.only(bottom: 10.h),
right: 10.w, child: Column(
top: 12.h, children: [
bottom: 12.h), CommonItem(
margin: EdgeInsets.only(bottom: 20.h, top: 10.h), leftTitel: '提醒方式'.tr,
decoration: BoxDecoration( rightTitle: "",
color: AppColors.mainBackgroundColor, isHaveLine: false,
borderRadius: BorderRadius.circular(6.0.w), isHaveRightWidget: false,
isHaveDirection: true,
), ),
child: Text( _buildNotifyContain('APP推送'.tr, '管理员'.tr),
'APP推送 管理员', Obx(() => state.emailListStr.value.isNotEmpty
style: TextStyle( ? _buildNotifyContain(
color: Colors.black, fontSize: 20.sp), '邮件提醒'.tr, state.emailListStr.value)
), : Container()),
) Obx(() => state.phontListStr.value.isNotEmpty
], ? _buildNotifyContain(
'短信提醒'.tr, state.phontListStr.value)
: Container()),
],
),
), ),
) ),
], ],
)), )),
Expanded( Expanded(
@ -120,7 +124,9 @@ class _NDaysUnopenedPageState extends State<NDaysUnopenedPage> {
)), )),
SubmitBtn( SubmitBtn(
btnName: '保存', btnName: '保存',
onClick: () {}, onClick: () {
logic.lockNoticeSettingAccountList();
},
), ),
SizedBox( SizedBox(
height: 60.h, height: 60.h,
@ -131,15 +137,46 @@ class _NDaysUnopenedPageState extends State<NDaysUnopenedPage> {
); );
} }
Widget _buildNotifyContain(String notifyTitle, String notifyContent) {
return Container(
padding:
EdgeInsets.only(left: 10.w, right: 10.w, top: 12.h, bottom: 12.h),
margin: EdgeInsets.only(bottom: 20.h, top: 10.h, left: 20.w, right: 20.w),
decoration: BoxDecoration(
color: AppColors.mainBackgroundColor,
borderRadius: BorderRadius.circular(6.0.w),
),
child: Row(
children: [
Text(
notifyTitle,
style: TextStyle(color: Colors.black, fontSize: 20.sp),
),
Expanded(
child: SizedBox(
width: 20.w,
)),
Text(notifyContent,
textAlign: TextAlign.end,
style: TextStyle(
color: AppColors.placeholderTextColor, fontSize: 20.sp)),
],
),
);
}
CupertinoSwitch _unOpenDoorSwitch() { CupertinoSwitch _unOpenDoorSwitch() {
return CupertinoSwitch( return CupertinoSwitch(
activeColor: CupertinoColors.activeBlue, activeColor: CupertinoColors.activeBlue,
trackColor: CupertinoColors.systemGrey5, trackColor: CupertinoColors.systemGrey5,
thumbColor: CupertinoColors.white, thumbColor: CupertinoColors.white,
value: state.isunOpenNotice.value, value: state.isUnOpenNotice.value,
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {
state.isunOpenNotice.value = value; state.isUnOpenNotice.value = value;
if (!state.isUnOpenNotice.value) {
state.msgNoticeInfo.value = MsgNoticeData();
}
}); });
}, },
); );

View File

@ -1,24 +1,50 @@
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/messageWarn/lockUser/lockUser_entity.dart';
import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart';
import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart';
class NDaysUnopenedState { class NDaysUnopenedState {
final List<String> unopenDoorTimeList = [ final List unopenDoorTimeList = [
'1天', 1,
'2天', 2,
'3天', 3,
'4天', 4,
'5天', 5,
'6天', 6,
'7天', 7,
'8天', 8,
'9天', 9,
'10天', 10,
'11天', 11,
'12天', 12,
'13天', 13,
'14天', 14,
'15天', 15,
]; ];
var isunOpenNotice = false.obs; // N天未开门提醒 var isUnOpenNotice = false.obs; // N天未开门提醒
var unOpenDoorTime = '1天'.obs; // var unOpenDoorTime = 1.obs; //
var getLockId = 0.obs;
var lockUserKeys = LockUserListKeys().obs;
var emailReceiverList = [].obs;
var phoneReceiverList = [].obs;
var emailListStr = ''.obs;
var phontListStr = ''.obs;
var msgNoticeInfo = MsgNoticeData().obs;
NDaysUnopenedState() {
Map map = Get.arguments;
if (map['lockId'] != null) {
getLockId.value = map['lockId'];
}
if (map['lockSetInfoData'] != null) {
msgNoticeInfo.value = map['lockSetInfoData'];
isUnOpenNotice.value =
msgNoticeInfo.value.dayNotOpenDoorState == 1 ? true : false;
unOpenDoorTime.value = msgNoticeInfo.value.dayNotOpenDoorValue!;
}
}
} }

View File

@ -1,3 +1,5 @@
import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart';
class OpenDoorNotifyEntity { class OpenDoorNotifyEntity {
int? errorCode; int? errorCode;
String? description; String? description;

View File

@ -3,7 +3,6 @@ import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/appRouters.dart'; import 'package:star_lock/appRouters.dart';
import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart';
import 'package:star_lock/main/lockDetail/messageWarn/notificationMode/notificationMode_data.dart'; import 'package:star_lock/main/lockDetail/messageWarn/notificationMode/notificationMode_data.dart';
import 'package:star_lock/main/lockDetail/messageWarn/notificationMode/notificationMode_logic.dart'; import 'package:star_lock/main/lockDetail/messageWarn/notificationMode/notificationMode_logic.dart';
import 'package:star_lock/tools/commonItem.dart'; import 'package:star_lock/tools/commonItem.dart';

View File

@ -1,4 +1,5 @@
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart';
import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart'; import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart';
import 'package:star_lock/main/lockDetail/messageWarn/notificationMode/notificationMode_data.dart'; import 'package:star_lock/main/lockDetail/messageWarn/notificationMode/notificationMode_data.dart';
@ -9,6 +10,7 @@ class NotificationModeState {
var countryName = '中国'.obs; var countryName = '中国'.obs;
var countryCode = 86.obs; var countryCode = 86.obs;
var familyData = DataList().obs; var familyData = DataList().obs;
var msgNoticeInfo = MsgNoticeData().obs;
NotificationModeState() { NotificationModeState() {
Map map = Get.arguments; Map map = Get.arguments;
@ -37,5 +39,32 @@ class NotificationModeState {
} }
} }
} }
if (map['msgNoticeInfo'] != null) {
msgNoticeInfo.value = map['msgNoticeInfo'];
if (msgNoticeInfo.value.dayNotOpenDoorNoticeWayList != null) {
for (NoticeWay item
in msgNoticeInfo.value.dayNotOpenDoorNoticeWayList!) {
if (item.type == 'mail' && item.accounts != null) {
for (Accounts account in item.accounts!) {
if (account.account != null) {
MsgNoticeModeData msgNoticeModeData = MsgNoticeModeData();
msgNoticeModeData.receiveEmail = account.account!;
emailReceiverList.value.add(msgNoticeModeData);
}
}
} else if (item.type == 'sms' && item.accounts != null) {
for (Accounts account in item.accounts!) {
if (account.account != null && account.countryCode != null) {
MsgNoticeModeData msgNoticeModeData = MsgNoticeModeData();
msgNoticeModeData.receivePhone = account.account!;
msgNoticeModeData.countryCode = account.countryCode!;
phoneReceiverList.value.add(msgNoticeModeData);
}
}
}
}
}
}
} }
} }

View File

@ -1850,14 +1850,14 @@ class ApiRepository {
} }
// N天未开门 // N天未开门
Future<MsgNotificationEntity> updateNdaysNotCloseDoorNoticeSetting( Future<OpenDoorNotifyEntity> updateNdaysNotCloseDoorNoticeSetting(
{required int lockId, {required int lockId,
required int dayNotOpenDoorState, required int dayNotOpenDoorState,
required int dayNotOpenDoorValue, required int dayNotOpenDoorValue,
required List dayNotOpenDoorNoticeWayList}) async { required List dayNotOpenDoorNoticeWayList}) async {
final res = await apiProvider.updateNdaysNotCloseDoorNoticeSetting(lockId, final res = await apiProvider.updateNdaysNotCloseDoorNoticeSetting(lockId,
dayNotOpenDoorState, dayNotOpenDoorValue, dayNotOpenDoorNoticeWayList); dayNotOpenDoorState, dayNotOpenDoorValue, dayNotOpenDoorNoticeWayList);
return MsgNotificationEntity.fromJson(res.body); return OpenDoorNotifyEntity.fromJson(res.body);
} }
// //