89 lines
2.8 KiB
Dart
Executable File
89 lines
2.8 KiB
Dart
Executable File
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/blue/blue_manage.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/storage.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 {
|
|
final LoginEntity entity = await ApiRepository.to.login(
|
|
loginType: '1',
|
|
password: state.pwd.value,
|
|
countryCode: state.countryCode.value,
|
|
username: state.emailOrPhone.value);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
Storage.saveLoginData(entity.data);
|
|
Storage.setBool(saveIsVip, entity.data!.isVip == 0 ? false : true);
|
|
eventBus.fire(MineInfoChangeRefreshUI());
|
|
XSJPushProvider().initJPushService();
|
|
XSJPushProvider().initLocalNotification(false);
|
|
Get.offNamedUntil(Routers.starLockMain, (Route route) => false);
|
|
BlueManage().scanDevices.clear(); //清除设备缓存
|
|
}
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|