116 lines
3.8 KiB
Dart
Executable File
116 lines
3.8 KiB
Dart
Executable File
import 'dart:io';
|
|
|
|
import 'package:flutter/material.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';
|
|
import 'package:star_lock/tools/xs_jPhush.dart';
|
|
|
|
import '../../mine/mine/starLockMine_logic.dart';
|
|
import '../../network/api_repository.dart';
|
|
import '../../tools/eventBusEventManage.dart';
|
|
import '../../tools/showTipView.dart';
|
|
import '../../tools/storage.dart';
|
|
import '../register/entity/checkIP_entity.dart';
|
|
import 'starLock_login_state.dart';
|
|
|
|
class StarLockLoginLogic extends BaseGetXController {
|
|
final StarLockLoginState state = StarLockLoginState();
|
|
final StarLockMineState stateMyLogic = Get.put(StarLockMineLogic()).state;
|
|
int indexFocusNode = noneFocusNode;
|
|
static int noneFocusNode = 0;
|
|
static int emailOrPhoneFocusNode = 1;
|
|
static int pwdFocusNode = 2;
|
|
|
|
//检查焦点状态
|
|
void changeInputFocusNode() {
|
|
Future<void>.delayed(const Duration(milliseconds: 100), () {
|
|
if (indexFocusNode == noneFocusNode) {
|
|
return;
|
|
}
|
|
if (indexFocusNode == emailOrPhoneFocusNode) {
|
|
state.emailOrPhoneFocusNode.requestFocus();
|
|
} else if (indexFocusNode == pwdFocusNode) {
|
|
state.pwdFocusNode.requestFocus();
|
|
}
|
|
});
|
|
}
|
|
|
|
Future<void> login() async {
|
|
FocusScope.of(Get.context!).requestFocus(FocusNode()); //关闭键盘
|
|
final LoginEntity entity = await ApiRepository.to.login(
|
|
loginType: '1',
|
|
password: state.pwd.value,
|
|
countryCode: state.countryCode.value,
|
|
username: state.emailOrPhone.value,
|
|
deviceInfo: state.deviceInfoMap.value);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
Storage.saveLoginData(entity.data);
|
|
Storage.setBool(saveIsVip, entity.data!.isVip == 1);
|
|
eventBus.fire(MineInfoChangeRefreshUI());
|
|
XSJPushProvider().bindDeviceID();
|
|
XSJPushProvider().initLocalNotification(isCancelLocalPush: false);
|
|
Get.offNamedUntil(Routers.starLockMain, (Route route) => false);
|
|
BlueManage().scanDevices.clear(); //清除设备缓存
|
|
}
|
|
}
|
|
|
|
Future<void> checkIpAction() async {
|
|
final CheckIPEntity entity = await ApiRepository.to.checkIpAction(
|
|
ip: ''
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
if(state.countryName.value == entity.data!.name){
|
|
ShowTipView().showSureAlertDialog('国家地区的选择将影响数据安全,你当前选择的是阿尔巴尼亚,请确认后再继续'.tr, tipTitle: '确认国家或地区'.tr, sureStr: '我知道了'.tr);
|
|
}
|
|
}
|
|
}
|
|
|
|
void changeAgreeState() {
|
|
_resetCanNext();
|
|
}
|
|
|
|
void exchangeFistShow() =>
|
|
state.passwordShow.value = !state.passwordShow.value;
|
|
|
|
void checkNext(TextEditingController controller) {
|
|
changeInput(controller);
|
|
}
|
|
|
|
void changeInput(TextEditingController controller) {
|
|
if (controller == state.emailOrPhoneController) {
|
|
state.emailOrPhone.value = controller.text;
|
|
}
|
|
if (controller == state.pwdController) {
|
|
state.pwd.value = controller.text;
|
|
}
|
|
_resetCanNext();
|
|
}
|
|
|
|
void _resetCanNext() {
|
|
state.canNext.value = state.pwdIsOK && state.isEmailOrPhone;
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
state.onClose();
|
|
super.onClose();
|
|
}
|
|
|
|
//刷新设备信息
|
|
void flushedDeviceInfo(){
|
|
XSConstantMacro().getDeviceInfoData().then((Map<String, dynamic> data) {
|
|
state.deviceInfoMap.value = data;
|
|
}).catchError((dynamic error) {
|
|
// 适当处理错误
|
|
AppLog.log('获取设备信息时出错: $error');
|
|
});
|
|
}
|
|
|
|
}
|