Files
chat-flutter/lib/json/json_auth.dart
2025-09-12 20:35:12 +08:00

55 lines
1.2 KiB
Dart
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'dart:math';
import 'package:demo/tools/tools_regex.dart';
import 'package:get/get.dart';
import 'package:demo/views/login/login_index_view.dart';
// 鉴权接口
class JsonAuth {
// 发送验证码
static Future<String> sendCode(
String phone,
) async {
// 生成一个0到99之间的随机整数包括0和99
int random = Random().nextInt(10000);
return random.toString().padLeft(4, '0');
}
// 密码登录
static Future<AuthModel> loginPass(String phone, String password) async {
return AuthModel.fromJson({'phone': phone});
}
// 验证码登录
static Future<AuthModel> loginCode(String phone, String code) async {
return AuthModel.fromJson({'phone': phone});
}
// 注册账号
static Future<void> register(
String phone,
String code,
) async {}
// 退出登录
static Future<void> logout() async {
// 跳转
Get.offAllNamed(LoginIndexView.routeName);
}
}
class AuthModel {
String token;
String phone;
AuthModel(
this.token,
this.phone,
);
factory AuthModel.fromJson(Map<String, dynamic>? data) {
return AuthModel(
data?['token'] ?? ToolsRegex.token(),
data?['phone'] ?? '',
);
}
}