From cf5b7e621244d469e1cab75501d7fdfedf703c2a Mon Sep 17 00:00:00 2001 From: Daisy <> Date: Mon, 4 Sep 2023 15:04:44 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=8C=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=8D=95=E6=8A=8A=E9=92=A5=E5=8C=99=E8=AF=A6=E6=83=85=E5=80=9F?= =?UTF-8?q?=E5=8F=A3=202=EF=BC=8C=E9=94=81=E8=AE=BE=E7=BD=AE-=E5=9F=BA?= =?UTF-8?q?=E6=9C=AC=E4=BF=A1=E6=81=AF=E9=80=BB=E8=BE=91=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../basicInformation/KeyDetailEntity.dart | 149 ++++++++++ .../basicInformation_page.dart | 257 +++++++++++------- .../lcokSet/lockSet/lockSet_page.dart | 4 +- star_lock/lib/network/api.dart | 1 + star_lock/lib/network/api_provider.dart | 3 + star_lock/lib/network/api_repository.dart | 7 + star_lock/lib/tools/commonItem.dart | 2 + 7 files changed, 323 insertions(+), 100 deletions(-) create mode 100644 star_lock/lib/main/lockDetail/lcokSet/basicInformation/basicInformation/KeyDetailEntity.dart diff --git a/star_lock/lib/main/lockDetail/lcokSet/basicInformation/basicInformation/KeyDetailEntity.dart b/star_lock/lib/main/lockDetail/lcokSet/basicInformation/basicInformation/KeyDetailEntity.dart new file mode 100644 index 00000000..01064de4 --- /dev/null +++ b/star_lock/lib/main/lockDetail/lcokSet/basicInformation/basicInformation/KeyDetailEntity.dart @@ -0,0 +1,149 @@ +class KeyDetailEntity { + int? errorCode; + String? description; + String? errorMsg; + LockData? data; + + KeyDetailEntity({this.errorCode, this.description, this.errorMsg, this.data}); + + KeyDetailEntity.fromJson(Map json) { + errorCode = json['errorCode']; + description = json['description']; + errorMsg = json['errorMsg']; + data = json['data'] != null ? LockData.fromJson(json['data']) : null; + } + + Map toJson() { + final Map data = {}; + data['errorCode'] = errorCode; + data['description'] = description; + data['errorMsg'] = errorMsg; + if (this.data != null) { + data['data'] = this.data!.toJson(); + } + return data; + } +} + +class LockData { + int? keyId; + int? lockId; + String? lockName; + String? lockAlias; + int? userType; + int? keyStatus; + int? startDate; + int? endDate; + int? keyRight; + int? keyType; + String? remarks; + int? remoteEnable; + int? appUnlockMustOnline; + int? lockUserNo; + LockItem? lockData; + String? lockMac; + int? noKeyPwd; + int? electricQuantity; + String? featureValue; + String? groupId; + String? groupName; + + LockData( + {this.keyId, + this.lockId, + this.lockName, + this.lockAlias, + this.userType, + this.keyStatus, + this.startDate, + this.endDate, + this.keyRight, + this.keyType, + this.remarks, + this.remoteEnable, + this.appUnlockMustOnline, + this.lockUserNo, + this.lockData, + this.lockMac, + this.noKeyPwd, + this.electricQuantity, + this.featureValue, + this.groupId, + this.groupName}); + + LockData.fromJson(Map json) { + keyId = json['keyId']; + lockId = json['lockId']; + lockName = json['lockName']; + lockAlias = json['lockAlias']; + userType = json['userType']; + keyStatus = json['keyStatus']; + json['startDate'] != null ? startDate = json['startDate'] : 0; + json['endDate'] != null ? endDate = json['endDate'] : 0; + keyRight = json['keyRight']; + keyType = json['keyType']; + json['remarks'] != null ? remarks = json['remarks'] : ""; + json['remoteEnable'] != null ? remoteEnable = json['remoteEnable'] : 0; + json['appUnlockMustOnline'] != null + ? appUnlockMustOnline = json['appUnlockMustOnline'] + : 0; + json['lockUserNo'] != null ? lockUserNo = json['lockUserNo'] : 0; + lockData = + json['lockData'] != null ? LockItem.fromJson(json['lockData']) : null; + lockMac = json['lockMac']; + json['noKeyPwd'] != null ? noKeyPwd = json['noKeyPwd'] : 0; + json['electricQuantity'] != null + ? electricQuantity = json['electricQuantity'] + : 0; + json['featureValue'] != null ? featureValue = json['featureValue'] : ""; + json['groupId'] != null ? groupId = json['groupId'] : ""; + groupName = json['groupName']; + } + + Map toJson() { + final Map data = {}; + data['keyId'] = keyId; + data['lockId'] = lockId; + data['lockName'] = lockName; + data['lockAlias'] = lockAlias; + data['userType'] = userType; + data['keyStatus'] = keyStatus; + data['startDate'] = startDate; + data['endDate'] = endDate; + data['keyRight'] = keyRight; + data['keyType'] = keyType; + data['remarks'] = remarks; + data['remoteEnable'] = remoteEnable; + data['appUnlockMustOnline'] = appUnlockMustOnline; + data['lockUserNo'] = lockUserNo; + if (lockData != null) { + data['lockData'] = lockData!.toJson(); + } + data['lockMac'] = lockMac; + data['noKeyPwd'] = noKeyPwd; + data['electricQuantity'] = electricQuantity; + data['featureValue'] = featureValue; + data['groupId'] = groupId; + data['groupName'] = groupName; + return data; + } +} + +class LockItem { + String? lockName; + String? lockMac; + + LockItem({this.lockName, this.lockMac}); + + LockItem.fromJson(Map json) { + lockName = json['lockName']; + lockMac = json['lockMac']; + } + + Map toJson() { + final Map data = {}; + data['lockName'] = lockName; + data['lockMac'] = lockMac; + return data; + } +} diff --git a/star_lock/lib/main/lockDetail/lcokSet/basicInformation/basicInformation/basicInformation_page.dart b/star_lock/lib/main/lockDetail/lcokSet/basicInformation/basicInformation/basicInformation_page.dart index 65b17056..b1958f98 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/basicInformation/basicInformation/basicInformation_page.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/basicInformation/basicInformation/basicInformation_page.dart @@ -1,6 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import 'package:star_lock/main/lockDetail/lcokSet/basicInformation/basicInformation/KeyDetailEntity.dart'; +import 'package:star_lock/main/lockDetail/passwordKey/passwordKeyList/passwordKeyListEntity.dart'; +import 'package:star_lock/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKeyEntity.dart'; +import 'package:star_lock/main/lockMian/entity/lockInfoEntity.dart'; import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/tools/baseGetXController.dart'; @@ -19,6 +23,8 @@ class BasicInformationPage extends StatefulWidget { class _BasicInformationPageState extends State { late String _groupName = ""; + late KeyInfos keyInfo; + late LockMainEntity lockMainEntity; @override void initState() { @@ -28,115 +34,168 @@ class _BasicInformationPageState extends State { @override Widget build(BuildContext context) { + dynamic obj = ModalRoute.of(context)?.settings.arguments; + if (obj != null && (obj["keyInfo"] != null)) { + keyInfo = obj["keyInfo"]; + } + return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( barTitle: TranslationLoader.lanKeys!.basicInformation!.tr, haveBack: true, backgroundColor: AppColors.mainColor), - body: Column( - children: [ - Expanded( - child: ListView( - children: [ - CommonItem( - leftTitel: TranslationLoader.lanKeys!.lockNumber!.tr, - rightTitle: "MCBN0c_8f3106", - allHeight: 70.h, - isHaveLine: true), - CommonItem( - leftTitel: "MAC/ID", - rightTitle: "53:66:9F:06:31:8F/9418481", - allHeight: 70.h, - isHaveLine: false), - SizedBox( - height: 10.h, - ), - CommonItem( - leftTitel: - TranslationLoader.lanKeys!.electricQuantity!.tr, - rightTitle: "100%", - isHaveLine: true, - isHaveDirection: true, - action: () { - Navigator.pushNamed( - context, Routers.uploadElectricQuantityPage); - }), - CommonItem( - leftTitel: TranslationLoader.lanKeys!.periodValidity!.tr, - rightTitle: "永久", - allHeight: 70.h, - isHaveLine: false), - SizedBox( - height: 10.h, - ), - CommonItem( - leftTitel: TranslationLoader.lanKeys!.lockName!.tr, - rightTitle: "MCBN0c_8f3106", - isHaveLine: true, - isHaveDirection: true, - action: () { - Navigator.pushNamed(context, Routers.editLockNamePage); - }), - CommonItem( - leftTitel: TranslationLoader.lanKeys!.lockGrouping!.tr, - rightTitle: _groupName, - isHaveLine: true, - isHaveDirection: true, - action: () async { - var result = await Navigator.pushNamed( - context, Routers.lockSeletGroupingPage); - result as Map; - _groupName = result['groupName']; - setState(() {}); - }), - CommonItem( - leftTitel: - TranslationLoader.lanKeys!.adminOpenLockPassword!.tr, - rightTitle: "", - isHaveLine: false, - isHaveDirection: true, - action: () { - Navigator.pushNamed( - context, Routers.adminOpenLockPasswordPage); - }), - ], - ), - ), - ], - )); + body: FutureBuilder( + future: mockNetworkDataRequest(), + builder: (BuildContext context, AsyncSnapshot snapshot) { + //请求结束 + if (snapshot.connectionState == ConnectionState.done) { + if (snapshot.hasError) { + //请求失败 + return const Text('请求失败'); + } else { + //请求成功 + final LockData itemData = snapshot.data!; + + return Column( + children: [ + Expanded( + child: ListView( + children: [ + CommonItem( + leftTitel: + TranslationLoader.lanKeys!.lockNumber!.tr, + rightTitle: itemData.lockAlias, + allHeight: 70.h, + isHaveLine: true), + CommonItem( + leftTitel: "MAC/ID", + rightTitle: itemData.lockMac, + allHeight: 70.h, + isHaveLine: false), + SizedBox( + height: 10.h, + ), + CommonItem( + leftTitel: TranslationLoader + .lanKeys!.electricQuantity!.tr, + rightTitle: "${itemData.electricQuantity}%", + isHaveLine: true, + isHaveDirection: true, + action: () { + Navigator.pushNamed(context, + Routers.uploadElectricQuantityPage); + }), + CommonItem( + leftTitel: TranslationLoader + .lanKeys!.periodValidity!.tr, + rightTitle: getUseDateStr(itemData), + allHeight: 70.h, + isHaveLine: false), + SizedBox( + height: 10.h, + ), + CommonItem( + leftTitel: + TranslationLoader.lanKeys!.lockName!.tr, + rightTitle: itemData.lockName, + isHaveLine: true, + isHaveDirection: true, + action: () { + Navigator.pushNamed( + context, Routers.editLockNamePage); + }), + CommonItem( + leftTitel: + TranslationLoader.lanKeys!.lockGrouping!.tr, + rightTitle: itemData.groupName == "" + ? _groupName + : itemData.groupName, + isHaveLine: true, + isHaveDirection: true, + action: () async { + var result = await Navigator.pushNamed( + context, Routers.lockSeletGroupingPage); + result as Map; + _groupName = result['groupName']; + setState(() {}); + }), + CommonItem( + leftTitel: TranslationLoader + .lanKeys!.adminOpenLockPassword!.tr, + rightTitle: "", + isHaveLine: false, + isHaveDirection: true, + action: () { + Navigator.pushNamed(context, + Routers.adminOpenLockPasswordPage); + }), + ], + ), + ), + ], + ); + } + } else { + //请求未结束 显示loading + return Container(); + } + })); } -/* - void getLockInfo() async { - var entity = await ApiRepository.to.getLockInfo( - lastUpdateDate: DateTime.now().millisecondsSinceEpoch.toString(), - pageNo: '1', - ); - if (entity.errorCode!.codeIsSuccessful) { - // if (page == 0) { - // refreshController.refreshCompleted(); - // } else { - // if (entity.data!.keyInfos!.isEmpty) { - // refreshController.loadNoData(); - // } else { - // refreshController.loadComplete(); - // } - // } - // page++; - - if (entity.data!.keyInfos!.isEmpty) { - state.dataLength.value = 0; - } else if (entity.data!.keyInfos!.length == 1) { - state.dataLength.value = 1; + //使用期限 + String getUseDateStr(LockData indexEntity) { + String useDateStr = ''; + if (indexEntity.keyType == 1) { + //限期 + if (indexEntity.startDate != null && indexEntity.endDate != null) { + DateTime startDateStr = + DateTime.fromMillisecondsSinceEpoch(indexEntity.startDate!); + DateTime endDateStr = + DateTime.fromMillisecondsSinceEpoch(indexEntity.endDate!); + useDateStr = + '${startDateStr.toLocal().toString().substring(0, 16)}-${endDateStr.toLocal().toString().substring(0, 16)}'; } else { - state.dataLength.value = 2; + useDateStr = '限期'; } - state.lockMainEntity.value = entity; - } else { - // refreshController.loadFailed(); + } else if (indexEntity.keyType == 2) { + //永久 + useDateStr = '永久'; + } else if (indexEntity.keyType == 3) { + //单次 + useDateStr = '单次'; + } else if (indexEntity.keyType == 4) { + //循环 + useDateStr = '循环'; } - // refreshController.refreshCompleted(); + + return useDateStr; + } + + //1:限期 2:永久 3:单次 4:循环 + String getKeyTypeStr(int keyType) { + String keyTypeStr = ""; + if (keyType == 1) { + keyTypeStr = "限期"; + } else if (keyType == 2) { + keyTypeStr = '永久'; + } else if (keyType == 3) { + keyTypeStr = '单次'; + } else if (keyType == 4) { + keyTypeStr = '循环'; + } + return keyTypeStr; + } + + //请求电子钥匙列表 + Future mockNetworkDataRequest() async { + KeyDetailEntity entity = + await ApiRepository.to.getKeyDetail(keyInfo.lockId.toString()); + if (entity.errorCode!.codeIsSuccessful) { + // print("电子钥匙列表成功:${entity.data?.itemList}"); + return entity.data!; + } + LockData data = LockData(); + return data; } - */ } diff --git a/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_page.dart b/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_page.dart index ad898cbf..8281a610 100644 --- a/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_page.dart +++ b/star_lock/lib/main/lockDetail/lcokSet/lockSet/lockSet_page.dart @@ -43,7 +43,9 @@ class _LockSetPageState extends State { isHaveDirection: true, action: () { Navigator.pushNamed( - context, Routers.basicInformationPage); + context, Routers.basicInformationPage, arguments: { + 'keyInfo': state.getKeyInfosData.value + }); }), SizedBox( height: 10.h, diff --git a/star_lock/lib/network/api.dart b/star_lock/lib/network/api.dart index 450deeec..861599b2 100644 --- a/star_lock/lib/network/api.dart +++ b/star_lock/lib/network/api.dart @@ -38,4 +38,5 @@ abstract class Api { final String updateSettingURL = '/room/updateSetting'; //标记房态 final String keyGroupListURL = '/keyGroup/list'; //分组列表 final String lockListByGroupURL = '/room/listByGroup'; //分组下的锁 + final String getKeyDetailURL = '/key/get'; //获取单把钥匙详情信息 } diff --git a/star_lock/lib/network/api_provider.dart b/star_lock/lib/network/api_provider.dart index 4af64b07..4a6ffd18 100644 --- a/star_lock/lib/network/api_provider.dart +++ b/star_lock/lib/network/api_provider.dart @@ -373,6 +373,9 @@ class ApiProvider extends BaseProvider { Future lockListByGroup(String type, String keyGroupId) => post( lockListByGroupURL.toUrl, jsonEncode({'type': type, 'keyGroupId': keyGroupId})); + + Future getKeyDetail(String lockId) => + post(getKeyDetailURL.toUrl, jsonEncode({'lockId': lockId})); } extension ExtensionString on String { diff --git a/star_lock/lib/network/api_repository.dart b/star_lock/lib/network/api_repository.dart index b90d03c7..4df631d2 100644 --- a/star_lock/lib/network/api_repository.dart +++ b/star_lock/lib/network/api_repository.dart @@ -2,6 +2,7 @@ import 'package:get/get.dart'; import 'package:star_lock/login/seletCountryRegion/common/countryRegionEntity.dart'; import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyDetail/keyOperationRecordEntity.dart'; import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyList/entity/ElectronicKeyListEntity.dart'; +import 'package:star_lock/main/lockDetail/lcokSet/basicInformation/basicInformation/KeyDetailEntity.dart'; import 'package:star_lock/main/lockDetail/lcokSet/basicInformation/lockSeletGrouping/LockGroupListEntity.dart'; import 'package:star_lock/main/lockDetail/passwordKey/passwordKeyList/passwordKeyListEntity.dart'; import 'package:star_lock/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKeyEntity.dart'; @@ -362,4 +363,10 @@ class ApiRepository { final res = await apiProvider.lockListByGroup(type, keyGroupId); return PasswordKeyEntity.fromJson(res.body); } + + //获取单把钥匙详情信息 + Future getKeyDetail(String lockId) async { + final res = await apiProvider.getKeyDetail(lockId); + return KeyDetailEntity.fromJson(res.body); + } } diff --git a/star_lock/lib/tools/commonItem.dart b/star_lock/lib/tools/commonItem.dart index f99e5928..0c5b8d68 100644 --- a/star_lock/lib/tools/commonItem.dart +++ b/star_lock/lib/tools/commonItem.dart @@ -61,6 +61,8 @@ class CommonItem extends StatelessWidget { : Text( rightTitle!, textAlign: TextAlign.end, + overflow: TextOverflow.ellipsis, + maxLines: 1, style: TextStyle( fontSize: 22.sp, color: AppColors.darkGrayTextColor),