app-starlock/lib/login/register/starLock_register_logic.dart
Daisy fd4dab3e2e 1,新增获取设备信息的公用方法
2,用户登录新增入参:设备信息
3,注册接口新增入参:设备信息
2024-05-31 14:11:16 +08:00

114 lines
3.5 KiB
Dart
Executable File

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';
import 'starLock_register_state.dart';
class StarLockRegisterLogic extends BaseGetXController {
final StarLockRegisterState state = StarLockRegisterState();
late Timer _timer;
void _startTimer() {
_timer = Timer.periodic(1.seconds, (Timer timer) {
if (state.currentSecond > 1) {
state.currentSecond--;
} else {
_cancelTimer();
state.currentSecond = state.totalSeconds;
}
state.resetResend();
});
}
void _cancelTimer() {
_timer.cancel();
// _timer = null;
}
Future<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);
return;
}
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,
deviceInfo: state.deviceInfoMap.value);
if (entity.errorCode!.codeIsSuccessful) {
showToast('注册成功'.tr);
Get.back(result: <String, String>{
'phoneOrEmailStr': state.phoneOrEmailStr.value,
'pwd': state.pwd.value
});
}
}
Future<void> 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 {}
}
void changeAgreeState() {
_resetCanSub();
}
void checkNext(TextEditingController controller) {
changeInput(controller);
}
void changeInput(TextEditingController controller) {
if (controller == state.phoneOrEmailController) {
state.phoneOrEmailStr.value = controller.text;
state.phoneOrEmailStrIsOK.value = state.phoneOrEmailStr.value.isNotEmpty;
}
if (controller == state.pwdController) {
state.pwd.value = controller.text;
}
if (controller == state.sureController) {
state.surePwd.value = controller.text;
}
if (controller == state.codeController) {
state.verificationCode.value = controller.text;
}
_resetCanSub();
}
void _resetCanSub() {
state.canSub.value = state.pwdIsOK &&
state.codeIsOK &&
(state.isIphoneType.value ? state.isIphone : state.isEmail);
}
@override
void onReady() {
super.onReady();
XSConstantMacro().getDeviceInfoData().then((Map<String, dynamic> data) {
state.deviceInfoMap.value = data;
}).catchError((error) {
// 适当处理错误
AppLog.log('获取设备信息时出错: $error');
});
}
}