From fd4dab3e2e5d8848e019e23c3f90c062bc21b4e7 Mon Sep 17 00:00:00 2001 From: Daisy <> Date: Fri, 31 May 2024 14:11:16 +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?=E8=AE=BE=E5=A4=87=E4=BF=A1=E6=81=AF=E7=9A=84=E5=85=AC=E7=94=A8?= =?UTF-8?q?=E6=96=B9=E6=B3=95=202=EF=BC=8C=E7=94=A8=E6=88=B7=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=96=B0=E5=A2=9E=E5=85=A5=E5=8F=82=EF=BC=9A=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E4=BF=A1=E6=81=AF=203=EF=BC=8C=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E6=96=B0=E5=A2=9E=E5=85=A5=E5=8F=82=EF=BC=9A?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../XSConstantMacro/XSConstantMacro.dart | 25 +++++++ lib/login/login/starLock_login_logic.dart | 18 ++++- lib/login/login/starLock_login_state.dart | 1 + .../register/starLock_register_logic.dart | 57 ++++++++++----- .../register/starLock_register_page.dart | 73 ++++++++++--------- .../register/starLock_register_state.dart | 1 + .../register/starLock_register_xhj_page.dart | 17 +++-- lib/network/api_provider.dart | 7 +- lib/network/api_repository.dart | 17 +++-- 9 files changed, 142 insertions(+), 74 deletions(-) diff --git a/lib/common/XSConstantMacro/XSConstantMacro.dart b/lib/common/XSConstantMacro/XSConstantMacro.dart index bf692ec0..38485f83 100755 --- a/lib/common/XSConstantMacro/XSConstantMacro.dart +++ b/lib/common/XSConstantMacro/XSConstantMacro.dart @@ -1,3 +1,7 @@ +import 'dart:io'; + +import 'package:device_info_plus/device_info_plus.dart'; + import '../../flavors.dart'; class XSConstantMacro { @@ -85,4 +89,25 @@ class XSConstantMacro { static int webBuyTypeVip = 3; //VIP购买 static int webBuyTypeAuth = 4; //实名购买 static int webBuyTypeShop = 5; //商城购买 + + //设备类型信息 + Future> getDeviceInfoData() async { + final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); + final Map deviceData = {}; + + if (Platform.isAndroid) { + final AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; + deviceData['deviceBrand'] = androidInfo.brand; + deviceData['deviceModel'] = androidInfo.model; + deviceData['deviceVersion'] = androidInfo.version.release; + deviceData['deviceType'] = 10; + } else if (Platform.isIOS) { + final IosDeviceInfo iosInfo = await deviceInfo.iosInfo; + deviceData['deviceBrand'] = iosInfo.name; + deviceData['deviceModel'] = iosInfo.model; + deviceData['deviceVersion'] = iosInfo.systemVersion; + deviceData['deviceType'] = 20; + } + return deviceData; + } } diff --git a/lib/login/login/starLock_login_logic.dart b/lib/login/login/starLock_login_logic.dart index 9826cbce..8651fa1d 100755 --- a/lib/login/login/starLock_login_logic.dart +++ b/lib/login/login/starLock_login_logic.dart @@ -1,10 +1,11 @@ import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:flutter_bugly_plugin/flutter_bugly_plugin.dart'; import 'package:get/get.dart'; import 'package:star_lock/appRouters.dart'; +import 'package:star_lock/app_settings/app_settings.dart'; import 'package:star_lock/blue/blue_manage.dart'; +import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart'; import 'package:star_lock/login/login/entity/LoginEntity.dart'; import 'package:star_lock/mine/mine/starLockMine_state.dart'; import 'package:star_lock/tools/baseGetXController.dart'; @@ -44,7 +45,8 @@ class StarLockLoginLogic extends BaseGetXController { loginType: '1', password: state.pwd.value, countryCode: state.countryCode.value, - username: state.emailOrPhone.value); + username: state.emailOrPhone.value, + deviceInfo: state.deviceInfoMap.value); if (entity.errorCode!.codeIsSuccessful) { Storage.saveLoginData(entity.data); Storage.setBool(saveIsVip, entity.data!.isVip == 0 ? false : true); @@ -86,4 +88,16 @@ class StarLockLoginLogic extends BaseGetXController { state.onClose(); super.onClose(); } + + @override + void onReady() { + super.onReady(); + + XSConstantMacro().getDeviceInfoData().then((Map data) { + state.deviceInfoMap.value = data; + }).catchError((error) { + // 适当处理错误 + AppLog.log('获取设备信息时出错: $error'); + }); + } } diff --git a/lib/login/login/starLock_login_state.dart b/lib/login/login/starLock_login_state.dart index 1aeba9d8..9521398c 100755 --- a/lib/login/login/starLock_login_state.dart +++ b/lib/login/login/starLock_login_state.dart @@ -19,6 +19,7 @@ class StarLockLoginState { FocusNode emailOrPhoneFocusNode = FocusNode(); FocusNode pwdFocusNode = FocusNode(); + RxMap deviceInfoMap = {}.obs; StarLockLoginState() { // emailOrPhone.value = StoreService.to.getLastUserAccount() as String; diff --git a/lib/login/register/starLock_register_logic.dart b/lib/login/register/starLock_register_logic.dart index 39fd7561..ef1bcfd5 100755 --- a/lib/login/register/starLock_register_logic.dart +++ b/lib/login/register/starLock_register_logic.dart @@ -1,8 +1,10 @@ import 'dart:async'; - import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:star_lock/app_settings/app_settings.dart'; +import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart'; +import 'package:star_lock/login/login/entity/LoginEntity.dart'; +import 'package:star_lock/login/register/entity/SendValidationCodeEntity.dart'; import '../../network/api_repository.dart'; import '../../tools/baseGetXController.dart'; @@ -13,7 +15,7 @@ class StarLockRegisterLogic extends BaseGetXController { late Timer _timer; void _startTimer() { - _timer = Timer.periodic(1.seconds, (timer) { + _timer = Timer.periodic(1.seconds, (Timer timer) { if (state.currentSecond > 1) { state.currentSecond--; } else { @@ -29,35 +31,38 @@ class StarLockRegisterLogic extends BaseGetXController { // _timer = null; } - void register() async { - AppLog.log("state.pwd.value:${state.pwd.value} state.surePwd.value:${state.surePwd.value}"); - if(state.pwd.value != state.surePwd.value){ - showToast("密码不一致哦".tr); + Future register() async { + AppLog.log( + 'state.pwd.value:${state.pwd.value} state.surePwd.value:${state.surePwd.value}'); + if (state.pwd.value != state.surePwd.value) { + showToast('密码不一致哦'.tr); return; } - var entity = await ApiRepository.to.register( + final LoginEntity entity = await ApiRepository.to.register( receiverType: state.isIphoneType.value == true ? 1 : 2, countryCode: int.parse(state.countryCode.value), account: state.phoneOrEmailStr.value, password: state.pwd.value, - verificationCode: state.verificationCode.value); + verificationCode: state.verificationCode.value, + deviceInfo: state.deviceInfoMap.value); if (entity.errorCode!.codeIsSuccessful) { - showToast("注册成功".tr); - Get.back(result:{ - "phoneOrEmailStr":state.phoneOrEmailStr.value, - "pwd":state.pwd.value + showToast('注册成功'.tr); + Get.back(result: { + 'phoneOrEmailStr': state.phoneOrEmailStr.value, + 'pwd': state.pwd.value }); } } - void sendValidationCode() async { - var entity = await ApiRepository.to.sendValidationCodeUnLogin( - // state.countryCode.value, - countryCode: state.countryCode.value.toString(), - account: state.phoneOrEmailStr.value, - channel: state.isIphoneType.value ? "1" : "2", - codeType: '1', - xWidth: state.xWidth.value.toString()); + Future sendValidationCode() async { + final SendValidationCodeEntity entity = + await ApiRepository.to.sendValidationCodeUnLogin( + // state.countryCode.value, + countryCode: state.countryCode.value.toString(), + account: state.phoneOrEmailStr.value, + channel: state.isIphoneType.value ? '1' : '2', + codeType: '1', + xWidth: state.xWidth.value.toString()); if (entity.errorCode!.codeIsSuccessful) { _startTimer(); } else {} @@ -93,4 +98,16 @@ class StarLockRegisterLogic extends BaseGetXController { state.codeIsOK && (state.isIphoneType.value ? state.isIphone : state.isEmail); } + + @override + void onReady() { + super.onReady(); + + XSConstantMacro().getDeviceInfoData().then((Map data) { + state.deviceInfoMap.value = data; + }).catchError((error) { + // 适当处理错误 + AppLog.log('获取设备信息时出错: $error'); + }); + } } diff --git a/lib/login/register/starLock_register_page.dart b/lib/login/register/starLock_register_page.dart index ea90d00e..c87d092c 100755 --- a/lib/login/register/starLock_register_page.dart +++ b/lib/login/register/starLock_register_page.dart @@ -3,6 +3,7 @@ import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/app_settings/app_settings.dart'; +import 'package:star_lock/login/register/starLock_register_state.dart'; import '../../appRouters.dart'; import '../../app_settings/app_colors.dart'; @@ -21,8 +22,8 @@ class StarLockRegisterPage extends StatefulWidget { } class _StarLockRegisterPageState extends State { - final logic = Get.put(StarLockRegisterLogic()); - final state = Get.find().state; + final StarLockRegisterLogic logic = Get.put(StarLockRegisterLogic()); + final StarLockRegisterState state = Get.find().state; @override Widget build(BuildContext context) { @@ -35,7 +36,7 @@ class _StarLockRegisterPageState extends State { backgroundColor: AppColors.mainColor), body: ListView( padding: EdgeInsets.only(top: 40.h, left: 40.w, right: 40.w), - children: [ + children: [ topSelectCountryAndRegionWidget(), middleTFWidget(), Obx(() { @@ -67,11 +68,11 @@ class _StarLockRegisterPageState extends State { Widget topSelectCountryAndRegionWidget() { return Column( - children: [ + children: [ SizedBox(height: 50.h), Row( mainAxisAlignment: MainAxisAlignment.center, - children: [ + children: [ Container( width: 340.w, height: 60.h, @@ -81,7 +82,7 @@ class _StarLockRegisterPageState extends State { border: Border.all(width: 1.0, color: AppColors.greyLineColor)), child: Row( - children: [ + children: [ GestureDetector( onTap: () { state.isIphoneType.value = true; @@ -141,19 +142,19 @@ class _StarLockRegisterPageState extends State { SizedBox(height: 60.h), GestureDetector( onTap: () async { - var result = await Get.toNamed(Routers.selectCountryRegionPage); + final result = await Get.toNamed(Routers.selectCountryRegionPage); if (result != null) { result as Map; state.countryCode.value = result['code']; state.countryName.value = result['countryName']; } AppLog.log( - "路由返回值: $result, countryCode:${logic.state.countryCode}"); + '路由返回值: $result, countryCode:${logic.state.countryCode}'); }, child: Obx(() => SizedBox( height: 70.h, child: Row( - children: [ + children: [ SizedBox(width: 5.w), Expanded( child: Text( @@ -163,7 +164,7 @@ class _StarLockRegisterPageState extends State { SizedBox(width: 20.w), Row( mainAxisAlignment: MainAxisAlignment.end, - children: [ + children: [ Text( state.isIphoneType.value ? '${state.countryName.value} +${state.countryCode.value}' @@ -194,7 +195,7 @@ class _StarLockRegisterPageState extends State { Widget middleTFWidget() { return Column( - children: [ + children: [ Obx(() => LoginInput( controller: state.phoneOrEmailController, onchangeAction: (v) { @@ -207,7 +208,7 @@ class _StarLockRegisterPageState extends State { child: Image.asset( state.isIphoneType.value ? 'images/icon_login_account.png' - : "images/icon_login_email.png", + : 'images/icon_login_email.png', width: 30.w, height: 30.w, ), @@ -215,7 +216,7 @@ class _StarLockRegisterPageState extends State { hintText: "${TranslationLoader.lanKeys!.pleaseEnter!.tr}${state.isIphoneType.value ? "手机号".tr : TranslationLoader.lanKeys!.email!.tr}", keyboardType: TextInputType.number, - inputFormatters: [ + inputFormatters: [ // FilteringTextInputFormatter.allow(RegExp('[0-9]')), LengthLimitingTextInputFormatter(30), ])), @@ -236,8 +237,8 @@ class _StarLockRegisterPageState extends State { ), ), hintText: - "${TranslationLoader.lanKeys!.pleaseEnter!.tr}${TranslationLoader.lanKeys!.password!.tr}", - inputFormatters: [ + '${TranslationLoader.lanKeys!.pleaseEnter!.tr}${TranslationLoader.lanKeys!.password!.tr}', + inputFormatters: [ LengthLimitingTextInputFormatter(20), ]), SizedBox(height: 15.w), @@ -263,13 +264,13 @@ class _StarLockRegisterPageState extends State { ), ), hintText: - "${TranslationLoader.lanKeys!.sure!.tr}${TranslationLoader.lanKeys!.password!.tr}", - inputFormatters: [ + '${TranslationLoader.lanKeys!.sure!.tr}${TranslationLoader.lanKeys!.password!.tr}', + inputFormatters: [ LengthLimitingTextInputFormatter(20), ]), SizedBox(height: 10.w), Row( - children: [ + children: [ Expanded( child: LoginInput( controller: state.codeController, @@ -284,8 +285,8 @@ class _StarLockRegisterPageState extends State { ), ), hintText: - "${TranslationLoader.lanKeys!.pleaseEnter!.tr}${TranslationLoader.lanKeys!.verificationCode!.tr}", - inputFormatters: [ + '${TranslationLoader.lanKeys!.pleaseEnter!.tr}${TranslationLoader.lanKeys!.verificationCode!.tr}', + inputFormatters: [ LengthLimitingTextInputFormatter(20), ]), ), @@ -297,14 +298,14 @@ class _StarLockRegisterPageState extends State { state.phoneOrEmailStrIsOK.value && state.canResend.value ? () async { // Navigator.pushNamed(context, Routers.safetyVerificationPage, arguments: {"countryCode":"+86", "account":state.phoneOrEmailStr.value}); - var result = await Navigator.pushNamed( + final Object? result = await Navigator.pushNamed( context, Routers.safetyVerificationPage, - arguments: { - "countryCode": state.countryCode, - "account": state.phoneOrEmailStr.value + arguments: { + 'countryCode': state.countryCode, + 'account': state.phoneOrEmailStr.value }); state.xWidth.value = - (result as Map)['xWidth']; + (result! as Map)['xWidth']; logic.sendValidationCode(); } : null, @@ -337,7 +338,7 @@ class _StarLockRegisterPageState extends State { Widget _buildBottomAgreement() { return Row( mainAxisAlignment: MainAxisAlignment.start, - children: [ + children: [ Obx(() => GestureDetector( onTap: () { state.agree.value = !state.agree.value; @@ -358,7 +359,7 @@ class _StarLockRegisterPageState extends State { text: TextSpan( text: TranslationLoader.lanKeys!.readAndAgree!.tr, style: TextStyle(color: const Color(0xff333333), fontSize: 20.sp), - children: [ + children: [ WidgetSpan( alignment: PlaceholderAlignment.middle, child: GestureDetector( @@ -367,10 +368,11 @@ class _StarLockRegisterPageState extends State { style: TextStyle( color: AppColors.mainColor, fontSize: 20.sp)), onTap: () { - Get.toNamed(Routers.webviewShowPage, arguments: { - "url": XSConstantMacro.userAgreementURL, - "title": '用户协议'.tr - }); + Get.toNamed(Routers.webviewShowPage, + arguments: { + 'url': XSConstantMacro.userAgreementURL, + 'title': '用户协议'.tr + }); }, )), WidgetSpan( @@ -381,10 +383,11 @@ class _StarLockRegisterPageState extends State { style: TextStyle( color: AppColors.mainColor, fontSize: 20.sp)), onTap: () { - Get.toNamed(Routers.webviewShowPage, arguments: { - "url": XSConstantMacro.privacyPolicyURL, - "title": '隐私政策'.tr - }); + Get.toNamed(Routers.webviewShowPage, + arguments: { + 'url': XSConstantMacro.privacyPolicyURL, + 'title': '隐私政策'.tr + }); }, )), ], diff --git a/lib/login/register/starLock_register_state.dart b/lib/login/register/starLock_register_state.dart index 41625bac..2c1d55ad 100755 --- a/lib/login/register/starLock_register_state.dart +++ b/lib/login/register/starLock_register_state.dart @@ -32,6 +32,7 @@ class StarLockRegisterState { var btnText = ''.obs; var totalSeconds = 120; var currentSecond = 120; + RxMap deviceInfoMap = {}.obs; StarLockRegisterState() { resetResend(); diff --git a/lib/login/register/starLock_register_xhj_page.dart b/lib/login/register/starLock_register_xhj_page.dart index 6e8955df..ddace6a7 100755 --- a/lib/login/register/starLock_register_xhj_page.dart +++ b/lib/login/register/starLock_register_xhj_page.dart @@ -193,18 +193,21 @@ class _StarLockRegisterPageState extends State { ), Obx(() => GestureDetector( onTap: - state.phoneOrEmailStrIsOK.value && state.canResend.value ? () async { + state.phoneOrEmailStrIsOK.value && state.canResend.value + ? () async { // Navigator.pushNamed(context, Routers.safetyVerificationPage, arguments: {"countryCode":"+86", "account":state.phoneOrEmailStr.value}); - if(state.pwd.value != state.surePwd.value){ - logic.showToast("密码不一致哦".tr); - return; - } - var result = await Get.toNamed(Routers.safetyVerificationPage, + if (state.pwd.value != state.surePwd.value) { + logic.showToast("密码不一致哦".tr); + return; + } + var result = await Get.toNamed( + Routers.safetyVerificationPage, arguments: { "countryCode": state.countryCode, "account": state.phoneOrEmailStr.value }); - state.xWidth.value = (result as Map)['xWidth']; + state.xWidth.value = + (result as Map)['xWidth']; logic.sendValidationCode(); } : null, diff --git a/lib/network/api_provider.dart b/lib/network/api_provider.dart index 0c290898..0045081a 100755 --- a/lib/network/api_provider.dart +++ b/lib/network/api_provider.dart @@ -22,6 +22,7 @@ class ApiProvider extends BaseProvider { String account, String password, String verificationCode, + Map deviceInfo, ) => post( registerUrl.toUrl, @@ -32,6 +33,7 @@ class ApiProvider extends BaseProvider { 'password': password, 'verificationCode': verificationCode, 'platId': '2', + 'deviceInfo': deviceInfo, })); // post( @@ -65,7 +67,7 @@ class ApiProvider extends BaseProvider { })); Future login(String loginType, String password, String countryCode, - String username) => + String username, Map deviceInfo) => post( loginUrl.toUrl, jsonEncode({ @@ -74,7 +76,8 @@ class ApiProvider extends BaseProvider { 'platId': '2', 'uniqueid': '477E6814-289D-402A-9F49-F89A8BD05D63', 'countryCode': countryCode, - 'username': username + 'username': username, + 'deviceInfo': deviceInfo, })); Future resetPassword( diff --git a/lib/network/api_repository.dart b/lib/network/api_repository.dart index 5c6eef04..3a97c0fd 100755 --- a/lib/network/api_repository.dart +++ b/lib/network/api_repository.dart @@ -98,9 +98,10 @@ class ApiRepository { required int countryCode, required String account, required String password, - required String verificationCode}) async { - final res = await apiProvider.register( - receiverType, countryCode, account, password, verificationCode); + required String verificationCode, + required Map deviceInfo}) async { + final res = await apiProvider.register(receiverType, countryCode, account, + password, verificationCode, deviceInfo); return LoginEntity.fromJson(res.body); } @@ -124,9 +125,10 @@ class ApiRepository { {required String loginType, required String password, required String countryCode, - required String username}) async { - final res = - await apiProvider.login(loginType, password, countryCode, username); + required String username, + required Map deviceInfo}) async { + final res = await apiProvider.login( + loginType, password, countryCode, username, deviceInfo); return LoginEntity.fromJson(res.body); } @@ -2154,8 +2156,7 @@ class ApiRepository { // 电子钥匙获取短信模板 Future getAppInfo() async { - final Response res = - await apiProvider.getAppInfo(); + final Response res = await apiProvider.getAppInfo(); return GetAppInfo.fromJson(res.body); } }