From 5e40916e569b4ad470d7ff649896618e295b0c44 Mon Sep 17 00:00:00 2001 From: anfe <448468458@qq.com> Date: Thu, 6 Jun 2024 09:57:36 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat:=E4=B8=BB=E5=8A=A8=E5=BC=95=E5=AF=BC?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=BC=80=E5=90=AF=E6=8E=A8=E9=80=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- images/lan/lan_en.json | 4 +- images/lan/lan_keys.json | 4 +- images/lan/lan_zh.json | 3 +- .../lockMian/lockMain/lockMain_logic.dart | 69 ++++++++++++------- lib/main/lockMian/lockMain/lockMain_page.dart | 3 - 5 files changed, 54 insertions(+), 29 deletions(-) diff --git a/images/lan/lan_en.json b/images/lan/lan_en.json index 447da036..101e886b 100755 --- a/images/lan/lan_en.json +++ b/images/lan/lan_en.json @@ -867,5 +867,7 @@ "自定义短信模版":"Custom SMS template", "自定义邮件模版":"Custom email template", "名称":"Name", - "星星锁": "Star lock" + "星星锁": "Star lock", + "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "To receive important updates, please click 'OK' and enable notifications in the settings." + } diff --git a/images/lan/lan_keys.json b/images/lan/lan_keys.json index 1f83013b..c8130c70 100755 --- a/images/lan/lan_keys.json +++ b/images/lan/lan_keys.json @@ -899,5 +899,7 @@ "自定义短信模版":"自定义短信模版", "自定义邮件模版":"自定义邮件模版", "名称":"名称", - "星星锁": "星星锁" + "星星锁": "星星锁", + "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。" + } diff --git a/images/lan/lan_zh.json b/images/lan/lan_zh.json index 3c3bedf6..193c6d36 100755 --- a/images/lan/lan_zh.json +++ b/images/lan/lan_zh.json @@ -867,5 +867,6 @@ "自定义短信模版":"自定义短信模版", "自定义邮件模版":"自定义邮件模版", "名称":"名称", - "星星锁": "星星锁" + "星星锁": "星星锁", + "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。" } diff --git a/lib/main/lockMian/lockMain/lockMain_logic.dart b/lib/main/lockMian/lockMain/lockMain_logic.dart index 50c0c767..7b006eb1 100755 --- a/lib/main/lockMian/lockMain/lockMain_logic.dart +++ b/lib/main/lockMian/lockMain/lockMain_logic.dart @@ -1,7 +1,11 @@ import 'dart:async'; +import 'dart:io'; import 'package:connectivity_plus/connectivity_plus.dart'; +import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:get/get.dart'; +import 'package:permission_handler/permission_handler.dart'; import 'package:star_lock/main/lockMian/lockList/lockList_logic.dart'; +import 'package:star_lock/tools/showTipView.dart'; import '../../../app_settings/app_settings.dart'; import '../../../blue/blue_manage.dart'; @@ -17,7 +21,8 @@ class LockMainLogic extends BaseGetXController { Future getStarLockInfo( {bool isUnShowLoading = false}) async { - LockListInfoEntity entity = await ApiRepository.to.getStarLockListInfo( + final LockListInfoEntity entity = + await ApiRepository.to.getStarLockListInfo( pageNo: pageNo, pageSize: 50, isUnShowLoading: isUnShowLoading, @@ -59,33 +64,35 @@ class LockMainLogic extends BaseGetXController { /// 获取联网类型 void getConnectType() async { - var connectResult = await (Connectivity().checkConnectivity()); + final ConnectivityResult connectResult = + await (Connectivity().checkConnectivity()); if (connectResult == ConnectivityResult.mobile) { // _netType = "4G"; state.networkConnectionStatus.value = 1; - AppLog.log("网络连接: 4G 4G 4G 4G 4G"); + AppLog.log('网络连接: 4G 4G 4G 4G 4G'); } else if (connectResult == ConnectivityResult.wifi) { // _netType = "wifi"; state.networkConnectionStatus.value = 1; - AppLog.log("网络连接: wifi wifi wifi wifi wifi"); + AppLog.log('网络连接: wifi wifi wifi wifi wifi'); } else { // _netType = "未连接"; state.networkConnectionStatus.value = 0; - AppLog.log("网络连接: 未连接 未连接 未连接 未连接 未连接"); + AppLog.log('网络连接: 未连接 未连接 未连接 未连接 未连接'); // showToast("网络访问失败,请检查网络是否正常"); } } /// 判断网络是否连接 Future isConnected() async { - var connectResult = await (Connectivity().checkConnectivity()); + final ConnectivityResult connectResult = + await Connectivity().checkConnectivity(); return connectResult != ConnectivityResult.none; } /// 设置网络切换监听 - connectListener() async { + Future connectListener() async { Connectivity().onConnectivityChanged.listen((ConnectivityResult result) { - AppLog.log("设置网络切换监听:$result"); + AppLog.log('设置网络切换监听:$result'); if (state.networkConnectionStatus.value == 0 && result != ConnectivityResult.none) { // 从无网络到有网络 @@ -95,36 +102,52 @@ class LockMainLogic extends BaseGetXController { }); } + /// 检测推送是否开启 + Future checkWhetherPushIsEnabled() async { + bool notificationEnabled = false; + + if (Platform.isAndroid) { + notificationEnabled = await FlutterLocalNotificationsPlugin() + .resolvePlatformSpecificImplementation< + AndroidFlutterLocalNotificationsPlugin>() + ?.areNotificationsEnabled() ?? + false; + } else if (Platform.isIOS) { + notificationEnabled = await FlutterLocalNotificationsPlugin() + .resolvePlatformSpecificImplementation< + IOSFlutterLocalNotificationsPlugin>() + ?.requestPermissions( + alert: true, + badge: false, + sound: true, + ) ?? + false; + } + if (!notificationEnabled) { + //推送未开启 + ShowTipView().showIosTipWithContentDialog( + '为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。'.tr, () async { + openAppSettings(); + }); + } + } + @override void onReady() { - // TODO: implement onReady super.onReady(); - // 开启UDP UdpHelp().openUDP(); - BlueManage(); } @override void onInit() { - // TODO: implement onInit super.onInit(); - - // getLockInfo(); - // 设置网络变化监听 - // connectListener(); - // 获取网络连接状态 - // getConnectType(); + checkWhetherPushIsEnabled(); } @override void onClose() { - // TODO: implement onClose super.onClose(); - - // refreshController.dispose(); - // _teamEvent.cancel(); - // state.timer.cancel(); } } diff --git a/lib/main/lockMian/lockMain/lockMain_page.dart b/lib/main/lockMian/lockMain/lockMain_page.dart index 34319dbe..b23b80c4 100755 --- a/lib/main/lockMian/lockMain/lockMain_page.dart +++ b/lib/main/lockMian/lockMain/lockMain_page.dart @@ -54,9 +54,6 @@ class _StarLockMainPageState extends State with BaseWidget { WidgetsBinding.instance.addPostFrameCallback((_) async { setState(() {}); }); - // if (mounted) { - // setSŒe(() {}); - // } } @override From 7f0087d1531888a6f5670eef59ff4706ad24394a Mon Sep 17 00:00:00 2001 From: anfe <448468458@qq.com> Date: Thu, 6 Jun 2024 11:28:02 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat:=E6=90=9C=E7=B4=A2=E6=A8=A1=E5=BC=8F?= =?UTF-8?q?=EF=BC=8C=E5=88=A4=E6=96=AD=E8=AE=BE=E5=A4=87=E8=A2=AB=E9=87=8D?= =?UTF-8?q?=E7=BD=AE=E7=9A=84=E6=97=B6=E5=80=99=E9=87=8D=E7=BD=AE=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=BC=93=E5=AD=98=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/blue/blue_manage.dart | 40 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/blue/blue_manage.dart b/lib/blue/blue_manage.dart index 30e39212..6a26d88e 100755 --- a/lib/blue/blue_manage.dart +++ b/lib/blue/blue_manage.dart @@ -325,7 +325,8 @@ class BlueManage { mac != null) { scanSingleTimer?.cancel(); //兼容android 的低配手机 - await doNotSearchBLE(mac, connectStateCallBack); + await doNotSearchBLE(mac, connectStateCallBack, + isAddEquipment: isAddEquipment); scanSingleTimer = Timer(3.seconds, () { scanSingleTimer?.cancel(); startScanSingle(deviceName, 15, (List scanDevices) => null); @@ -384,6 +385,7 @@ class BlueManage { isAddEquipment == false) { connectStateCallBack(BluetoothConnectionState.disconnected); EasyLoading.showToast('该锁已被重置'.tr, duration: 2000.milliseconds); + scanDevices.clear(); return; } //尝试连接设备 @@ -392,7 +394,8 @@ class BlueManage { //直接给蓝牙设备写入 Future doNotSearchBLE( - String masAdds, ConnectStateCallBack connectStateCallBack) async { + String masAdds, ConnectStateCallBack connectStateCallBack, + {bool isAddEquipment = false}) async { await FlutterBluePlus.stopScan(); if (bluetoothConnectDevice == null || bluetoothConnectDevice?.remoteId.str != masAdds) { @@ -401,12 +404,14 @@ class BlueManage { _initListenConnectionState(); } //尝试连接设备 - await bluetoothDeviceConnect(bluetoothConnectDevice!, connectStateCallBack); + await bluetoothDeviceConnect(bluetoothConnectDevice!, connectStateCallBack, + isAddEquipment: isAddEquipment); } //设备连接 Future bluetoothDeviceConnect(BluetoothDevice bluetoothConnectDevice, - ConnectStateCallBack connectStateCallBack) async { + ConnectStateCallBack connectStateCallBack, + {bool isAddEquipment = false}) async { // 重连三次 const int maxAttempts = 3; int attempt = 0; @@ -430,23 +435,22 @@ class BlueManage { if (bluetoothConnectionState == BluetoothConnectionState.connected) { try { - bluetoothConnectDevice! - .discoverServices() - .then((List services) { - for (final BluetoothService service in services) { - if (service.uuid == _serviceIdConnect) { - for (final BluetoothCharacteristic characteristic - in service.characteristics) { - if (characteristic.characteristicUuid == - _characteristicIdSubscription) { - _subScribeToCharacteristic(characteristic); - bluetoothConnectionState = BluetoothConnectionState.connected; - connectStateCallBack(bluetoothConnectionState!); - } + final List services = + await bluetoothConnectDevice.discoverServices(); + //循环判断服务 + for (final BluetoothService service in services) { + if (service.uuid == _serviceIdConnect) { + for (final BluetoothCharacteristic characteristic + in service.characteristics) { + if (characteristic.characteristicUuid == + _characteristicIdSubscription) { + _subScribeToCharacteristic(characteristic); + bluetoothConnectionState = BluetoothConnectionState.connected; + connectStateCallBack(bluetoothConnectionState!); } } } - }); + } } on Exception catch (e) { bluetoothConnectionState = BluetoothConnectionState.disconnected; connectStateCallBack(bluetoothConnectionState!); From 7d01b9a05620fa0abf14a07b4ab238a40bb9c0a7 Mon Sep 17 00:00:00 2001 From: Daisy <> Date: Thu, 6 Jun 2024 13:58:21 +0800 Subject: [PATCH 3/5] =?UTF-8?q?1=EF=BC=8C=E6=96=B0=E5=BB=BA=E9=82=AE?= =?UTF-8?q?=E4=BB=B6=E6=A8=A1=E7=89=88=EF=BC=88=E7=94=B5=E5=AD=90=E9=92=A5?= =?UTF-8?q?=E5=8C=99=E3=80=81=E5=AF=86=E7=A0=81=EF=BC=89API=E5=AF=B9?= =?UTF-8?q?=E6=8E=A5=E5=8F=8A=E5=85=BC=E5=AE=B9=E7=9F=AD=E4=BF=A1=E6=A8=A1?= =?UTF-8?q?=E7=89=88=202=EF=BC=8C=E5=88=A0=E9=99=A4=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E6=A8=A1=E7=89=88API=E5=AF=B9=E6=8E=A5=E5=8F=8A=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E9=80=BB=E8=BE=91=E5=A4=84=E7=90=86=203=EF=BC=8C?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=AE=A1=E7=AE=97=E7=9F=AD=E4=BF=A1=E6=9D=A1?= =?UTF-8?q?=E6=95=B0=E5=87=BD=E6=95=B0=E5=8F=8A=E6=9B=B4=E6=96=B0=E5=B8=83?= =?UTF-8?q?=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../newSMSTemplate_logic.dart | 184 +++++++++++++----- .../newSMSTemplate_page.dart | 54 ++--- .../newSMSTemplate_state.dart | 7 +- .../customSMSTemplateList_logic.dart | 181 ++++++----------- 4 files changed, 227 insertions(+), 199 deletions(-) diff --git a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_logic.dart b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_logic.dart index 0bd6c527..0c149a5d 100644 --- a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_logic.dart +++ b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_logic.dart @@ -15,7 +15,7 @@ class NewSMSTemplateLogic extends BaseGetXController { //获取默认模板-- 1:电子钥匙 2:密码 Future getDefaultTemplate() async { final NewSMSTemplateEntity entity = await ApiRepository.to - .getDefaultTemplate(type: state.currentTemplate.value.type ?? 0); + .getDefaultTemplate(type: state.templateType.value); if (entity.errorCode!.codeIsSuccessful) { state.templateList.value = entity.dataList ?? []; if (state.templateList.isNotEmpty) { @@ -59,9 +59,32 @@ class NewSMSTemplateLogic extends BaseGetXController { } } - List buildElectronicKeySpan({required bool isPreview}) { - final List textSpans = []; + // 更新短信条数的函数 + void updateSmsCost(String template) { + state.smsCost.value = calculateSmsCost(template); + } + int calculateSmsCost(String template) { + final int smsCount = template.length; + if (smsCount <= 70) { + return 1; + } else { + return (smsCount / 67).ceil(); + } + } + + //构建电子钥匙模板 + List buildElectronicKeySpan({required bool isPreview}) { + //短信模版 + if (state.templateType.value == 1) { + return _buildSMSElectronicKey(isPreview); + } else { + return _buildEmailElectronicKey(isPreview); + } + } + + List _buildSMSElectronicKey(bool isPreview) { + final List textSpans = []; // 如果是预览模式,添加预览模板的文本 if (isPreview) { textSpans.add( @@ -74,7 +97,7 @@ class NewSMSTemplateLogic extends BaseGetXController { // 将模板分割为文本片段 final List textFragments = state.currentTemplate.value.template ?.split(RegularExpression.urlRegExp) ?? - []; + []; // 添加链接文本和普通文本到文本片段列表 for (int i = 0; i < textFragments.length; i++) { @@ -115,7 +138,62 @@ class NewSMSTemplateLogic extends BaseGetXController { ), ); } + return textSpans; + } + List _buildEmailElectronicKey(bool isPreview) { + final List textSpans = []; + + //邮件模版 + // 如果是预览模式,添加预览模板的文本 + if (isPreview) { + textSpans.add( + TextSpan( + text: '${state.templateOneTf.text}\n', + style: state.defaultStyle, + ), + ); + } else { + String template = state.currentTemplate.value.template ?? ''; + template = template.replaceAll(',', ',\n'); + + // 定义匹配 ${} 包围的变量的正则表达式 + final RegExp variableRegExp = RegExp(r'\{([^}]+)\}'); + final Iterable matches = variableRegExp.allMatches(template); + + int start = 0; + for (final Match match in matches) { + // 添加非变量文本 + if (match.start > start) { + textSpans.add( + TextSpan( + text: template.substring(start, match.start), + style: state.defaultStyle, + ), + ); + } + + // 添加变量文本 + textSpans.add( + TextSpan( + text: match.group(0), + style: state.highStyle, + ), + ); + + start = match.end; + } + + // 添加剩余的非变量文本 + if (start < template.length) { + textSpans.add( + TextSpan( + text: template.substring(start), + style: state.defaultStyle, + ), + ); + } + } return textSpans; } @@ -132,64 +210,68 @@ class NewSMSTemplateLogic extends BaseGetXController { ); } - // 定义匹配 ${} 包围的变量的正则表达式 - final RegExp variableRegExp = RegExp(r'\$\{([^}]+)\}'); + //短信模版才需要加默认模版 + if (state.templateType == 1 || + (state.templateType == 2 && isPreview == false)) { + // 定义匹配 ${} 包围的变量的正则表达式 + final RegExp variableRegExp = RegExp(r'\$\{([^}]+)\}'); - final String template = state.currentTemplate.value.template ?? ''; + final String template = state.currentTemplate.value.template ?? ''; - // 对模板进行处理 - int startIndex = 0; - for (final Match match in variableRegExp.allMatches(template)) { - // 处理变量之前的文本 - final String nonVariableText = - template.substring(startIndex, match.start); + // 对模板进行处理 + int startIndex = 0; + for (final Match match in variableRegExp.allMatches(template)) { + // 处理变量之前的文本 + final String nonVariableText = + template.substring(startIndex, match.start); + // 替换非变量文本中的字符 + final String replacedNonVariableText = + nonVariableText.replaceAllMapped(RegExp(r',|。'), (Match match) { + return '${match.group(0)}\n'; + }); + textSpans.add( + TextSpan( + text: replacedNonVariableText, + style: state.defaultStyle, + ), + ); + + // 处理变量 + final String variableText = match.group(0) ?? ''; + textSpans.add( + TextSpan( + text: variableText, + style: state.highStyle, + ), + ); + + // 更新起始索引 + startIndex = match.end; + } + + // 添加最后一个变量之后的文本 + final String remainingText = template.substring(startIndex); // 替换非变量文本中的字符 - final String replacedNonVariableText = - nonVariableText.replaceAllMapped(RegExp(r',|。'), (Match match) { + final String replacedRemainingText = + remainingText.replaceAllMapped(RegExp(r',|。'), (Match match) { return '${match.group(0)}\n'; }); textSpans.add( TextSpan( - text: replacedNonVariableText, + text: replacedRemainingText, style: state.defaultStyle, ), ); - // 处理变量 - final String variableText = match.group(0) ?? ''; - textSpans.add( - TextSpan( - text: variableText, - style: state.highStyle, - ), - ); - - // 更新起始索引 - startIndex = match.end; - } - - // 添加最后一个变量之后的文本 - final String remainingText = template.substring(startIndex); - // 替换非变量文本中的字符 - final String replacedRemainingText = - remainingText.replaceAllMapped(RegExp(r',|。'), (Match match) { - return '${match.group(0)}\n'; - }); - textSpans.add( - TextSpan( - text: replacedRemainingText, - style: state.defaultStyle, - ), - ); - - // 在预览模式下,添加预览模板的文本 - if (isPreview) { - textSpans.add( - TextSpan( - text: '\n${state.templateTwoTf.text}', - style: state.defaultStyle, - ), - ); + // 在预览模式下,添加预览模板的文本 + if (isPreview) { + textSpans.add( + TextSpan( + text: '\n${state.templateTwoTf.text}', + style: state.defaultStyle, + ), + ); + } } return textSpans; diff --git a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_page.dart b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_page.dart index b61a7e2e..afee8c2f 100755 --- a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_page.dart +++ b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_page.dart @@ -28,7 +28,7 @@ class _NewSMSTemplatePageState extends State { return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( - barTitle: state.templateType.value == 1 ? '新建短信模版'.tr : '新建邮件模版'.tr, + barTitle: state.templateType == 1 ? '新建短信模版'.tr : '新建邮件模版'.tr, haveBack: true, backgroundColor: AppColors.mainColor, ), @@ -109,18 +109,24 @@ class _NewSMSTemplatePageState extends State { height: 100, child: _buildTextField(state.templateOneTf), ), - Obx(() => _buildTemplateWithType(isPreview: false)), + Obx(() => Container( + width: 1.sw - 50.w, + margin: EdgeInsets.only(left: 25.w, right: 25.w), + child: _buildTemplateWithType(isPreview: false), + )), SizedBox(height: 10.h), - Container( - margin: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.h), - height: 100, - child: Stack( - alignment: Alignment.bottomRight, - children: [ - _buildTextField(state.templateTwoTf), - ], - ), - ), + Obx(() => Visibility( + visible: state.templateType.value == 1, + child: Container( + margin: EdgeInsets.symmetric(horizontal: 25.w, vertical: 25.h), + height: 100, + child: Stack( + alignment: Alignment.bottomRight, + children: [ + _buildTextField(state.templateTwoTf), + ], + ), + ))), ], ), ); @@ -144,7 +150,9 @@ class _NewSMSTemplatePageState extends State { ), ), Obx(() => Container( + width: 1.sw - 50.w, margin: EdgeInsets.only(left: 25.w, right: 25.w), + padding: EdgeInsets.only(left: 20.w, right: 20.w, top: 10.h), decoration: BoxDecoration( color: const Color(0xFFF5F5F5), borderRadius: BorderRadius.circular(10.h), @@ -158,7 +166,7 @@ class _NewSMSTemplatePageState extends State { bottom: 25.h, ), child: Text( - '预计产生短信条数:2', + '预计产生短信条数:${state.smsCost.value}', style: TextStyle( color: Colors.grey, fontSize: 20.sp, @@ -176,19 +184,12 @@ class _NewSMSTemplatePageState extends State { state.currentTemplate.value.template!.isEmpty) { return const SizedBox.shrink(); // 如果为空,返回一个空的 SizedBox } else { - return Row( - children: [ - Padding( - padding: EdgeInsets.symmetric(horizontal: 25.w, vertical: 10.h), - child: Obx(() => RichText( - text: TextSpan( - children: state.currentTemplate.value.typeName == '电子钥匙' - ? logic.buildElectronicKeySpan(isPreview: isPreview) - : logic.buildPasswordSpan(isPreview: isPreview), - ), - )), - ), - ], + return RichText( + text: TextSpan( + children: state.currentTemplate.value.typeName == '电子钥匙' + ? logic.buildElectronicKeySpan(isPreview: isPreview) + : logic.buildPasswordSpan(isPreview: isPreview), + ), ); } } @@ -213,6 +214,7 @@ class _NewSMSTemplatePageState extends State { onChanged: (String value) { setState(() { controller.text = value; + logic.updateSmsCost(value); // 更新短信条数 }); }, ); diff --git a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_state.dart b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_state.dart index 2da43402..d2b540d2 100644 --- a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_state.dart +++ b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesAddSMSTemplate/newSMSTemplate_state.dart @@ -30,7 +30,8 @@ class NewSMSTemplateState { RxBool isVip = false.obs; RxList templateList = [].obs; - Rx currentTemplate = SMSTemplateData().obs; - RxBool isShowDate = false.obs; - RxInt templateType = 0.obs; + Rx currentTemplate = SMSTemplateData().obs; //当前模板信息 + RxBool isShowDate = false.obs; //是否显示日期 + RxInt templateType = 0.obs; //1:短信 2:邮件 + RxInt smsCost = 0.obs; //短信条数 } diff --git a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart index 12c38ebf..af8e5d31 100644 --- a/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart +++ b/lib/mine/valueAddedServices/valueAddedServicesSMSTemplate/valueAddedServicesListSMSTemplate/customSMSTemplateList_logic.dart @@ -12,9 +12,8 @@ import '../../../../tools/baseGetXController.dart'; class CustomSMSTemplateListLogic extends BaseGetXController { CustomSMSTemplateListState state = CustomSMSTemplateListState(); - //获取短信模板列表 + // 获取短信模板列表 Future getSMSTemplateListRequest({required bool isRefresh}) async { - // 如果是下拉刷新,清空已有数据 if (isRefresh) { state.smsTemplateList.clear(); pageNo = 1; @@ -31,7 +30,7 @@ class CustomSMSTemplateListLogic extends BaseGetXController { } } - //删除短信模版 + // 删除短信模板 Future deleteSMSTemplateRequest({required int id}) async { final LoginEntity entity = await ApiRepository.to.deleteTemplateInfo(id: id); @@ -42,131 +41,75 @@ class CustomSMSTemplateListLogic extends BaseGetXController { List buildElectronicKeySpan( {required CustomSMSTemplateItem templateData}) { - final List textSpans = []; - - textSpans.add( - TextSpan( - text: '${templateData.regards}\n', - style: state.defaultStyle, - ), - ); - // 将模板分割为文本片段 - final List textFragments = - templateData.template?.split(RegularExpression.urlRegExp) ?? []; - - // 添加链接文本和普通文本到文本片段列表 - for (int i = 0; i < textFragments.length; i++) { - final String textFragment = textFragments[i]; - // 添加普通文本 - textSpans.add( - TextSpan( - text: textFragment, - style: state.defaultStyle, - ), - ); - // 如果不是最后一个文本片段,则添加换行符 - if (i < textFragments.length - 1) { - textSpans.add( - TextSpan( - text: '\n', - style: state.defaultStyle, - ), - ); - // 添加链接文本 - textSpans.add( - TextSpan( - text: RegularExpression.urlRegExp - .stringMatch(templateData.template!) ?? - '', - style: state.highStyle, - ), - ); - } - } - - textSpans.add( - TextSpan( - text: '\n${templateData.tips}', - style: state.defaultStyle, - ), - ); - + final List textSpans = []; + _addTextSpan(textSpans, '${templateData.regards}\n', state.defaultStyle); + _buildTextSpansFromTemplate( + textSpans, templateData.template, state.defaultStyle, state.highStyle); + _addTextSpan(textSpans, '\n${templateData.tips}', state.defaultStyle); return textSpans; } List buildPasswordSpan( {required CustomSMSTemplateItem templateData}) { - final List textSpans = []; - - textSpans.add( - TextSpan( - text: '${templateData.regards}\n', - style: state.defaultStyle, - ), - ); - - // 定义匹配 ${} 包围的变量的正则表达式 - final RegExp variableRegExp = RegExp(r'\$\{([^}]+)\}'); - - final String template = templateData.template ?? ''; - - // 对模板进行处理 - int startIndex = 0; - for (final Match match in variableRegExp.allMatches(template)) { - // 处理变量之前的文本 - final String nonVariableText = - template.substring(startIndex, match.start); - // 替换非变量文本中的字符 - final String replacedNonVariableText = - nonVariableText.replaceAllMapped(RegExp(r',|。'), (Match match) { - return '${match.group(0)}\n'; - }); - textSpans.add( - TextSpan( - text: replacedNonVariableText, - style: state.defaultStyle, - ), - ); - - // 处理变量 - final String variableText = match.group(0) ?? ''; - textSpans.add( - TextSpan( - text: variableText, - style: state.highStyle, - ), - ); - - // 更新起始索引 - startIndex = match.end; - } - - // 添加最后一个变量之后的文本 - final String remainingText = template.substring(startIndex); - // 替换非变量文本中的字符 - final String replacedRemainingText = - remainingText.replaceAllMapped(RegExp(r',|。'), (Match match) { - return '${match.group(0)}\n'; - }); - textSpans.add( - TextSpan( - text: replacedRemainingText, - style: state.defaultStyle, - ), - ); - - textSpans.add( - TextSpan( - text: '\n${templateData.tips}', - style: state.defaultStyle, - ), - ); - + final List textSpans = []; + _addTextSpan(textSpans, '${templateData.regards}\n', state.defaultStyle); + _buildPasswordTextSpans( + textSpans, templateData.template, state.defaultStyle, state.highStyle); + _addTextSpan(textSpans, '\n${templateData.tips}', state.defaultStyle); return textSpans; } + void _buildTextSpansFromTemplate(List textSpans, String? template, + TextStyle defaultStyle, TextStyle highStyle) { + final List textFragments = + template?.split(RegularExpression.urlRegExp) ?? []; + for (int i = 0; i < textFragments.length; i++) { + _addTextSpan(textSpans, textFragments[i], defaultStyle); + if (i < textFragments.length - 1) { + _addTextSpan(textSpans, '\n', defaultStyle); + _addTextSpan( + textSpans, + RegularExpression.urlRegExp.stringMatch(template!) ?? '', + highStyle); + } + } + } + + void _buildPasswordTextSpans(List textSpans, String? template, + TextStyle defaultStyle, TextStyle highStyle) { + final RegExp variableRegExp = RegExp(r'\$\{([^}]+)\}'); + final String text = template ?? ''; + int startIndex = 0; + + for (final Match match in variableRegExp.allMatches(text)) { + _addTextSpan( + textSpans, + text + .substring(startIndex, match.start) + .replaceAllMapped(RegExp(r',|。'), (Match match) { + return '${match.group(0)}\n'; + }), + defaultStyle); + _addTextSpan(textSpans, match.group(0) ?? '', highStyle); + startIndex = match.end; + } + + _addTextSpan( + textSpans, + text.substring(startIndex).replaceAllMapped(RegExp(r',|。'), + (Match match) { + return '${match.group(0)}\n'; + }), + defaultStyle); + } + + void _addTextSpan(List textSpans, String text, TextStyle style) { + textSpans.add(TextSpan(text: text, style: style)); + } + @override - onReady() async { + Future onReady() async { + super.onReady(); var isVip = await Storage.getBool(saveIsVip); state.isVip.value = isVip ?? false; } From 425a68843e7b513934079285068ea30db362b071 Mon Sep 17 00:00:00 2001 From: Daisy <> Date: Thu, 6 Jun 2024 15:56:23 +0800 Subject: [PATCH 4/5] =?UTF-8?q?1=EF=BC=8C=E4=BF=AE=E5=A4=8DIOSAPP=E4=B8=8A?= =?UTF-8?q?=E6=9C=89=E6=98=BE=E7=A4=BA=E6=95=B0=E5=AD=97=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E4=B8=8D=E6=98=AF=E6=9C=AA=E8=AF=BB=E6=B6=88=E6=81=AF=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E9=87=8F=202=EF=BC=8C=E4=BF=AE=E6=94=B9=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E9=A1=B5-=E8=AE=BE=E7=BD=AE-=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E9=94=AE=E5=A4=87=E6=B3=A8=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- images/lan/lan_en.json | 3 +- images/lan/lan_keys.json | 3 +- images/lan/lan_zh.json | 3 +- ios/Runner/AppDelegate.m | 4 +- .../lockSet/resetButton/resetButton_page.dart | 49 +++++++++++-------- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/images/lan/lan_en.json b/images/lan/lan_en.json index 101e886b..ec433bbf 100755 --- a/images/lan/lan_en.json +++ b/images/lan/lan_en.json @@ -868,6 +868,7 @@ "自定义邮件模版":"Custom email template", "名称":"Name", "星星锁": "Star lock", - "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "To receive important updates, please click 'OK' and enable notifications in the settings." + "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "To receive important updates, please click 'OK' and enable notifications in the settings.", + "开启后,可通过长按锁上的设置键重新上电,用APP重新添加":"After turning on, you can re-power on by long pressing the setting key on the lock, and re-add it with the APP" } diff --git a/images/lan/lan_keys.json b/images/lan/lan_keys.json index c8130c70..8f758a6b 100755 --- a/images/lan/lan_keys.json +++ b/images/lan/lan_keys.json @@ -900,6 +900,7 @@ "自定义邮件模版":"自定义邮件模版", "名称":"名称", "星星锁": "星星锁", - "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。" + "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。", + "开启后,可通过长按锁上的设置键重新上电,用APP重新添加":"开启后,可通过长按锁上的设置键重新上电,用APP重新添加" } diff --git a/images/lan/lan_zh.json b/images/lan/lan_zh.json index 193c6d36..73db333a 100755 --- a/images/lan/lan_zh.json +++ b/images/lan/lan_zh.json @@ -868,5 +868,6 @@ "自定义邮件模版":"自定义邮件模版", "名称":"名称", "星星锁": "星星锁", - "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。" + "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。", + "开启后,可通过长按锁上的设置键重新上电,用APP重新添加":"开启后,可通过长按锁上的设置键重新上电,用APP重新添加" } diff --git a/ios/Runner/AppDelegate.m b/ios/Runner/AppDelegate.m index 87707e2d..3514fd7a 100755 --- a/ios/Runner/AppDelegate.m +++ b/ios/Runner/AppDelegate.m @@ -71,14 +71,14 @@ // iOS 8 Notifications [application registerUserNotificationSettings: [UIUserNotificationSettings settingsForTypes: - (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) + (UIUserNotificationTypeSound | UIUserNotificationTypeAlert) categories:nil]]; [application registerForRemoteNotifications]; } else { // iOS < 8 Notifications [[UIApplication sharedApplication] registerForRemoteNotificationTypes: - (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; + (UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)]; } } /* diff --git a/lib/main/lockDetail/lockSet/resetButton/resetButton_page.dart b/lib/main/lockDetail/lockSet/resetButton/resetButton_page.dart index ab2bfcae..936adeec 100755 --- a/lib/main/lockDetail/lockSet/resetButton/resetButton_page.dart +++ b/lib/main/lockDetail/lockSet/resetButton/resetButton_page.dart @@ -1,11 +1,10 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; +import '../../../../flavors.dart'; import '../../../../app_settings/app_colors.dart'; -import '../../../../blue/blue_manage.dart'; import '../../../../tools/appRouteObserver.dart'; import '../../../../tools/showTipView.dart'; import '../../../../tools/submitBtn.dart'; @@ -23,7 +22,7 @@ class ResetButtonPage extends StatefulWidget { class _ResetButtonPageState extends State with RouteAware { final logic = Get.put(ResetButtonLogic()); final state = Get.find().state; - + @override Widget build(BuildContext context) { return Scaffold( @@ -44,10 +43,16 @@ class _ResetButtonPageState extends State with RouteAware { mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - TranslationLoader.lanKeys!.resetButtonTip1!.tr, - style: TextStyle(fontSize: 20.sp), - ), + if (F.isSKY) + Text( + TranslationLoader.lanKeys!.resetButtonTip1!.tr, + style: TextStyle(fontSize: 20.sp), + ) + else + Text( + '开启后,可通过长按锁上的设置键重新上电,用APP重新添加'.tr, + style: TextStyle(fontSize: 20.sp), + ), SizedBox( height: 10.h, ), @@ -63,35 +68,38 @@ class _ResetButtonPageState extends State with RouteAware { height: 30.h, ), Obx(() => Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Expanded( - child: Text( - "${TranslationLoader.lanKeys!.currentMode!.tr} : ${state.resetButtonEnable.value == 1 ? TranslationLoader.lanKeys!.opened!.tr : TranslationLoader.lanKeys!.closed!.tr}", - style: - TextStyle(fontWeight: FontWeight.w600, fontSize: 20.sp), + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Expanded( + child: Text( + "${TranslationLoader.lanKeys!.currentMode!.tr} : ${state.resetButtonEnable.value == 1 ? TranslationLoader.lanKeys!.opened!.tr : TranslationLoader.lanKeys!.closed!.tr}", + style: TextStyle( + fontWeight: FontWeight.w600, fontSize: 20.sp), )), - ], - )), + ], + )), SizedBox( height: 30.h, ), Obx(() => SubmitBtn( - btnName: state.resetButtonEnable.value == 1 ? TranslationLoader.lanKeys!.close!.tr : TranslationLoader.lanKeys!.open!.tr, + btnName: state.resetButtonEnable.value == 1 + ? TranslationLoader.lanKeys!.close!.tr + : TranslationLoader.lanKeys!.open!.tr, borderRadius: 20.w, fontSize: 32.sp, // margin: EdgeInsets.only(left: 03.w, right: 30.w, top: 20.w), padding: EdgeInsets.only(top: 20.w, bottom: 20.w), onClick: () { // showDeletAlertTipDialog(context); - ShowTipView().showIosTipWithContentDialog('确定要${state.resetButtonEnable.value == 1 ? TranslationLoader.lanKeys!.close!.tr : TranslationLoader.lanKeys!.open!.tr}重置键?', () { + ShowTipView().showIosTipWithContentDialog( + '确定要${state.resetButtonEnable.value == 1 ? TranslationLoader.lanKeys!.close!.tr : TranslationLoader.lanKeys!.open!.tr}重置键?', + () { logic.sendBurglarAlarm(); }); })), ], ), - ) - ); + )); } @override @@ -144,5 +152,4 @@ class _ResetButtonPageState extends State with RouteAware { state.ifCurrentScreen.value = false; state.sureBtnState.value = 0; } - } From d5853eaacecf1d7eb45f65085fee289e145d5177 Mon Sep 17 00:00:00 2001 From: anfe <448468458@qq.com> Date: Thu, 6 Jun 2024 17:42:03 +0800 Subject: [PATCH 5/5] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E7=BE=A4=E5=8F=91?= =?UTF-8?q?=E6=89=80=E9=92=A5=E5=8C=99=E7=9A=84=E6=B7=BB=E5=8A=A0=E8=A7=A3?= =?UTF-8?q?=E9=94=81=E8=80=85=E9=80=BB=E8=BE=91=EF=BC=8C=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=EF=BC=8C=E6=97=A0=E6=B3=95=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=88=A0=E9=99=A4=EF=BC=8C=E5=88=A0=E9=99=A4=E6=8C=89?= =?UTF-8?q?=E9=92=AE=E7=82=B9=E5=87=BB=E4=B8=8D=E7=81=B5=E6=95=8F=E3=80=82?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E6=89=8B=E6=9C=BA=E5=8F=B7=E6=88=96=E9=82=AE?= =?UTF-8?q?=E7=AE=B1=E6=A0=BC=E5=BC=8F=E8=AF=86=E5=88=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android/app/build.gradle | 16 +- images/lan/lan_en.json | 7 +- images/lan/lan_keys.json | 7 +- images/lan/lan_zh.json | 16 +- .../massSendElectronicKey_page.dart | 1 - .../massSendReceiverCell.dart | 146 ++++++++++++------ .../massSendReceiver_logic.dart | 16 +- .../massSendReceiver_page.dart | 88 +++++++---- .../massSendReceiver_state.dart | 8 +- .../lockMain/xhj/lockMain_xhj_logic.dart | 12 ++ lib/mine/mine/starLockMine_logic.dart | 3 +- lib/mine/mine/starLockMine_page.dart | 2 +- .../lockUserManageList_logic.dart | 13 +- .../lockUserManageList_page.dart | 1 - lib/tools/regexp_tool.dart | 18 +++ 15 files changed, 239 insertions(+), 115 deletions(-) create mode 100644 lib/tools/regexp_tool.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index e71f2d1c..d7c56a09 100755 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -52,14 +52,14 @@ android { // 这里“debug”不是一个自定义变量,而是一个特定的关键词,凡是使用--debug模式,都会引用到这里 // 目前看来,debug模式没办法在buildTypes里面按flavors指定编译签名,所有口味的debug模式只能用同一个签名 debug { - // storeFile file("starlock.keystore") - // storePassword '123456' - // keyAlias = 'starlock' - // keyPassword '123456' - storeFile file("xhj.jks") - storePassword 'xhj8872' - keyAlias = 'upload' - keyPassword 'xhj8872' + storeFile file("starlock.keystore") + storePassword '123456' + keyAlias = 'starlock' + keyPassword '123456' +// storeFile file("xhj.jks") +// storePassword 'xhj8872' +// keyAlias = 'upload' +// keyPassword 'xhj8872' } sky { // CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown diff --git a/images/lan/lan_en.json b/images/lan/lan_en.json index 101e886b..521e460e 100755 --- a/images/lan/lan_en.json +++ b/images/lan/lan_en.json @@ -868,6 +868,9 @@ "自定义邮件模版":"Custom email template", "名称":"Name", "星星锁": "Star lock", - "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "To receive important updates, please click 'OK' and enable notifications in the settings." - + "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "To receive important updates, please click 'OK' and enable notifications in the settings.", + "已有": "Already has", + "新增": "New", + "账号格式错误": "The account format is incorrect", + "接收者信息为空": "The recipient information is empty" } diff --git a/images/lan/lan_keys.json b/images/lan/lan_keys.json index c8130c70..dab00332 100755 --- a/images/lan/lan_keys.json +++ b/images/lan/lan_keys.json @@ -900,6 +900,9 @@ "自定义邮件模版":"自定义邮件模版", "名称":"名称", "星星锁": "星星锁", - "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。" - + "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。", + "已有": "已有", + "新增": "新增", + "账号格式错误": "账号格式错误", + "接收者信息为空": "接收者信息为空" } diff --git a/images/lan/lan_zh.json b/images/lan/lan_zh.json index 193c6d36..ac9966e6 100755 --- a/images/lan/lan_zh.json +++ b/images/lan/lan_zh.json @@ -862,11 +862,15 @@ "五": "五", "六": "六", "日": "日", - "新建短信模版":"新建短信模版", - "新建邮件模版":"新建邮件模版", - "自定义短信模版":"自定义短信模版", - "自定义邮件模版":"自定义邮件模版", - "名称":"名称", + "新建短信模版": "新建短信模版", + "新建邮件模版": "新建邮件模版", + "自定义短信模版": "自定义短信模版", + "自定义邮件模版": "自定义邮件模版", + "名称": "名称", "星星锁": "星星锁", - "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。" + "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。": "为了让您及时收到重要通知和更新,我们需要获取通知权限。请点击“确定”按钮,然后在设置页面中启用通知权限。", + "已有": "已有", + "新增": "新增", + "账号格式错误": "账号格式错误", + "接收者信息为空": "接收者信息为空" } diff --git a/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendElectronicKey/massSendElectronicKey_page.dart b/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendElectronicKey/massSendElectronicKey_page.dart index 12ecdf09..66ca8f01 100755 --- a/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendElectronicKey/massSendElectronicKey_page.dart +++ b/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendElectronicKey/massSendElectronicKey_page.dart @@ -170,7 +170,6 @@ class _MassSendElectronicKeyPageState extends State { if (value != null) { value as Map; state.receiverList = value['lockUserList']; - setState(() {}); } }); diff --git a/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiverCell.dart b/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiverCell.dart index e59c8a9a..3048b287 100755 --- a/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiverCell.dart +++ b/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiverCell.dart @@ -3,6 +3,7 @@ import 'package:flutter_native_contact_picker/flutter_native_contact_picker.dart import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/lockUserList/lockUserList_entity.dart'; +import 'package:star_lock/tools/regexp_tool.dart'; import 'package:star_lock/translations/trans_lib.dart'; import '../../../../../../app_settings/app_colors.dart'; @@ -13,6 +14,7 @@ class MassSendReceiverCell extends StatefulWidget { required this.onDeleteUser, Key? key, }) : super(key: key); + final int currentIndex; final LockUserItemData userData; final VoidCallback onDeleteUser; @@ -25,6 +27,7 @@ class _MassSendReceiverCellState extends State { final FlutterContactPicker contactPicker = FlutterContactPicker(); late TextEditingController _receiverController; late TextEditingController _nickNameController; + RxString errorTxt = ''.obs; @override void initState() { @@ -50,50 +53,95 @@ class _MassSendReceiverCellState extends State { @override Widget build(BuildContext context) { - return Container( - color: Colors.white, - child: Row( - children: [ - GestureDetector( - onTap: widget.onDeleteUser, - child: Padding( - padding: EdgeInsets.symmetric(horizontal: 20.w), - child: Image.asset( - 'images/icon_massSend_delete.png', - width: 26.w, - height: 26.w, + return Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + color: Colors.white, + child: Row( + children: [ + GestureDetector( + onTap: widget.onDeleteUser, + child: Container( + color: Colors.transparent, + padding: EdgeInsets.all(20.r), + child: Image.asset( + 'images/icon_massSend_delete.png', + width: 26.w, + height: 26.w, + ), + ), ), - ), + Expanded( + child: Column( + children: [ + _buildCellWidget( + leftTitle: TranslationLoader.lanKeys!.receiver!.tr, + isInputField: true, + inputHint: TranslationLoader + .lanKeys!.pleaseEnterNumberOrEmail!.tr, + controller: _receiverController, + isContactPickerEnabled: true, + onSubmitted: (String text) { + final bool isEmail = RegexpTool.isEmail(text); + final bool isPhoneNumber = + RegexpTool.isPhoneNumber(text); + if (text.trim() == '' || isEmail || isPhoneNumber) { + errorTxt.value = ''; + } else { + errorTxt.value = '账号格式错误'.tr; + } + }), + Divider( + color: AppColors.greyLineColor, + indent: 20.w, + endIndent: 20.w, + height: 1, + ), + _buildCellWidget( + leftTitle: TranslationLoader.lanKeys!.name!.tr, + isInputField: true, + inputHint: TranslationLoader.lanKeys!.enterYourName!.tr, + controller: _nickNameController, + isContactPickerEnabled: false, + onSubmitted: (String text) { + final bool isEmail = RegexpTool.isEmail(text); + final bool isPhoneNumber = + RegexpTool.isPhoneNumber(text); + if (text.trim() == '' || isEmail || isPhoneNumber) { + errorTxt.value = ''; + } else { + errorTxt.value = '账号格式错误'.tr; + } + }), + ], + ), + ), + ], ), - Expanded( - child: Column( - children: [ - _buildCellWidget( - leftTitle: TranslationLoader.lanKeys!.receiver!.tr, - isInputField: true, - inputHint: - TranslationLoader.lanKeys!.pleaseEnterNumberOrEmail!.tr, - controller: _receiverController, - isContactPickerEnabled: true, - ), - Divider( - color: AppColors.greyLineColor, - indent: 20.w, - endIndent: 20.w, - height: 1, - ), - _buildCellWidget( - leftTitle: TranslationLoader.lanKeys!.name!.tr, - isInputField: true, - inputHint: TranslationLoader.lanKeys!.enterYourName!.tr, - controller: _nickNameController, - isContactPickerEnabled: false, - ), - ], - ), - ), - ], - ), + ), + Obx(() { + return errorTxt.value.trim() != '' + ? Padding( + padding: EdgeInsets.only( + left: 80.w, + top: 10.h, + bottom: 10.h, + ), + child: Text( + errorTxt.value, + style: TextStyle( + color: Colors.red, + fontSize: 18.sp, + ), + ), + ) + : SizedBox( + height: 10.w, + ); + }), + ], ); } @@ -103,20 +151,22 @@ class _MassSendReceiverCellState extends State { required String inputHint, required TextEditingController controller, required bool isContactPickerEnabled, + ValueChanged? onSubmitted, }) { return Container( height: 60.h, padding: EdgeInsets.only(right: 20.w), child: Row( - children: [ + children: [ SizedBox(width: 20.w), Text(leftTitle, style: TextStyle(fontSize: 22.sp)), Expanded(child: SizedBox(width: 10.w)), Row( mainAxisAlignment: MainAxisAlignment.end, - children: [ + children: [ if (isInputField) - _buildTextField(controller, inputHint, isContactPickerEnabled) + _buildTextField(controller, inputHint, isContactPickerEnabled, + onSubmitted: onSubmitted) else Text( controller.text, @@ -132,11 +182,12 @@ class _MassSendReceiverCellState extends State { } Widget _buildTextField(TextEditingController controller, String hintText, - bool isContactPickerEnabled) { + bool isContactPickerEnabled, + {ValueChanged? onSubmitted}) { return SizedBox( width: 380.w, child: Row( - children: [ + children: [ Expanded( child: TextField( controller: controller, @@ -148,6 +199,7 @@ class _MassSendReceiverCellState extends State { hintStyle: TextStyle(fontSize: 22.sp), border: InputBorder.none, ), + onSubmitted: onSubmitted, ), ), if (isContactPickerEnabled) diff --git a/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiver_logic.dart b/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiver_logic.dart index 3de713fa..d727ec46 100755 --- a/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiver_logic.dart +++ b/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiver_logic.dart @@ -1,3 +1,4 @@ +import 'package:get/get.dart'; import 'package:star_lock/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/lockUserList/lockUserList_entity.dart'; import 'package:star_lock/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiver_state.dart'; import 'package:star_lock/tools/baseGetXController.dart'; @@ -6,14 +7,25 @@ import 'package:star_lock/tools/storage.dart'; class MassSendReceiverLogic extends BaseGetXController { MassSendReceiverState state = MassSendReceiverState(); + @override + void onInit() { + super.onInit(); + final dynamic data = Get.arguments; + if (data is Map && data['lockUserList'] is List) { + data['lockUserList'].forEach((dynamic lockUser) { + state.lockUserList.add(lockUser); + }); + } + } + @override Future onReady() async { super.onReady(); - LockUserItemData data = LockUserItemData(); + final LockUserItemData data = LockUserItemData(); state.lockUserList.add(data); - var isVip = await Storage.getBool(saveIsVip); + final bool? isVip = await Storage.getBool(saveIsVip); state.isVip.value = isVip ?? false; state.isVip.refresh(); } diff --git a/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiver_page.dart b/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiver_page.dart index 7a6175f3..546c7215 100755 --- a/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiver_page.dart +++ b/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiver_page.dart @@ -1,13 +1,17 @@ import 'package:flutter/material.dart'; +import 'package:flutter_easyloading/flutter_easyloading.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/appRouters.dart'; import 'package:star_lock/app_settings/app_colors.dart'; +import 'package:star_lock/app_settings/app_settings.dart'; import 'package:star_lock/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/lockUserList/lockUserList_entity.dart'; import 'package:star_lock/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiverCell.dart'; import 'package:star_lock/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiver_logic.dart'; -import 'package:star_lock/tools/showCupertinoAlertView.dart'; +import 'package:star_lock/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiver_state.dart'; import 'package:star_lock/tools/commonItem.dart'; +import 'package:star_lock/tools/regexp_tool.dart'; +import 'package:star_lock/tools/showCupertinoAlertView.dart'; import 'package:star_lock/translations/trans_lib.dart'; class MassSendReceiverPage extends StatefulWidget { @@ -20,8 +24,8 @@ class MassSendReceiverPage extends StatefulWidget { } class _MassSendReceiverPageState extends State { - final logic = Get.put(MassSendReceiverLogic()); - final state = Get.find().state; + final MassSendReceiverLogic logic = Get.put(MassSendReceiverLogic()); + final MassSendReceiverState state = Get.find().state; @override Widget build(BuildContext context) { @@ -40,7 +44,7 @@ class _MassSendReceiverPageState extends State { icon: const Icon(Icons.arrow_back_ios, color: Colors.white), onPressed: () => Navigator.of(context).pop(), ), - actions: [ + actions: [ TextButton( child: Text( TranslationLoader.lanKeys!.save!.tr, @@ -50,24 +54,37 @@ class _MassSendReceiverPageState extends State { if (!state.isVip.value) { return; } - Map resultMap = {}; - resultMap['lockUserList'] = state.lockUserList.value; + if (state.lockUserList.isEmpty) { + EasyLoading.showToast('接收者信息为空'.tr); + return; + } + for (final LockUserItemData userItem in state.lockUserList) { + final bool isEmail = RegexpTool.isEmail(userItem.userid ?? ''); + final bool isPhoneNumber = + RegexpTool.isPhoneNumber(userItem.userid ?? ''); + if (!isEmail && !isPhoneNumber) { + EasyLoading.showToast('账号格式错误'.tr); + return; + } + } + final Map resultMap = {}; + resultMap['lockUserList'] = state.lockUserList; Navigator.pop(context, resultMap); }, ), ], ), body: Column( - children: [ + children: [ Obx(() => Visibility( - visible: state.isVip.value ? false : true, + visible: !state.isVip.value, child: ShowCupertinoAlertView() .topTipsAdvancedFeatures('开通高级功能后才可以选择和添加接收者'.tr))), Obx(() => Visibility( - visible: state.isVip.value ? true : false, + visible: state.isVip.value, child: CommonItem( leftTitel: TranslationLoader.lanKeys!.countryAndRegion!.tr, - rightTitle: "", + rightTitle: '', isHaveLine: true, isHaveRightWidget: true, isHaveDirection: true, @@ -78,7 +95,7 @@ class _MassSendReceiverPageState extends State { fontSize: 22.sp, color: AppColors.darkGrayTextColor), ), action: () async { - var result = await Navigator.pushNamed( + final Object? result = await Navigator.pushNamed( context, Routers.selectCountryRegionPage); if (result != null) { result as Map; @@ -88,24 +105,26 @@ class _MassSendReceiverPageState extends State { } }, ))), - Obx(() => Row( - children: [controlViewTitle(0), controlViewTitle(1)], + Obx(() => Padding( + padding: EdgeInsets.symmetric(vertical: 20.h), + child: Row( + children: [controlViewTitle(0), controlViewTitle(1)], + ), )), SizedBox( height: 2.h, ), Obx(() => Visibility( - visible: state.isVip.value ? true : false, + visible: state.isVip.value, child: Expanded( child: ListView.separated( itemBuilder: (BuildContext context, int index) { - LockUserItemData data = state.lockUserList.value[index]; + final LockUserItemData data = state.lockUserList[index]; state.emailOrPhoneController.text = data.userid ?? ''; state.keyNameController.text = data.nickname ?? ''; - return _itemBuilder(index, data); }, - itemCount: state.lockUserList.value.length, + itemCount: state.lockUserList.length, separatorBuilder: (BuildContext context, int index) { return Divider( height: 20.h, @@ -129,7 +148,7 @@ class _MassSendReceiverPageState extends State { child: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, - children: [ + children: [ Image.asset( state.isVip.value ? 'images/icon_btn_add.png' @@ -141,7 +160,7 @@ class _MassSendReceiverPageState extends State { width: 6.w, ), Text( - btnIndex == 0 ? '已有' : '新增', + btnIndex == 0 ? '已有'.tr : '新增'.tr, style: TextStyle( color: state.isVip.value ? AppColors.mainColor @@ -158,17 +177,27 @@ class _MassSendReceiverPageState extends State { } if (btnIndex == 0) { //已有 - Navigator.pushNamed(context, Routers.lockUserListPage).then((val) { + Navigator.pushNamed(context, Routers.lockUserListPage) + .then((Object? val) { if (val != null) { val as Map; - state.lockUserList.value = val['lockUserList']; - + if (val['lockUserList'] is List) { + final List uid = state.lockUserList + .where((LockUserItemData e) => e.isCheck ?? false) + .map((LockUserItemData e) => e.uid) + .toList(); + val['lockUserList'].forEach((LockUserItemData itemData) { + if (!uid.contains(itemData.uid)) { + state.lockUserList.add(itemData); + } + }); + } setState(() {}); } }); } else if (btnIndex == 1) { //新增 - state.lockUserList.value.add(LockUserItemData()); + state.lockUserList.add(LockUserItemData()); setState(() {}); } }, @@ -177,12 +206,11 @@ class _MassSendReceiverPageState extends State { Widget _itemBuilder(int index, LockUserItemData userData) { return MassSendReceiverCell( - currentIndex: index, - userData: userData, - onDeleteUser: () { - state.lockUserList.removeAt(index - 1); - setState(() {}); - }, - ); + currentIndex: index, + userData: userData, + onDeleteUser: () { + state.lockUserList.removeAt(index); + setState(() {}); + }); } } diff --git a/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiver_state.dart b/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiver_state.dart index a742cbfe..7617a81b 100755 --- a/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiver_state.dart +++ b/lib/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/massSendReceiver/massSendReceiver_state.dart @@ -10,11 +10,11 @@ class MassSendReceiverState { // } // } - var isVip = false.obs; - var lockUserList = [].obs; + RxBool isVip = false.obs; + RxList lockUserList = [].obs; TextEditingController emailOrPhoneController = TextEditingController(); TextEditingController keyNameController = TextEditingController(); - var countryCode = '86'.obs; - var countryName = '中国'.obs; + RxString countryCode = '86'.obs; + RxString countryName = '中国'.obs; } diff --git a/lib/main/lockMian/lockMain/xhj/lockMain_xhj_logic.dart b/lib/main/lockMian/lockMain/xhj/lockMain_xhj_logic.dart index 0e28f379..07326628 100755 --- a/lib/main/lockMian/lockMain/xhj/lockMain_xhj_logic.dart +++ b/lib/main/lockMian/lockMain/xhj/lockMain_xhj_logic.dart @@ -5,7 +5,10 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/main/lockMian/lockMain/lockMain_page.dart'; import 'package:star_lock/main/lockMian/lockMain/xhj/lockMain_xhj_state.dart'; +import 'package:star_lock/mine/minePersonInfo/minePersonInfoPage/minePersonInfo_entity.dart'; +import 'package:star_lock/network/api_repository.dart'; import 'package:star_lock/tools/baseGetXController.dart'; +import 'package:star_lock/tools/storage.dart'; class LockMainXHJLogic extends BaseGetXController { final LockMainXHJState state = LockMainXHJState(); @@ -17,6 +20,14 @@ class LockMainXHJLogic extends BaseGetXController { bool get isMall => state.index ==1; + //用户信息 + Future getUserInfoRequest() async { + final MinePersonInfoEntity entity = await ApiRepository.to.getUserInfo(); + if (entity.errorCode!.codeIsSuccessful) { + Storage.setBool(saveIsVip, entity.data!.isVip==1); + } + } + //打开设备弹窗 void openEquipment() { showModalBottomSheet( @@ -48,6 +59,7 @@ class LockMainXHJLogic extends BaseGetXController { @override void onInit() { super.onInit(); + getUserInfoRequest(); } @override diff --git a/lib/mine/mine/starLockMine_logic.dart b/lib/mine/mine/starLockMine_logic.dart index 106bcf08..c1d1bdf2 100755 --- a/lib/mine/mine/starLockMine_logic.dart +++ b/lib/mine/mine/starLockMine_logic.dart @@ -39,7 +39,7 @@ class StarLockMineLogic extends BaseGetXController { }); } - getMineInfoData() async { + Future getMineInfoData() async { final String? data = await Storage.getString(saveUserLoginData); if (data != null && data.isNotEmpty) { state.userNickName.value = (await Storage.getNickname())!; @@ -59,7 +59,6 @@ class StarLockMineLogic extends BaseGetXController { @override Future onInit() async { super.onInit(); - getMineInfoData(); } diff --git a/lib/mine/mine/starLockMine_page.dart b/lib/mine/mine/starLockMine_page.dart index f13d35d6..55ea2ce8 100755 --- a/lib/mine/mine/starLockMine_page.dart +++ b/lib/mine/mine/starLockMine_page.dart @@ -28,7 +28,7 @@ class StarLockMinePageState extends State with BaseWidget { final StarLockMineState state = Get.find().state; @override - initState() { + void initState() { super.initState(); logic.getUserInfoRequest(); } diff --git a/lib/mine/mineSet/lockUserManage/lockUserManageList/lockUserManageList_logic.dart b/lib/mine/mineSet/lockUserManage/lockUserManageList/lockUserManageList_logic.dart index ba999e85..39f8edf7 100755 --- a/lib/mine/mineSet/lockUserManage/lockUserManageList/lockUserManageList_logic.dart +++ b/lib/mine/mineSet/lockUserManage/lockUserManageList/lockUserManageList_logic.dart @@ -12,10 +12,11 @@ import 'lockUserManageList_state.dart'; class LockUserManageListLogic extends BaseGetXController { final LockUserManageListState state = LockUserManageListState(); + StreamSubscription? _getElectronicKeyListRefreshUIEvent; //请求锁用户列表 Future lockUserListRequest() async { - LockUserListEntity entity = + final LockUserListEntity entity = await ApiRepository.to.lockUserList(pageNo.toString(), pageSize, state.searchController.text); if(entity.errorCode!.codeIsSuccessful){ if (pageNo == 1) { @@ -23,7 +24,7 @@ class LockUserManageListLogic extends BaseGetXController { pageNo++; } else { if (entity.data!.isNotEmpty) { - state.dataList.value.addAll(entity.data!); + state.dataList.addAll(entity.data!); pageNo++; } } @@ -33,7 +34,7 @@ class LockUserManageListLogic extends BaseGetXController { //删除锁用户管理 Future deletelockUserRequest(int uid) async { - var entity = await ApiRepository.to.deletLockUser(uid); + final entity = await ApiRepository.to.deletLockUser(uid); if (entity.errorCode!.codeIsSuccessful) { EasyLoading.showToast('删除成功',duration: 2000.milliseconds); showToast('删除成功', something: (){ @@ -44,7 +45,6 @@ class LockUserManageListLogic extends BaseGetXController { } /// 刷新电子钥匙列表 - StreamSubscription? _getElectronicKeyListRefreshUIEvent; void _getElectronicKeyListRefreshUIAction() { // 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus _getElectronicKeyListRefreshUIEvent = eventBus.on().listen((event) { @@ -55,23 +55,18 @@ class LockUserManageListLogic extends BaseGetXController { @override void onReady() { - // TODO: implement onReady super.onReady(); - _getElectronicKeyListRefreshUIAction(); } @override void onInit() { - // TODO: implement onInit super.onInit(); } @override void onClose() { - // TODO: implement onClose super.onClose(); - _getElectronicKeyListRefreshUIEvent?.cancel(); } } \ No newline at end of file diff --git a/lib/mine/mineSet/lockUserManage/lockUserManageList/lockUserManageList_page.dart b/lib/mine/mineSet/lockUserManage/lockUserManageList/lockUserManageList_page.dart index 101d64b7..6a347f1c 100755 --- a/lib/mine/mineSet/lockUserManage/lockUserManageList/lockUserManageList_page.dart +++ b/lib/mine/mineSet/lockUserManage/lockUserManageList/lockUserManageList_page.dart @@ -38,7 +38,6 @@ class _LockUserManageListPageState extends State { @override void initState() { super.initState(); - getHttpData(); } diff --git a/lib/tools/regexp_tool.dart b/lib/tools/regexp_tool.dart new file mode 100644 index 00000000..0ae87b30 --- /dev/null +++ b/lib/tools/regexp_tool.dart @@ -0,0 +1,18 @@ +/// +/// 正则判断工具 +/// +class RegexpTool { + //判断手机号 + static bool isPhoneNumber(String input) { + // 手机号正则表达式 + final RegExp phoneNumberRegExp = RegExp(r'^1[0-9]{10}$'); + return phoneNumberRegExp.hasMatch(input); + } + + //判断邮箱 + static bool isEmail(String input) { + // 邮箱正则表达式 + final RegExp emailRegExp = RegExp(r'^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$'); + return emailRegExp.hasMatch(input); + } +}