117 lines
3.4 KiB
Dart
117 lines
3.4 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/appRouters.dart';
|
|
import 'package:star_lock/main/lockDetail/passwordKey/passwordKeyList/passwordKeyListEntity.dart';
|
|
import 'package:star_lock/mine/minePersonInfo/minePersonInfoEmail/mineBindPhoneOrEmail_state.dart';
|
|
import 'package:star_lock/network/api_repository.dart';
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
|
|
|
import '../../../tools/eventBusEventManage.dart';
|
|
import '../../../tools/storage.dart';
|
|
|
|
class MineBindPhoneOrEmailLogic extends BaseGetXController {
|
|
final MineBindPhoneOrEmailState state = MineBindPhoneOrEmailState();
|
|
|
|
late Timer _timer;
|
|
void _startTimer() {
|
|
_timer = Timer.periodic(1.seconds, (timer) {
|
|
if (state.currentSecond > 1) {
|
|
state.currentSecond--;
|
|
} else {
|
|
_cancelTimer();
|
|
state.currentSecond = state.totalSeconds;
|
|
}
|
|
state.resetResend();
|
|
});
|
|
}
|
|
|
|
void _cancelTimer() {
|
|
_timer.cancel();
|
|
}
|
|
|
|
//获取验证码请求
|
|
void sendValidationCode() async {
|
|
var entity = await ApiRepository.to.sendValidationCodeAuth(
|
|
countryCode: state.channel.value == '1' ? state.countryCode.value : '',
|
|
account: state.inputAccount.value,
|
|
channel: state.channel.value,
|
|
codeType: state.codeType.value,
|
|
xWidth: state.xWidth.value.toString());
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
_startTimer();
|
|
}
|
|
}
|
|
|
|
//绑定邮箱请求
|
|
Future<void> bindEmailRequest() async {
|
|
PasswordKeyListEntity entity = await ApiRepository.to.bindEmail(
|
|
state.inputAccount.value,
|
|
state.verificationCode.value,
|
|
state.unbindToken.value);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast("邮箱绑定成功".tr, something: () async {
|
|
final loginData = await Storage.getLoginData();
|
|
loginData!.email = state.inputAccount.value;
|
|
Storage.saveLoginData(loginData);
|
|
eventBus.fire(MineInfoChangeRefreshUI());
|
|
Get.until((route) => route.settings.name == Routers.minePersonInfoPage);
|
|
});
|
|
}
|
|
}
|
|
|
|
//绑定手机请求
|
|
Future<void> bindMobileRequest() async {
|
|
PasswordKeyListEntity entity = await ApiRepository.to.bindPhone(
|
|
state.countryCode.value,
|
|
state.inputAccount.value,
|
|
state.verificationCode.value,
|
|
state.unbindToken.value);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast("手机绑定成功".tr, something: () async {
|
|
final loginData = await Storage.getLoginData();
|
|
loginData!.mobile = state.inputAccount.value;
|
|
Storage.saveLoginData(loginData);
|
|
eventBus.fire(MineInfoChangeRefreshUI());
|
|
Get.until((route) => route.settings.name == Routers.minePersonInfoPage);
|
|
});
|
|
}
|
|
}
|
|
|
|
void checkNext(TextEditingController controller) {
|
|
changeInput(controller);
|
|
}
|
|
|
|
void changeInput(TextEditingController controller) {
|
|
if (controller == state.accountController) {
|
|
state.inputAccount.value = controller.text;
|
|
state.accountIsOK.value = state.inputAccount.value.isNotEmpty;
|
|
}
|
|
if (controller == state.codeController) {
|
|
state.verificationCode.value = controller.text;
|
|
}
|
|
|
|
_resetCanSub();
|
|
}
|
|
|
|
void _resetCanSub() {
|
|
state.canSub.value = state.codeIsOK;
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
super.onReady();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
super.onClose();
|
|
}
|
|
}
|