增加若干基础页面
This commit is contained in:
@@ -1,20 +1,64 @@
|
||||
import 'dart:io';
|
||||
import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
||||
import 'state.dart';
|
||||
import '../../utils/utils.dart';
|
||||
import '../../api/index.dart';
|
||||
|
||||
class LoginLogic extends GetxController {
|
||||
final LoginState state = LoginState();
|
||||
|
||||
void isExit(context) {
|
||||
if (state.lastPressedAt == null ||
|
||||
DateTime.now().difference(state.lastPressedAt!) >
|
||||
const Duration(seconds: 1)) {
|
||||
//两次点击间隔超过1秒则重新计时
|
||||
state.lastPressedAt = DateTime.now();
|
||||
BotToast.showText(text:"再按一次退出程序");
|
||||
return;
|
||||
void setPhone(String value) => state.phone = value;
|
||||
|
||||
void setSmsCode(String value) => state.code = value;
|
||||
|
||||
// 验证码倒计时
|
||||
void startCountdownTimer() {
|
||||
if (state.countTime > 0) {
|
||||
state.countTime--;
|
||||
update();
|
||||
Future.delayed(const Duration(seconds: 1), startCountdownTimer);
|
||||
} else {
|
||||
state.countTime = 0;
|
||||
update();
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// 获取验证码
|
||||
Future<void> getCode(context) async {
|
||||
if (ToolFn.isBlank(state.phone) || ToolFn.checkMobile(state.phone)) {
|
||||
return ToolFn.tips("请输入正确的手机号");
|
||||
}
|
||||
if (state.countTime == 0) {
|
||||
final res =
|
||||
await Request.post<Map<String, dynamic>>(LoginApi.getCode, data: {
|
||||
"phone": state.phone,
|
||||
});
|
||||
TDToast.showText(res["msg"].toString(), context: context);
|
||||
state.countTime = 60;
|
||||
startCountdownTimer();
|
||||
}
|
||||
}
|
||||
|
||||
// 登录
|
||||
Future<void> loginFn(context) async {
|
||||
if (ToolFn.isBlank(state.phone) || ToolFn.checkMobile(state.phone)) {
|
||||
return ToolFn.tips("请输入正确的手机号");
|
||||
}
|
||||
if (ToolFn.isBlank(state.code)) {
|
||||
return ToolFn.tips("请输入正确的验证码");
|
||||
}
|
||||
FocusScope.of(context).unfocus();
|
||||
final res =
|
||||
await Request.post<Map<String, dynamic>>(LoginApi.phoneLogin, data: {
|
||||
"Phone": state.phone,
|
||||
"Code": state.code,
|
||||
});
|
||||
// 保存token
|
||||
StorageUtil().putString("token", res["data"]["token"]);
|
||||
// 保存用户信息
|
||||
StorageUtil().putJSON("userInfo", res["data"]["data"]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user