1,新增获取单把钥匙详情借口

2,锁设置-基本信息逻辑处理
This commit is contained in:
Daisy 2023-09-04 15:04:44 +08:00
parent d8c68b5ac7
commit cf5b7e6212
7 changed files with 323 additions and 100 deletions

View File

@ -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<String, dynamic> json) {
errorCode = json['errorCode'];
description = json['description'];
errorMsg = json['errorMsg'];
data = json['data'] != null ? LockData.fromJson(json['data']) : null;
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
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<String, dynamic> 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<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
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<String, dynamic> json) {
lockName = json['lockName'];
lockMac = json['lockMac'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['lockName'] = lockName;
data['lockMac'] = lockMac;
return data;
}
}

View File

@ -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<BasicInformationPage> {
late String _groupName = "";
late KeyInfos keyInfo;
late LockMainEntity lockMainEntity;
@override
void initState() {
@ -28,115 +34,168 @@ class _BasicInformationPageState extends State<BasicInformationPage> {
@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<String, dynamic>;
_groupName = result['groupName'];
setState(() {});
}),
CommonItem(
leftTitel:
TranslationLoader.lanKeys!.adminOpenLockPassword!.tr,
rightTitle: "",
isHaveLine: false,
isHaveDirection: true,
action: () {
Navigator.pushNamed(
context, Routers.adminOpenLockPasswordPage);
}),
],
),
),
],
));
body: FutureBuilder<LockData>(
future: mockNetworkDataRequest(),
builder: (BuildContext context, AsyncSnapshot<LockData> 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<String, dynamic>;
_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<LockData> 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;
}
*/
}

View File

@ -43,7 +43,9 @@ class _LockSetPageState extends State<LockSetPage> {
isHaveDirection: true,
action: () {
Navigator.pushNamed(
context, Routers.basicInformationPage);
context, Routers.basicInformationPage, arguments: {
'keyInfo': state.getKeyInfosData.value
});
}),
SizedBox(
height: 10.h,

View File

@ -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'; //
}

View File

@ -373,6 +373,9 @@ class ApiProvider extends BaseProvider {
Future<Response> lockListByGroup(String type, String keyGroupId) => post(
lockListByGroupURL.toUrl,
jsonEncode({'type': type, 'keyGroupId': keyGroupId}));
Future<Response> getKeyDetail(String lockId) =>
post(getKeyDetailURL.toUrl, jsonEncode({'lockId': lockId}));
}
extension ExtensionString on String {

View File

@ -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<KeyDetailEntity> getKeyDetail(String lockId) async {
final res = await apiProvider.getKeyDetail(lockId);
return KeyDetailEntity.fromJson(res.body);
}
}

View File

@ -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),