From fb403df0927721453423923b5191bc0149596d2b Mon Sep 17 00:00:00 2001 From: Daisy <> Date: Sat, 4 May 2024 15:46:41 +0800 Subject: [PATCH] =?UTF-8?q?1=EF=BC=8C=E6=96=B0=E5=A2=9E=E5=AE=9E=E5=90=8D?= =?UTF-8?q?=E8=AE=A4=E8=AF=81=E5=BC=B9=E5=87=BA=E6=A1=86=E5=8F=8A=E8=B4=AD?= =?UTF-8?q?=E4=B9=B0=202=EF=BC=8C=E6=96=B0=E5=A2=9E=E8=B4=AD=E4=B9=B0?= =?UTF-8?q?=E5=A2=9E=E5=80=BC=E6=9C=8D=E5=8A=A1=E7=9B=B8=E5=85=B3=E7=BD=91?= =?UTF-8?q?=E9=A1=B5=E5=9B=9E=E9=80=80=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- star_lock/images/lan/lan_en.json | 4 +- star_lock/images/lan/lan_keys.json | 4 +- star_lock/images/lan/lan_zh.json | 4 +- star_lock/lib/appRouters.dart | 2 +- .../sendElectronicKey_page.dart | 36 +++++++------ .../advancedFeaturesWeb_logic.dart | 53 ++++++++++++------- .../advancedFeaturesWeb_page.dart | 33 +++++------- .../advancedFeaturesWeb_state.dart | 7 ++- star_lock/lib/tools/showTipView.dart | 41 +++++++++++--- 9 files changed, 117 insertions(+), 67 deletions(-) diff --git a/star_lock/images/lan/lan_en.json b/star_lock/images/lan/lan_en.json index 9852fba1..c188992b 100644 --- a/star_lock/images/lan/lan_en.json +++ b/star_lock/images/lan/lan_en.json @@ -792,5 +792,7 @@ "开通高级功能后才可以对锁进行管理":"You can manage locks only after the advanced function is enabled", "去开通":"Go and Activate", "实名认证":"Real-name authentication", - "当前剩余数量":"Current surplus quantity" + "当前剩余数量":"Current surplus quantity", + "购买":"Buy", + "实名认证为付费功能,请购买后再使用":"Real-name authentication is a paid function, please use it after purchase" } diff --git a/star_lock/images/lan/lan_keys.json b/star_lock/images/lan/lan_keys.json index f966c98a..974b1e07 100644 --- a/star_lock/images/lan/lan_keys.json +++ b/star_lock/images/lan/lan_keys.json @@ -819,5 +819,7 @@ "开通高级功能后才可以对锁进行管理":"开通高级功能后才可以对锁进行管理", "去开通":"去开通", "实名认证":"实名认证", - "当前剩余数量":"当前剩余数量" + "当前剩余数量":"当前剩余数量", + "购买":"购买", + "实名认证为付费功能,请购买后再使用":"实名认证为付费功能,请购买后再使用" } diff --git a/star_lock/images/lan/lan_zh.json b/star_lock/images/lan/lan_zh.json index 172214a8..cad55aca 100644 --- a/star_lock/images/lan/lan_zh.json +++ b/star_lock/images/lan/lan_zh.json @@ -822,5 +822,7 @@ "开通高级功能后才可以对锁进行管理":"开通高级功能后才可以对锁进行管理", "去开通":"去开通", "实名认证":"实名认证", - "当前剩余数量":"当前剩余数量" + "当前剩余数量":"当前剩余数量", + "购买":"购买", + "实名认证为付费功能,请购买后再使用":"实名认证为付费功能,请购买后再使用" } diff --git a/star_lock/lib/appRouters.dart b/star_lock/lib/appRouters.dart index 09da688d..8aad7340 100644 --- a/star_lock/lib/appRouters.dart +++ b/star_lock/lib/appRouters.dart @@ -1071,7 +1071,7 @@ abstract class AppRouters { GetPage(name: Routers.addPalmPage, page: (() => const AddPalmPage())), GetPage( name: Routers.advancedFeaturesWebPage, - page: (() => AdvancedFeaturesWebPage())), + page: (() => const AdvancedFeaturesWebPage())), GetPage( name: Routers.advancedFunctionRecordPage, page: (() => const AdvancedFunctionRecordPage())), diff --git a/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_page.dart b/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_page.dart index fcdd9649..b5f6032f 100644 --- a/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_page.dart +++ b/star_lock/lib/main/lockDetail/electronicKey/sendElectronicKey/sendElectronicKey/sendElectronicKey_page.dart @@ -215,8 +215,8 @@ class _SendElectronicKeyPageState extends State rightTitle: state.timeLimitEndTime.value, isHaveDirection: true, action: () { - PDuration selectDate = - PDuration.parse(DateTime.tryParse(state.timeLimitEndTime.value)); + PDuration selectDate = PDuration.parse( + DateTime.tryParse(state.timeLimitEndTime.value)); Pickers.showDatePicker(context, selectDate: selectDate, mode: DateMode.YMDHM, onConfirm: (p) { state.timeLimitEndTime.value = @@ -233,19 +233,17 @@ class _SendElectronicKeyPageState extends State return Column( children: [ CommonItem( - leftTitel: TranslationLoader.lanKeys!.realNameAuthentication!.tr, - rightTitle: "", - isTipsImg: true, - tipsImgAction: () { - ShowTipView().showSureAlertDialog( - "人脸实名认证指的是用户在使用手机APP开锁时,需要先进行本人人脸验证,验证通过才能开锁。".tr); - }, - isHaveRightWidget: true, - rightWidget: SizedBox( - width: 60.w, height: 50.h, child: _remoteSwitch(false)), - action: () { - // Toast.show(msg: '此功能暂未开放'); - }), + leftTitel: TranslationLoader.lanKeys!.realNameAuthentication!.tr, + rightTitle: "", + isTipsImg: true, + tipsImgAction: () { + ShowTipView().showSureAlertDialog( + "人脸实名认证指的是用户在使用手机APP开锁时,需要先进行本人人脸验证,验证通过才能开锁。".tr); + }, + isHaveRightWidget: true, + rightWidget: + SizedBox(width: 60.w, height: 50.h, child: _remoteSwitch(false)), + ), ], ); } @@ -609,6 +607,14 @@ class _SendElectronicKeyPageState extends State state.isRemoteUnlock.value = !state.isRemoteUnlock.value; } else { state.isAuthentication.value = !state.isAuthentication.value; + if (state.isAuthentication.value) { + ShowTipView().showBuyTipWithContentAlert( + titleStr: '实名认证为付费功能,请购买后再使用'.tr, + sureClick: () { + Get.toNamed(Routers.advancedFeaturesWebPage, + arguments: {'isShop': false}); + }); + } } }, ); diff --git a/star_lock/lib/mine/valueAddedServices/advancedFeaturesWeb/advancedFeaturesWeb_logic.dart b/star_lock/lib/mine/valueAddedServices/advancedFeaturesWeb/advancedFeaturesWeb_logic.dart index 0a23cf62..6480dca7 100644 --- a/star_lock/lib/mine/valueAddedServices/advancedFeaturesWeb/advancedFeaturesWeb_logic.dart +++ b/star_lock/lib/mine/valueAddedServices/advancedFeaturesWeb/advancedFeaturesWeb_logic.dart @@ -1,8 +1,10 @@ import 'dart:convert'; +import 'package:flutter/services.dart'; import 'package:fluwx/fluwx.dart'; import 'package:get/get.dart'; import 'package:star_lock/app_settings/app_settings.dart'; +import 'package:star_lock/flavors.dart'; import 'package:star_lock/mine/valueAddedServices/advancedFeaturesWeb/advancedFeaturesWeb_entity.dart'; import 'package:star_lock/mine/valueAddedServices/advancedFeaturesWeb/advancedFeaturesWeb_state.dart'; import 'package:star_lock/network/api_repository.dart'; @@ -14,11 +16,9 @@ import 'package:webview_flutter/webview_flutter.dart'; class AdvancedFeaturesWebLogic extends BaseGetXController { late AdvancedFeaturesWebState state = AdvancedFeaturesWebState(); - // AdvancedFeaturesWebLogic({required bool allowReturn, required bool isShop}) - // : state = - // AdvancedFeaturesWebState(allowReturn: allowReturn, isShop: isShop); + DateTime? _lastPressedAt; // 记录上一次按下返回键的时间 - //获取商城跳转地址 + //获取购买跳转地址 Future getVipBuyURLRequest() async { AdvancedFeaturesWebEntity entity = await ApiRepository.to.getServicePackageBuyUrl(); @@ -26,7 +26,7 @@ class AdvancedFeaturesWebLogic extends BaseGetXController { state.vipBuyUrl.value = state.isShop.value == true ? entity.data!.shopList! : entity.data!.cloudauthBuyUrl!; - state.mallWebView.setNavigationDelegate( + state.vipBuyWebView.setNavigationDelegate( NavigationDelegate( onProgress: (int progress) { // Update loading bar. @@ -49,15 +49,13 @@ class AdvancedFeaturesWebLogic extends BaseGetXController { }, ), ); - state.mallWebView.loadRequest(Uri.parse(state.vipBuyUrl.value)); - // FlutterBridge.postMessage({action:'',data:'{}',callFun:'回调给js的方法'}) - state.mallWebView.addJavaScriptChannel( + state.vipBuyWebView.loadRequest(Uri.parse(state.vipBuyUrl.value)); + state.vipBuyWebView.addJavaScriptChannel( "FlutterBridge", onMessageReceived: (JavaScriptMessage message) async { flutterBridge(message); }, ); - // onMessageReceived } } @@ -89,7 +87,7 @@ class AdvancedFeaturesWebLogic extends BaseGetXController { 'errCode': response.errCode, 'errStr': response.errStr, }; - state.mallWebView.runJavaScript( + state.vipBuyWebView.runJavaScript( 'window.$callFun(`${json.encode(data)}`)', ); } @@ -98,15 +96,39 @@ class AdvancedFeaturesWebLogic extends BaseGetXController { //判断webview 是否可以有路由可以回退,无则退出当前页面 Future canGoBack(bool didPop) async { - bool canGoBack = await state.mallWebView.canGoBack(); + bool canGoBack = await state.vipBuyWebView.canGoBack(); if (canGoBack) { - await state.mallWebView.goBack(); + await state.vipBuyWebView.goBack(); + } else if (state.allowReturn) { + Get.back(); } else { - if (state.allowReturn) Get.back(); + if (_lastPressedAt == null || + DateTime.now().difference(_lastPressedAt!) > + const Duration(seconds: 2)) { + // 如果两次返回键时间间隔大于 2 秒,则提示再次按下返回键退出 + _lastPressedAt = DateTime.now(); + showToast('再返回一次退出${F.title}'); + return false; + } + SystemNavigator.pop(); + return true; } + refreshGoBack(); return false; } + //刷新当前路由状态 + void refreshGoBack() { + //如果属于一直返回按钮,则根据是否有路由可以回退刷新 + if (state.allowReturn) { + return; + } + state.vipBuyWebView.canGoBack().then((value) { + state.canGoBack = value; + update(); + }); + } + @override Future onReady() async { super.onReady(); @@ -117,9 +139,4 @@ class AdvancedFeaturesWebLogic extends BaseGetXController { super.onInit(); getVipBuyURLRequest(); } - - @override - void onClose() { - super.onClose(); - } } diff --git a/star_lock/lib/mine/valueAddedServices/advancedFeaturesWeb/advancedFeaturesWeb_page.dart b/star_lock/lib/mine/valueAddedServices/advancedFeaturesWeb/advancedFeaturesWeb_page.dart index 1fd4b034..c56adebc 100644 --- a/star_lock/lib/mine/valueAddedServices/advancedFeaturesWeb/advancedFeaturesWeb_page.dart +++ b/star_lock/lib/mine/valueAddedServices/advancedFeaturesWeb/advancedFeaturesWeb_page.dart @@ -7,15 +7,7 @@ import 'package:star_lock/tools/titleAppBar.dart'; import 'package:webview_flutter/webview_flutter.dart'; class AdvancedFeaturesWebPage extends StatefulWidget { - AdvancedFeaturesWebPage( - {Key? key, - this.showAppBar = true, - this.allowReturn = true, - this.isShop = true}) - : super(key: key); - bool showAppBar; - bool allowReturn; - bool isShop; + const AdvancedFeaturesWebPage({Key? key}) : super(key: key); @override State createState() => @@ -39,17 +31,20 @@ class _AdvancedFeaturesWebPageState extends State { child: Scaffold( resizeToAvoidBottomInset: false, backgroundColor: const Color(0xFFFFFFFF), - appBar: widget.showAppBar - ? TitleAppBar( - barTitle: logic.state.isShop.value == true - ? '高级功能'.tr - : '实名认证'.tr, - haveBack: true, - backgroundColor: AppColors.mainColor, - ) - : null, + appBar: TitleAppBar( + barTitle: + logic.state.isShop.value == true ? '高级功能'.tr : '实名认证'.tr, + haveBack: true, + backgroundColor: AppColors.mainColor, + backAction: () => logic.canGoBack(false), + ), body: Obx(() => Column( children: [ + PopScope( + onPopInvoked: logic.canGoBack, + canPop: false, + child: const SizedBox(), + ), Container( padding: EdgeInsets.only(bottom: 10.w), child: LinearProgressIndicator( @@ -61,7 +56,7 @@ class _AdvancedFeaturesWebPageState extends State { ), Expanded( child: WebViewWidget( - controller: logic.state.mallWebView), + controller: logic.state.vipBuyWebView), ), ], ))), diff --git a/star_lock/lib/mine/valueAddedServices/advancedFeaturesWeb/advancedFeaturesWeb_state.dart b/star_lock/lib/mine/valueAddedServices/advancedFeaturesWeb/advancedFeaturesWeb_state.dart index f1e55368..75c9b027 100644 --- a/star_lock/lib/mine/valueAddedServices/advancedFeaturesWeb/advancedFeaturesWeb_state.dart +++ b/star_lock/lib/mine/valueAddedServices/advancedFeaturesWeb/advancedFeaturesWeb_state.dart @@ -4,13 +4,12 @@ import 'package:star_lock/webview/webview_logic.dart'; import 'package:webview_flutter/webview_flutter.dart'; class AdvancedFeaturesWebState { - // AdvancedFeaturesWebState({required this.allowReturn, required this.isShop}); - - var vipBuyUrl = "".obs; + var vipBuyUrl = "".obs; //购买跳转地址 var webProgress = 0.0.obs; bool allowReturn = true; - late WebViewController mallWebView = initWebViewController(); + late WebViewController vipBuyWebView = initWebViewController(); var isShop = true.obs; //是否为高级功能购买页面 + bool canGoBack = false; //初始化webView控制器 WebViewController initWebViewController() { diff --git a/star_lock/lib/tools/showTipView.dart b/star_lock/lib/tools/showTipView.dart index f38ba524..935f1804 100644 --- a/star_lock/lib/tools/showTipView.dart +++ b/star_lock/lib/tools/showTipView.dart @@ -1,4 +1,3 @@ - import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_easyloading/flutter_easyloading.dart'; @@ -11,7 +10,6 @@ import 'showDeleteAdministratorIsHaveAllDataWidget.dart'; typedef BlockIsHaveAllDataCallback = void Function(bool isAllData); class ShowTipView { - // 只有一个确定按钮 void showSureAlertDialog(String contentStr) { showCupertinoDialog( @@ -33,7 +31,8 @@ class ShowTipView { } // 授权管理员调用是否删除数据 - void showDeleteAdministratorIsHaveAllDataDialog(String contentStr, BlockIsHaveAllDataCallback blockIsHaveAllDataCallback) { + void showDeleteAdministratorIsHaveAllDataDialog(String contentStr, + BlockIsHaveAllDataCallback blockIsHaveAllDataCallback) { bool selet = false; showDialog( context: Get.context!, @@ -44,7 +43,7 @@ class ShowTipView { // height: 100.h, child: ShowDeleteAdministratorIsHaveAllDataWidget( contentStr: contentStr, - blockIsHaveAllDataCallback: (a){ + blockIsHaveAllDataCallback: (a) { selet = a; }, ), @@ -96,14 +95,15 @@ class ShowTipView { ); } - void showTFViewAlertDialog(TextEditingController controller, String title, String tipTitle, Function sureClick) { + void showTFViewAlertDialog(TextEditingController controller, String title, + String tipTitle, Function sureClick) { // 点击删除 开始扫描 showDialog( context: Get.context!, builder: (BuildContext context) { return ShowTFView( title: title, - tipTitle: tipTitle??"", + tipTitle: tipTitle ?? "", controller: controller, sureClick: () { //发送删除锁请求 @@ -122,4 +122,31 @@ class ShowTipView { ); } -} \ No newline at end of file + // 购买按钮 + void showBuyTipWithContentAlert( + {required String titleStr, required Function sureClick}) { + showCupertinoDialog( + context: Get.context!, + builder: (context) { + return CupertinoAlertDialog( + title: Text(titleStr), + actions: [ + CupertinoDialogAction( + child: Text(TranslationLoader.lanKeys!.cancel!.tr), + onPressed: () { + Get.back(); + }, + ), + CupertinoDialogAction( + child: Text('购买'.tr), + onPressed: () { + Get.back(); + sureClick(); + }, + ), + ], + ); + }, + ); + } +}