1,新增开门通知家人详情逻辑处理及数据展示
2,新增删除家人接口对接及对应处理 3,开门通知模块部分代码重构
This commit is contained in:
parent
c7bf28ec0f
commit
edcf16114f
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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 '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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),
|
||||
|
||||
@ -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'];
|
||||
}
|
||||
|
||||
@ -204,6 +204,8 @@ abstract class Api {
|
||||
'/lockNoticeSettingAccount/add'; //添加开门通知
|
||||
final String lockNoticeSettingListURL =
|
||||
'/lockNoticeSettingAccount/list'; //开门通知列表
|
||||
final String deleteLockNoticeSettingAccountURL =
|
||||
'/lockNoticeSettingAccount/delete'; //删除开门通知
|
||||
|
||||
final String setWechatPushSwitchURL =
|
||||
'/user/setMpWechatPushSwitch'; //设置微信公众号推送
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user