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",
"关锁":"关锁",
"功能":"功能",
"配件":"配件"
"配件":"配件",
"N天未开门提醒":"N days did not open the door reminder"
}

View File

@ -770,5 +770,6 @@
"邮件提醒":"邮件提醒",
"关锁":"Close Lock",
"功能":"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 {
int? errorCode;
String? description;
@ -27,21 +29,19 @@ class MsgNotificationEntity {
}
class MsgNoticeData {
List? openDoorNoticeList;
int? dayNotOpenDoorState;
int? dayNotOpenDoorValue;
List? dayNotOpenDoorNoticeWayList;
List<NoticeWay>? dayNotOpenDoorNoticeWayList;
int? doorNotCloseState;
int? tamperAlarmState;
int? lowElecNoticeState;
List<void>? lowElecNoticeWayList;
List<void>? coercionOpenDoorNoticeList;
List? lowElecNoticeWayList;
List? coercionOpenDoorNoticeList;
int? doorbellNoticeState;
int? someoneAtDoorNoticeState;
MsgNoticeData(
{this.openDoorNoticeList,
this.dayNotOpenDoorState,
{this.dayNotOpenDoorState,
this.dayNotOpenDoorValue,
this.dayNotOpenDoorNoticeWayList,
this.doorNotCloseState,
@ -53,18 +53,12 @@ class MsgNoticeData {
this.someoneAtDoorNoticeState});
MsgNoticeData.fromJson(Map<String, dynamic> json) {
if (json['openDoorNoticeList'] != null) {
openDoorNoticeList = [];
json['openDoorNoticeList'].forEach((v) {
openDoorNoticeList!.add(v);
});
}
dayNotOpenDoorState = json['dayNotOpenDoorState'];
dayNotOpenDoorValue = json['dayNotOpenDoorValue'];
if (json['dayNotOpenDoorNoticeWayList'] != null) {
dayNotOpenDoorNoticeWayList = [];
dayNotOpenDoorNoticeWayList = <NoticeWay>[];
json['dayNotOpenDoorNoticeWayList'].forEach((v) {
dayNotOpenDoorNoticeWayList!.add(v);
dayNotOpenDoorNoticeWayList!.add(NoticeWay.fromJson(v));
});
}
doorNotCloseState = json['doorNotCloseState'];
@ -88,10 +82,6 @@ class MsgNoticeData {
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
if (openDoorNoticeList != null) {
data['openDoorNoticeList'] =
openDoorNoticeList!.map((v) => v.toJson()).toList();
}
data['dayNotOpenDoorState'] = dayNotOpenDoorState;
data['dayNotOpenDoorValue'] = dayNotOpenDoorValue;
if (dayNotOpenDoorNoticeWayList != null) {
@ -103,11 +93,11 @@ class MsgNoticeData {
data['lowElecNoticeState'] = lowElecNoticeState;
if (lowElecNoticeWayList != null) {
data['lowElecNoticeWayList'] =
lowElecNoticeWayList!.map((v) => v).toList();
lowElecNoticeWayList!.map((v) => v.toJson()).toList();
}
if (coercionOpenDoorNoticeList != null) {
data['coercionOpenDoorNoticeList'] =
coercionOpenDoorNoticeList!.map((v) => v).toList();
coercionOpenDoorNoticeList!.map((v) => v.toJson()).toList();
}
data['doorbellNoticeState'] = doorbellNoticeState;
data['someoneAtDoorNoticeState'] = someoneAtDoorNoticeState;

View File

@ -89,7 +89,14 @@ class _MsgNotificationPageState extends State<MsgNotificationPage> {
isHaveLine: true,
isHaveDirection: true,
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(

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 'nDaysUnopened_state.dart';
class NDaysUnopenedLogic extends BaseGetXController {
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/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:get/get.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/pickers/pickers.dart';
import 'package:star_lock/tools/pickers/style/default_style.dart';
@ -30,7 +29,7 @@ class _NDaysUnopenedPageState extends State<NDaysUnopenedPage> {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: 'N天未开门',
barTitle: 'N天未开门'.tr,
haveBack: true,
backgroundColor: AppColors.mainColor),
body: Container(
@ -52,7 +51,7 @@ class _NDaysUnopenedPageState extends State<NDaysUnopenedPage> {
height: 20.h,
),
CommonItem(
leftTitel: 'N天未开门提醒',
leftTitel: 'N天未开门提醒'.tr,
rightTitle: '',
isHaveLine: true,
isHaveDirection: false,
@ -60,12 +59,12 @@ class _NDaysUnopenedPageState extends State<NDaysUnopenedPage> {
rightWidget: _unOpenDoorSwitch(),
action: () {}),
Visibility(
visible: state.isunOpenNotice.value,
visible: state.isUnOpenNotice.value,
child: Column(
children: [
Obx(() => CommonItem(
leftTitel: '门未开时间',
rightTitle: state.unOpenDoorTime.value,
rightTitle: '${state.unOpenDoorTime.value}',
isHaveLine: true,
isHaveRightWidget: false,
isHaveDirection: true,
@ -77,41 +76,46 @@ class _NDaysUnopenedPageState extends State<NDaysUnopenedPage> {
SizedBox(
height: 20.h,
),
Container(
color: Colors.white,
margin: EdgeInsets.only(bottom: 10.h),
child: Column(
children: [
CommonItem(
leftTitel: '提醒方式'.tr,
rightTitle: "",
isHaveLine: false,
isHaveRightWidget: false,
isHaveDirection: true,
action: () {
Get.toNamed(Routers.notificationModePage);
},
),
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),
decoration: BoxDecoration(
color: AppColors.mainBackgroundColor,
borderRadius: BorderRadius.circular(6.0.w),
GestureDetector(
onTap: () {
Get.toNamed(Routers.notificationModePage, arguments: {
'msgNoticeInfo': state.msgNoticeInfo.value
})?.then((val) {
if (val != null) {
state.emailListStr.value =
logic.getEmailListStr(val);
state.phontListStr.value =
logic.getPhoneListStr(val);
print(
'emailListStr:${state.emailListStr.value},phontListStr:${state.phontListStr.value}');
}
});
},
child: Container(
color: Colors.white,
margin: EdgeInsets.only(bottom: 10.h),
child: Column(
children: [
CommonItem(
leftTitel: '提醒方式'.tr,
rightTitle: "",
isHaveLine: false,
isHaveRightWidget: false,
isHaveDirection: true,
),
child: Text(
'APP推送 管理员',
style: TextStyle(
color: Colors.black, fontSize: 20.sp),
),
)
],
_buildNotifyContain('APP推送'.tr, '管理员'.tr),
Obx(() => state.emailListStr.value.isNotEmpty
? _buildNotifyContain(
'邮件提醒'.tr, state.emailListStr.value)
: Container()),
Obx(() => state.phontListStr.value.isNotEmpty
? _buildNotifyContain(
'短信提醒'.tr, state.phontListStr.value)
: Container()),
],
),
),
)
),
],
)),
Expanded(
@ -120,7 +124,9 @@ class _NDaysUnopenedPageState extends State<NDaysUnopenedPage> {
)),
SubmitBtn(
btnName: '保存',
onClick: () {},
onClick: () {
logic.lockNoticeSettingAccountList();
},
),
SizedBox(
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() {
return CupertinoSwitch(
activeColor: CupertinoColors.activeBlue,
trackColor: CupertinoColors.systemGrey5,
thumbColor: CupertinoColors.white,
value: state.isunOpenNotice.value,
value: state.isUnOpenNotice.value,
onChanged: (value) {
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: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 {
final List<String> unopenDoorTimeList = [
'1天',
'2天',
'3天',
'4天',
'5天',
'6天',
'7天',
'8天',
'9天',
'10天',
'11天',
'12天',
'13天',
'14天',
'15天',
final List unopenDoorTimeList = [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
];
var isunOpenNotice = false.obs; // N天未开门提醒
var unOpenDoorTime = '1天'.obs; //
var isUnOpenNotice = false.obs; // N天未开门提醒
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 {
int? errorCode;
String? description;

View File

@ -3,7 +3,6 @@ import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.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_logic.dart';
import 'package:star_lock/tools/commonItem.dart';

View File

@ -1,4 +1,5 @@
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/notificationMode/notificationMode_data.dart';
@ -9,6 +10,7 @@ class NotificationModeState {
var countryName = '中国'.obs;
var countryCode = 86.obs;
var familyData = DataList().obs;
var msgNoticeInfo = MsgNoticeData().obs;
NotificationModeState() {
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天未开门
Future<MsgNotificationEntity> updateNdaysNotCloseDoorNoticeSetting(
Future<OpenDoorNotifyEntity> updateNdaysNotCloseDoorNoticeSetting(
{required int lockId,
required int dayNotOpenDoorState,
required int dayNotOpenDoorValue,
required List dayNotOpenDoorNoticeWayList}) async {
final res = await apiProvider.updateNdaysNotCloseDoorNoticeSetting(lockId,
dayNotOpenDoorState, dayNotOpenDoorValue, dayNotOpenDoorNoticeWayList);
return MsgNotificationEntity.fromJson(res.body);
return OpenDoorNotifyEntity.fromJson(res.body);
}
//