1,新增开门通知家人详情逻辑处理及数据展示

2,新增删除家人接口对接及对应处理
3,开门通知模块部分代码重构
This commit is contained in:
Daisy 2024-04-23 10:51:49 +08:00
parent c7bf28ec0f
commit edcf16114f
11 changed files with 192 additions and 47 deletions

View File

@ -1,5 +1,6 @@
import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/messageWarn/addFamily/addFamily_state.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';
@ -7,6 +8,7 @@ import 'package:star_lock/tools/baseGetXController.dart';
class AddFamilyLogic extends BaseGetXController {
final AddFamilyState state = AddFamilyState();
//
void addLockNoticeSetting() async {
var entity = await ApiRepository.to.addLockNoticeSetting(
lockId: state.getLockId.value,
@ -27,6 +29,18 @@ class AddFamilyLogic extends BaseGetXController {
}
}
//
void deleteLockNoticeSetting() async {
var entity = await ApiRepository.to.deleteLockNoticeSettingAccount(
lockNoticeSettingAccountId: state.familyData.value.id!,
);
if (entity.errorCode!.codeIsSuccessful) {
showToast('删除成功'.tr);
Get.back(result: true);
}
}
//
List getEmailAndSMSAccountList(bool isEmail) {
List list = [];
List accountList = [];
@ -78,6 +92,7 @@ class AddFamilyLogic extends BaseGetXController {
return phoneListStr;
}
//
bool checkBtnDisable() {
if ((state.emailListStr.value.isEmpty ||
state.phontListStr.value.isEmpty) ||
@ -88,4 +103,65 @@ class AddFamilyLogic extends BaseGetXController {
return true;
}
}
// 1: 2: 3: 4: 5:
String getKeyTypeStr() {
int keyType = state.familyData.value.settingValue!.openDoorType!;
switch (keyType) {
case 1:
return '电子钥匙';
case 2:
return '密码';
case 3:
return '指纹';
case 4:
return '';
case 5:
return '人脸';
default:
return '';
}
}
//
Map<String, List<MsgNoticeModeData>> getAccountsMap() {
List<MsgNoticeModeData> mailAccounts = [];
List<MsgNoticeModeData> smsAccounts = [];
if (state.familyData.value.settingValue != null) {
for (NoticeWay item
in state.familyData.value.settingValue!.noticeWayList!) {
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

@ -25,7 +25,7 @@ class _AddFamilyPageState extends State<AddFamilyPage> {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: '添加家人'.tr,
barTitle: state.isDetail.value ? '家人详情'.tr : '添加家人'.tr,
haveBack: true,
backgroundColor: AppColors.mainColor),
body: Container(
@ -34,8 +34,9 @@ class _AddFamilyPageState extends State<AddFamilyPage> {
children: [
Obx(() => CommonItem(
leftTitel: '开门方式'.tr,
rightTitle:
state.lockUserKeys.value.currentKeyTypeStr ?? '请选择'.tr,
rightTitle: state.isDetail.value
? logic.getKeyTypeStr()
: state.lockUserKeys.value.currentKeyTypeStr ?? '请选择'.tr,
isHaveLine: true,
isHaveDirection: true,
action: () {
@ -50,7 +51,9 @@ class _AddFamilyPageState extends State<AddFamilyPage> {
})),
Obx(() => CommonItem(
leftTitel: '家人'.tr,
rightTitle: state.lockUserKeys.value.currentKeyName ?? '',
rightTitle: state.isDetail.value
? state.familyData.value.settingValue?.remark
: state.lockUserKeys.value.currentKeyName,
isHaveLine: true,
isHaveRightWidget:
state.lockUserKeys.value.currentKeyName == null
@ -99,10 +102,17 @@ class _AddFamilyPageState extends State<AddFamilyPage> {
height: 40.h,
)),
Obx(() => SubmitBtn(
btnName: '保存'.tr,
isDisabled: logic.checkBtnDisable(),
btnName: state.isDetail.value == true ? '删除'.tr : '保存'.tr,
isDisabled: state.isDetail.value == true
? true
: logic.checkBtnDisable(),
isDelete: state.isDetail.value,
onClick: () {
logic.addLockNoticeSetting();
if (state.isDetail.value) {
logic.deleteLockNoticeSetting();
} else {
logic.addLockNoticeSetting();
}
},
)),
SizedBox(
@ -145,6 +155,9 @@ class _AddFamilyPageState extends State<AddFamilyPage> {
//
Widget getFamilyWidget(String tfStr) {
TextEditingController emailController = TextEditingController();
if (state.isDetail.value) {
emailController.text = state.familyData.value.settingValue?.remark ?? '';
}
return SizedBox(
height: 50.h,
width: 360.w,
@ -157,6 +170,7 @@ class _AddFamilyPageState extends State<AddFamilyPage> {
maxLines: 1,
autofocus: false,
textAlign: TextAlign.end,
style: TextStyle(fontSize: 22.sp),
decoration: InputDecoration(
//
contentPadding: const EdgeInsets.only(top: -12.0, bottom: 0.0),

View File

@ -1,5 +1,6 @@
import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/messageWarn/lockUser/lockUser_entity.dart';
import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart';
class AddFamilyState {
var getLockId = 0.obs;
@ -11,11 +12,21 @@ class AddFamilyState {
var openDoorId = 0.obs;
var openDoorType = 0.obs;
var familyData = DataList().obs;
var isDetail = false.obs;
AddFamilyState() {
Map map = Get.arguments;
if (map['getLockId'] != null) {
getLockId.value = map['getLockId'];
if (map['lockId'] != null) {
getLockId.value = map['lockId'];
}
if (map['isDetail'] != null) {
isDetail.value = map['isDetail'];
}
if (map['itemData'] != null) {
familyData.value = map['itemData'];
}
}
}

View File

@ -1,15 +1,21 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart';
class FamilyDetailsState {
TextEditingController changeNameController = TextEditingController(); //
var familyName = ''.obs;
var getLockId = 0.obs;
var familyData = DataList().obs;
FamilyDetailsState() {
Map map = Get.arguments;
if (map['lockId'] != null) {
getLockId.value = map['lockId'];
}
if (map['itemData'] != null) {
familyData.value = map['itemData'];
}
}
}

View File

@ -103,19 +103,19 @@ class SettingValue {
int? openDoorId;
int? openDoorType;
String? remark;
List<NoticeWay>? noticeWay;
List<NoticeWay>? noticeWayList;
SettingValue(
{this.openDoorId, this.openDoorType, this.remark, this.noticeWay});
{this.openDoorId, this.openDoorType, this.remark, this.noticeWayList});
SettingValue.fromJson(Map<String, dynamic> json) {
openDoorId = json['openDoorId'];
openDoorType = json['openDoorType'];
remark = json['remark'];
if (json['noticeWay'] != null) {
noticeWay = <NoticeWay>[];
noticeWayList = <NoticeWay>[];
json['noticeWay'].forEach((v) {
noticeWay!.add(NoticeWay.fromJson(v));
noticeWayList!.add(NoticeWay.fromJson(v));
});
}
}
@ -125,8 +125,8 @@ class SettingValue {
data['openDoorId'] = openDoorId;
data['openDoorType'] = openDoorType;
data['remark'] = remark;
if (noticeWay != null) {
data['noticeWay'] = noticeWay!.map((v) => v.toJson()).toList();
if (noticeWayList != null) {
data['noticeWay'] = noticeWayList!.map((v) => v.toJson()).toList();
}
return data;
}

View File

@ -16,4 +16,23 @@ class OpenDoorNotifyLogic extends BaseGetXController {
state.openDoorNotifyList.value = entity.data!.list!;
}
}
// 1: 2: 3: 4: 5:
String getKeyTypeStr(DataList itemData) {
int keyType = itemData.settingValue!.openDoorType!;
switch (keyType) {
case 1:
return '电子钥匙';
case 2:
return '密码';
case 3:
return '指纹';
case 4:
return '';
case 5:
return '人脸';
default:
return '';
}
}
}

View File

@ -2,6 +2,8 @@ import 'package:flutter/material.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/openDoorNotify/openDoorNotify_entity.dart';
import 'package:star_lock/tools/noData.dart';
import '../../../../../app_settings/app_colors.dart';
import '../../../../../tools/submitBtn.dart';
@ -41,13 +43,17 @@ class _OpenDoorNotifyPageState extends State<OpenDoorNotifyPage> {
SizedBox(
height: 20.h,
),
Expanded(child: Obx(() => _buildMainUI())),
Expanded(
child: Obx(() => state.openDoorNotifyList.value.isNotEmpty
? _buildMainUI()
: NoData())),
AddBottomWhiteBtn(
btnName: '添加家人'.tr,
onClick: () {
Get.toNamed(Routers.addFamilyPage,
arguments: {'getLockId': state.getLockId.value})
?.then((value) {
Get.toNamed(Routers.addFamilyPage, arguments: {
'lockId': state.getLockId.value,
'isDetail': false
})?.then((value) {
if (value != null) {
logic.lockNoticeSettingAccountList();
}
@ -76,10 +82,7 @@ class _OpenDoorNotifyPageState extends State<OpenDoorNotifyPage> {
shrinkWrap: true,
itemCount: state.openDoorNotifyList.length,
itemBuilder: (c, index) {
return _electronicKeyItem(
'images/controls_user.png', '18682150237', '电子钥匙', () {
Get.toNamed(Routers.familyDetailsPage);
});
return _electronicKeyItem(state.openDoorNotifyList.value[index]);
},
separatorBuilder: (BuildContext context, int index) {
return const Divider(
@ -90,10 +93,19 @@ class _OpenDoorNotifyPageState extends State<OpenDoorNotifyPage> {
);
}
Widget _electronicKeyItem(String avatarURL, String familyAccount,
String openDoorWay, Function() action) {
Widget _electronicKeyItem(DataList itemData) {
return GestureDetector(
onTap: action,
onTap: () {
Get.toNamed(Routers.addFamilyPage, arguments: {
'itemData': itemData,
'lockId': state.getLockId.value,
'isDetail': true
})?.then((value) {
if (value != null) {
logic.lockNoticeSettingAccountList();
}
});
},
child: Container(
color: Colors.white,
height: 90.h,
@ -103,7 +115,7 @@ class _OpenDoorNotifyPageState extends State<OpenDoorNotifyPage> {
width: 30.w,
),
Image.asset(
avatarURL,
'images/controls_user.png',
width: 60.w,
height: 60.w,
),
@ -117,7 +129,7 @@ class _OpenDoorNotifyPageState extends State<OpenDoorNotifyPage> {
Row(
children: [
Text(
familyAccount,
itemData.settingValue!.remark ?? '',
style: TextStyle(
fontSize: 24.sp, color: AppColors.blackColor),
),
@ -133,7 +145,7 @@ class _OpenDoorNotifyPageState extends State<OpenDoorNotifyPage> {
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text(
openDoorWay,
logic.getKeyTypeStr(itemData),
style: TextStyle(
fontSize: 18.sp,
color: AppColors.placeholderTextColor),

View File

@ -1,19 +1,11 @@
import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart';
class OpenDoorNotifyState {
var msgNoticeInfo = MsgNoticeData().obs;
var pageNum = 1.obs; //
final pageSize = 20.obs; //
var itemDataList = [].obs;
var getLockId = 0.obs;
var openDoorNotifyList = [].obs;
var openDoorNotifyList = [].obs; //
OpenDoorNotifyState() {
Map map = Get.arguments;
if (map['msgNoticeInfo'] != null) {
msgNoticeInfo.value = map['msgNoticeInfo'];
}
if (map['lockId'] != null) {
getLockId.value = map['lockId'];
}

View File

@ -204,6 +204,8 @@ abstract class Api {
'/lockNoticeSettingAccount/add'; //
final String lockNoticeSettingListURL =
'/lockNoticeSettingAccount/list'; //
final String deleteLockNoticeSettingAccountURL =
'/lockNoticeSettingAccount/delete'; //
final String setWechatPushSwitchURL =
'/user/setMpWechatPushSwitch'; //

View File

@ -674,13 +674,12 @@ class ApiProvider extends BaseProvider {
}));
///
Future<Response> updateNetworkInfo(int lockId, String network) =>
post(
updateLockSettingUrl.toUrl,
jsonEncode({
'lockId': lockId,
'network': network,
}));
Future<Response> updateNetworkInfo(int lockId, String network) => post(
updateLockSettingUrl.toUrl,
jsonEncode({
'lockId': lockId,
'network': network,
}));
//
Future<Response> setLockSoundData(
@ -1889,6 +1888,14 @@ class ApiProvider extends BaseProvider {
post(lockNoticeSettingListURL.toUrl,
jsonEncode({'lockId': lockId, 'noticeType': noticeType}));
//
Future<Response> deleteLockNoticeSettingAccount(
int lockNoticeSettingAccountId) =>
post(
deleteLockNoticeSettingAccountURL.toUrl,
jsonEncode(
{'lockNoticeSettingAccountId': lockNoticeSettingAccountId}));
//
Future<Response> setMpWechatPushSwitch(int mpWechatPushSwitch) => post(
setWechatPushSwitchURL.toUrl,

View File

@ -714,8 +714,6 @@ class ApiRepository {
return LoginEntity.fromJson(res.body);
}
//
Future<LoginEntity> setLockSound({
required int lockId,
@ -1909,6 +1907,14 @@ class ApiRepository {
return OpenDoorNotifyEntity.fromJson(res.body);
}
//
Future<OpenDoorNotifyEntity> deleteLockNoticeSettingAccount(
{required int lockNoticeSettingAccountId}) async {
final res = await apiProvider
.deleteLockNoticeSettingAccount(lockNoticeSettingAccountId);
return OpenDoorNotifyEntity.fromJson(res.body);
}
//
Future<VersionUndateEntity> setMpWechatPushSwitch(
{required int mpWechatPushSwitch}) async {