From 624a43fde2ca1a4e3056709e3bb6d1de147c2392 Mon Sep 17 00:00:00 2001 From: anfe <448468458@qq.com> Date: Wed, 22 May 2024 14:07:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=81=A2=E5=A4=8D=20http=20=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../authorizedAdminList_page.dart | 49 +++++++++--------- .../notice_template_entity.dart | 50 +++++++++++++++++++ .../volumeAuthorizationLock_logic.dart | 20 ++++++-- .../volumeAuthorizationLock_page.dart | 43 +++------------- lib/network/api.dart | 2 + lib/network/api_provider.dart | 26 +++++++--- lib/network/api_repository.dart | 11 ++++ lib/network/response_interceptor_log.dart | 2 +- 8 files changed, 133 insertions(+), 70 deletions(-) create mode 100644 lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/notice_template_entity.dart diff --git a/lib/main/lockDetail/authorizedAdmin/authorizedAdminList/authorizedAdminList_page.dart b/lib/main/lockDetail/authorizedAdmin/authorizedAdminList/authorizedAdminList_page.dart index 752a1115..1fa9edf5 100755 --- a/lib/main/lockDetail/authorizedAdmin/authorizedAdminList/authorizedAdminList_page.dart +++ b/lib/main/lockDetail/authorizedAdmin/authorizedAdminList/authorizedAdminList_page.dart @@ -4,6 +4,7 @@ import 'package:flutter_slidable/flutter_slidable.dart'; import 'package:get/get.dart'; import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart'; import 'package:star_lock/main/lockDetail/authorizedAdmin/authorizedAdminList/authorizedAdminList_logic.dart'; +import 'package:star_lock/main/lockDetail/authorizedAdmin/authorizedAdminList/authorizedAdminList_state.dart'; import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyList/entity/ElectronicKeyListEntity.dart'; import 'package:star_lock/tools/noData.dart'; import 'package:star_lock/tools/storage.dart'; @@ -25,8 +26,8 @@ class AuthorizedAdminListPage extends StatefulWidget { } class _AuthorizedAdminListPageState extends State { - final logic = Get.put(AuthorizedAdminListLogic()); - final state = Get.find().state; + final AuthorizedAdminListLogic logic = Get.put(AuthorizedAdminListLogic()); + final AuthorizedAdminListState state = Get.find().state; @override void initState() { @@ -37,7 +38,7 @@ class _AuthorizedAdminListPageState extends State { Future mockRequest() async { // 获取是否是演示模式 演示模式不获取接口 - var isDemoMode = await Storage.getBool(ifIsDemoModeOrNot); + final bool? isDemoMode = await Storage.getBool(ifIsDemoModeOrNot); if (isDemoMode == false) { logic.mockNetworkDataRequest().then((ElectronicKeyListEntity value) { setState(() {}); @@ -63,7 +64,7 @@ class _AuthorizedAdminListPageState extends State { mockRequest(); }, child: Column( - children: [ + children: [ Expanded(child: _buildMainUI()), SizedBox( height: 20.h, @@ -72,7 +73,7 @@ class _AuthorizedAdminListPageState extends State { btnName: TranslationLoader.lanKeys!.addAuthorizedAdmin!.tr, onClick: () { Navigator.pushNamed(context, Routers.authorizedAdminPage) - .then((val) { + .then((Object? val) { if (val != null) { logic.pageNo = 1; mockRequest(); @@ -89,14 +90,14 @@ class _AuthorizedAdminListPageState extends State { } Widget _buildMainUI() { - return Obx(() => state.itemDataList.value.isEmpty + return Obx(() => state.itemDataList.isEmpty ? NoData(noDataHeight: 1.sh - ScreenUtil().statusBarHeight - 90) : SlidableAutoCloseBehavior( child: ListView.separated( - itemCount: state.itemDataList.value.length, - itemBuilder: (c, index) { - ElectronicKeyListItem indexEntity = - state.itemDataList.value[index]; + itemCount: state.itemDataList.length, + itemBuilder: (BuildContext c, int index) { + final ElectronicKeyListItem indexEntity = + state.itemDataList[index]; String useDateStr = ''; //使用期限 String keyStatus = ''; //钥匙状态 @@ -116,16 +117,16 @@ class _AuthorizedAdminListPageState extends State { } return Slidable( - key: ValueKey(indexEntity.keyId), + key: ValueKey(indexEntity.keyId), endActionPane: ActionPane( extentRatio: 0.2, motion: const ScrollMotion(), - children: [ + children: [ SlidableAction( onPressed: (BuildContext context) { ShowTipView() .showDeleteAdministratorIsHaveAllDataDialog( - '同时删除其发送的所有钥匙,钥匙删除后不能恢复', (isAllData) { + '同时删除其发送的所有钥匙,钥匙删除后不能恢复', (bool isAllData) { logic.deleteKeyRequest(indexEntity.keyId.toString(), isAllData ? 1 : 0); }); @@ -145,9 +146,9 @@ class _AuthorizedAdminListPageState extends State { isAdminKey, () { Navigator.pushNamed( context, Routers.electronicKeyDetailPage, - arguments: { - "itemData": indexEntity, - }).then((val) { + arguments: { + 'itemData': indexEntity, + }).then((Object? val) { if (val != null) { logic.mockNetworkDataRequest(); setState(() {}); @@ -172,14 +173,14 @@ class _AuthorizedAdminListPageState extends State { if (indexEntity.keyType == XSConstantMacro.keyTypeTime) { //限期 - DateTime startDateStr = + final DateTime startDateStr = DateTime.fromMillisecondsSinceEpoch(indexEntity.startDate!); - DateTime endDateStr = + final DateTime endDateStr = DateTime.fromMillisecondsSinceEpoch(indexEntity.endDate!); useDateStr = '${startDateStr.toLocal().toString().substring(0, 16)}-${endDateStr.toLocal().toString().substring(0, 16)}'; } else if (indexEntity.keyType == XSConstantMacro.keyTypeLong) { - useDateStr = "永久"; + useDateStr = '永久'; } return useDateStr; } @@ -192,7 +193,7 @@ class _AuthorizedAdminListPageState extends State { color: Colors.white, height: 100.h, child: Row( - children: [ + children: [ SizedBox(width: 30.w), Image.asset( avatarURL, @@ -203,13 +204,13 @@ class _AuthorizedAdminListPageState extends State { Expanded( child: Column( mainAxisAlignment: MainAxisAlignment.center, - children: [ + children: [ Row( - children: [ + children: [ SizedBox( width: 1.sw - 110.w - 100.w, child: Row( - children: [ + children: [ Flexible( child: Text(receiveUser, maxLines: 1, @@ -231,7 +232,7 @@ class _AuthorizedAdminListPageState extends State { SizedBox(height: 10.h), Row( mainAxisAlignment: MainAxisAlignment.start, - children: [ + children: [ Text( useDate, style: TextStyle( diff --git a/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/notice_template_entity.dart b/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/notice_template_entity.dart new file mode 100644 index 00000000..54905b3e --- /dev/null +++ b/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/notice_template_entity.dart @@ -0,0 +1,50 @@ +class NoticeTemplateEntity { + + int? errorCode; + String? description; + String? errorMsg; + Data? data; + + NoticeTemplateEntity( + {this.errorCode, this.description, this.errorMsg, this.data}); + + NoticeTemplateEntity.fromJson(Map json) { + errorCode = json['errorCode']; + description = json['description']; + errorMsg = json['errorMsg']; + if (json['data'] is Map) { + data = Data.fromJson(json['data']); + } + } + + Map toJson() { + final Map data = {}; + data['errorCode'] = errorCode; + data['description'] = description; + data['errorMsg'] = errorMsg; + data['data'] = this.data; + return data; + } +} + +class Data { + List? userNos = []; + + Data({ + this.userNos, + }); + + Data.fromJson(Map json) { + if (json['userNos'] is List) { + json['userNos'].forEach((element) { + userNos?.add(element); + }); + } + } + + Map toJson() { + final Map data = {}; + data['userNos'] = userNos; + return data; + } +} \ No newline at end of file diff --git a/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_logic.dart b/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_logic.dart index 99472fb2..a6043d15 100755 --- a/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_logic.dart +++ b/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_logic.dart @@ -2,19 +2,21 @@ import 'dart:ffi'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:get/get.dart'; +import 'package:star_lock/main/lockDetail/lockSet/basicInformation/basicInformation/KeyDetailEntity.dart'; import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/tools/baseGetXController.dart'; +import 'package:star_lock/tools/commonDataManage.dart'; import 'volumeAuthorizationLock_state.dart'; class VolumeAuthorizationLockLogic extends BaseGetXController { - final state = VolumeAuthorizationLockState(); + final VolumeAuthorizationLockState state = VolumeAuthorizationLockState(); //发送批量授权管理员 Future addAuthorizedAdminRequest() async { String getFailureDateTime = '0'; String getEffectiveDateTime = '0'; - if (state.selectWidgetType == '1') { + if (state.selectWidgetType.value == '1') { getFailureDateTime = state.failureDateTime.value.millisecondsSinceEpoch.toString(); getEffectiveDateTime = @@ -25,11 +27,11 @@ class VolumeAuthorizationLockLogic extends BaseGetXController { showToast('请选择锁'.tr); return; } - var entity = await ApiRepository.to.addAuthorizedAdmin( + final KeyDetailEntity entity = await ApiRepository.to.addAuthorizedAdmin( createUser: state.isCreateUser.value ? '1' : '0', endDate: getFailureDateTime, isRemoteUnlock: '0', - keyGroupIdList: [], + keyGroupIdList: [], lockIdList: state.lockIdList.value, name: state.keyNameController.text, startDate: getEffectiveDateTime, @@ -49,4 +51,14 @@ class VolumeAuthorizationLockLogic extends BaseGetXController { } } } + + //发送消息 + Future sendMsg({required bool isPhone}) async { + if (isPhone) { + } else {} + var entity = await ApiRepository.to.getNoticeTemplate( + lockId: CommonDataManage().currentKeyInfo.lockId!, + keyId: CommonDataManage().currentKeyInfo.keyId!, + channelType: 1); + } } diff --git a/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_page.dart b/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_page.dart index 2aa60e45..b553ad90 100755 --- a/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_page.dart +++ b/lib/main/lockDetail/authorizedAdmin/volumeAuthorizationLock/volumeAuthorizationLock_page.dart @@ -181,7 +181,7 @@ class _VolumeAuthorizationLockPageState children: [ CommonItem( leftTitel: TranslationLoader.lanKeys!.lock!.tr, - rightTitle: state.lockIdList.value.isEmpty + rightTitle: state.lockIdList.isEmpty ? TranslationLoader.lanKeys!.pleaseSelect!.tr : state.lockIdList.length.toString(), isHaveDirection: true, @@ -190,11 +190,12 @@ class _VolumeAuthorizationLockPageState arguments: {'keyLimits': '1'}) .then((Object? value) { //得到选中的锁ID列表 - if (value != null) { - value as Map; - state.lockIdList.value = value['selectLockIdList']; - - // setState(() {}); + if (value is Map && value['selectLockIdList'] is List) { + state.lockIdList.clear(); + value['selectLockIdList'].forEach((element) { + state.lockIdList.add(element); + }); + setState(() {}); } }); }), @@ -211,13 +212,6 @@ class _VolumeAuthorizationLockPageState width: 60.w, height: 50.h, child: _onlyManageYouCreatesUserSwitch())), - - // CommonItem( - // leftTitel: TranslationLoader.lanKeys!.remoteUnlockingAllowed!.tr, - // rightTitle: '', - // isHaveRightWidget: true, - // rightWidget: SizedBox(width: 60.w, height: 50.h, child: _switch()), - // action: () {}), Container(height: 10.h), ], ); @@ -375,31 +369,10 @@ class _VolumeAuthorizationLockPageState btnName: '微信通知', onClick: () {}, ), - SizedBox( - height: 10.h, - ), - OutLineBtn( - btnName: '标记为已入住', - onClick: () {}, - ), ], ); } - // CupertinoSwitch _switch() { - // return CupertinoSwitch( - // activeColor: CupertinoColors.activeBlue, - // trackColor: CupertinoColors.systemGrey5, - // thumbColor: CupertinoColors.white, - // value: state.isRemoteUnlock.value, - // onChanged: (bool value) { - // setState(() { - // _isRemoteUnlock = !_isRemoteUnlock; - // }); - // }, - // ); - // } - //仅管理自己创建的用户 CupertinoSwitch _onlyManageYouCreatesUserSwitch() { return CupertinoSwitch( @@ -407,7 +380,7 @@ class _VolumeAuthorizationLockPageState trackColor: CupertinoColors.systemGrey5, thumbColor: CupertinoColors.white, value: state.onlyManageYouCreatesUser.value, - onChanged: (value) { + onChanged: (bool value) { setState(() { state.onlyManageYouCreatesUser.value = !state.onlyManageYouCreatesUser.value; diff --git a/lib/network/api.dart b/lib/network/api.dart index 16d06347..845f7107 100755 --- a/lib/network/api.dart +++ b/lib/network/api.dart @@ -235,4 +235,6 @@ abstract class Api { final String getUserNoList = '/key/getUserNoList'; //获取指定锁下所有userNo + final String getNoticeTemplateURL = '/key/getNoticeTemplate'; //获取短信或者邮箱模板 + } diff --git a/lib/network/api_provider.dart b/lib/network/api_provider.dart index c44115cb..d2347c6d 100755 --- a/lib/network/api_provider.dart +++ b/lib/network/api_provider.dart @@ -374,12 +374,15 @@ class ApiProvider extends BaseProvider { })); // 获取锁信息列表 - Future getStarLockListInfo(int pageNo, int pageSize,{bool isUnShowLoading = true}) => post( - getStarLockInfoURL.toUrl, - jsonEncode({ - "pageNo": pageNo, - 'pageSize': pageSize, - }),isUnShowLoading: isUnShowLoading); + Future getStarLockListInfo(int pageNo, int pageSize, + {bool isUnShowLoading = true}) => + post( + getStarLockInfoURL.toUrl, + jsonEncode({ + "pageNo": pageNo, + 'pageSize': pageSize, + }), + isUnShowLoading: isUnShowLoading); // 获取所有锁设置信息 Future getLockSettingInfoData(String lockId) => post( @@ -2078,6 +2081,17 @@ class ApiProvider extends BaseProvider { // 获取指定锁下所有userNo Future getLockUserNoList(int lockId) => post(getUserNoList.toUrl, jsonEncode({'lockId': lockId})); + + // 获取短信或者邮箱模板 + Future> getNoticeTemplate( + int lockId, int keyId, int channelType) => + post( + getNoticeTemplateURL.toUrl, + jsonEncode({ + 'lockId': lockId, + 'keyId': keyId, + 'channelType': channelType, + })); } extension ExtensionString on String { diff --git a/lib/network/api_repository.dart b/lib/network/api_repository.dart index 64818b1f..1a1f2819 100755 --- a/lib/network/api_repository.dart +++ b/lib/network/api_repository.dart @@ -2112,4 +2112,15 @@ class ApiRepository { final res = await apiProvider.getLockUserNoList(lockId); return LockUserNoListEntity.fromJson(res.body); } + + // 检测certifyId是否完成认证 + Future getNoticeTemplate({ + required int lockId, + required int keyId, + required int channelType, + }) async { + final Response res = + await apiProvider.getNoticeTemplate(lockId, keyId, channelType); + return LockUserNoListEntity.fromJson(res.body); + } } diff --git a/lib/network/response_interceptor_log.dart b/lib/network/response_interceptor_log.dart index f24553c4..85890536 100755 --- a/lib/network/response_interceptor_log.dart +++ b/lib/network/response_interceptor_log.dart @@ -5,7 +5,7 @@ import 'package:get/get_connect/http/src/request/request.dart'; import 'package:star_lock/app_settings/app_settings.dart'; FutureOr responseLogInterceptor(Request request, Response response) { - // AppLog.log('HTTP request:${request.url}\n RESPONSE => stataCode:${response.statusCode} ${response.bodyString}'); // \n ${response.headers} + AppLog.log('HTTP request:${request.url}\n RESPONSE => stataCode:${response.statusCode} ${response.bodyString}'); // \n ${response.headers} EasyLoading.dismiss(animation: true); return response; }