no message
This commit is contained in:
parent
c4502ae140
commit
7e982a5c2c
|
|
@ -1,6 +1,6 @@
|
|||
import 'package:dio/dio.dart' hide Headers;
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
import 'package:school_asignment_app/common/job/common/base_structure_result.dart';
|
||||
import 'package:school_asignment_app/common/job/user_info_detail.dart';
|
||||
|
||||
part 'retrofit_client.g.dart';
|
||||
|
||||
|
|
@ -10,5 +10,8 @@ abstract class RetrofitClient {
|
|||
factory RetrofitClient(Dio dio, {String? baseUrl}) = _RetrofitClient;
|
||||
|
||||
@POST("/api/rbac/Auth/Login")
|
||||
Future<dynamic> toLogin(@Field() String account, @Field() String password);
|
||||
Future toLogin(@Field() String account, @Field() String password);
|
||||
|
||||
@GET("/api/rbac/User/GetUser")
|
||||
Future<UserInfoDetail> getUser(@Query('userId') String userId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'user_info_detail.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
class UserInfoDetail extends Object {
|
||||
@JsonKey(name: 'account')
|
||||
String account;
|
||||
|
||||
@JsonKey(name: 'name')
|
||||
String name;
|
||||
|
||||
@JsonKey(name: 'gender')
|
||||
int gender;
|
||||
|
||||
@JsonKey(name: 'schoolId')
|
||||
String schoolId;
|
||||
|
||||
@JsonKey(name: 'schoolName')
|
||||
String schoolName;
|
||||
|
||||
@JsonKey(name: 'lastLoginTime')
|
||||
String lastLoginTime;
|
||||
|
||||
@JsonKey(name: 'isActive')
|
||||
bool isActive;
|
||||
|
||||
@JsonKey(name: 'accessFailedCount')
|
||||
int accessFailedCount;
|
||||
|
||||
@JsonKey(name: 'lockoutEndDate')
|
||||
String lockoutEndDate;
|
||||
|
||||
@JsonKey(name: 'creatorName')
|
||||
String creatorName;
|
||||
|
||||
@JsonKey(name: 'creationTime')
|
||||
String creationTime;
|
||||
|
||||
@JsonKey(name: 'id')
|
||||
String id;
|
||||
|
||||
UserInfoDetail(
|
||||
this.account,
|
||||
this.name,
|
||||
this.gender,
|
||||
this.schoolId,
|
||||
this.schoolName,
|
||||
this.lastLoginTime,
|
||||
this.isActive,
|
||||
this.accessFailedCount,
|
||||
this.lockoutEndDate,
|
||||
this.creatorName,
|
||||
this.creationTime,
|
||||
this.id,
|
||||
);
|
||||
|
||||
factory UserInfoDetail.fromJson(Map<String, dynamic> srcJson) => _$UserInfoDetailFromJson(srcJson);
|
||||
|
||||
Map<String, dynamic> toJson() => _$UserInfoDetailToJson(this);
|
||||
}
|
||||
|
|
@ -1,16 +1,13 @@
|
|||
/// 用户 - 配置信息
|
||||
/// 本地存储信息
|
||||
|
||||
// ignore_for_file: constant_identifier_names
|
||||
class AppStorageKey {
|
||||
/// 登录用户的基本信息
|
||||
static const String STORAGE_USER_INFO = 'user_info';
|
||||
enum AppStorageKey {
|
||||
token(value: '', label: "登录用户的token"),
|
||||
xToken(value: '', label: "登录用户的Xtoken,刷新token信息"),
|
||||
userMobile(value: '', label: "用户输入过的手机号码"),
|
||||
userInfo(value: '', label: "登录用户的基本信息 及 token过期时间"),
|
||||
userDetailInfo(value: '', label: "用户的详细信息");
|
||||
|
||||
/// 登录用户的token
|
||||
static const String STORAGE_USER_TOKEN = 'APP:TOKEN';
|
||||
|
||||
/// 登录用户的Xtoken
|
||||
static const String STORAGE_X_TOKEN = 'APP:XTOKEN';
|
||||
|
||||
/// 用户输入过的手机号码
|
||||
static const String STORAGE_USER_MOBILE = 'user_mobile';
|
||||
final String label;
|
||||
final String value;
|
||||
const AppStorageKey({required this.value, required this.label});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,20 @@
|
|||
import 'package:get/get.dart';
|
||||
import 'package:school_asignment_app/common/job/user_info.dart';
|
||||
import 'package:school_asignment_app/common/job/user_info_detail.dart';
|
||||
import 'package:school_asignment_app/common/utils/storage.dart';
|
||||
import 'package:school_asignment_app/common/store/app_storage_key.dart';
|
||||
import 'package:school_asignment_app/routes/app_pages.dart';
|
||||
|
||||
class UserStore extends GetxController {
|
||||
UserStore._privateConstructor() {
|
||||
init();
|
||||
}
|
||||
|
||||
static final UserStore _instance = UserStore._privateConstructor();
|
||||
factory UserStore() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
static UserStore get to => Get.find();
|
||||
|
||||
/// 是否登录
|
||||
|
|
@ -12,15 +22,20 @@ class UserStore extends GetxController {
|
|||
String? token;
|
||||
String? xToken;
|
||||
|
||||
/// 用户信息
|
||||
/// 用户Token及过期时间信息
|
||||
Rx<UserInfo?> userInfo = Rx(null);
|
||||
|
||||
/// 用户详细信息
|
||||
Rx<UserInfoDetail?> userDetailInfo = Rx(null);
|
||||
|
||||
void init() {
|
||||
token = StorageService.to.read(AppStorageKey.STORAGE_USER_TOKEN) ?? '';
|
||||
token = StorageService.to.read(AppStorageKey.token.value) ?? '';
|
||||
try {
|
||||
userInfo.value = StorageService.to.read(AppStorageKey.STORAGE_USER_INFO);
|
||||
userInfo.value = StorageService.to.read(AppStorageKey.userInfo.value);
|
||||
userDetailInfo.value = StorageService.to.read(AppStorageKey.userDetailInfo.value);
|
||||
} catch (err) {
|
||||
StorageService.to.remove(AppStorageKey.STORAGE_USER_INFO);
|
||||
StorageService.to.remove(AppStorageKey.userInfo.value);
|
||||
StorageService.to.remove(AppStorageKey.userDetailInfo.value);
|
||||
}
|
||||
if ((token?.isNotEmpty ?? false) && userInfo.value != null) {
|
||||
isLogin.value = true;
|
||||
|
|
@ -33,17 +48,24 @@ class UserStore extends GetxController {
|
|||
/// 保存 token
|
||||
void setToken(String token) {
|
||||
token = token;
|
||||
StorageService.to.write(AppStorageKey.STORAGE_USER_TOKEN, token);
|
||||
StorageService.to.write(AppStorageKey.token.value, token);
|
||||
}
|
||||
|
||||
/// 更新Xtoken的匙
|
||||
void setXToken(String xtoken) {
|
||||
xtoken = xtoken;
|
||||
StorageService.to.write(AppStorageKey.STORAGE_X_TOKEN, xtoken);
|
||||
StorageService.to.write(AppStorageKey.xToken.value, xtoken);
|
||||
}
|
||||
|
||||
/// 保存 token
|
||||
/// 保存 用户信息
|
||||
void setUserInfo(UserInfo info) {
|
||||
userInfo.value = info;
|
||||
StorageService.to.write(AppStorageKey.STORAGE_USER_INFO, info);
|
||||
StorageService.to.write(AppStorageKey.userInfo.value, info);
|
||||
}
|
||||
|
||||
/// 保存 用户信息
|
||||
void setUserDetailInfo(UserInfoDetail info) {
|
||||
userDetailInfo.value = info;
|
||||
StorageService.to.write(AppStorageKey.userDetailInfo.value, info);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ void main() async {
|
|||
/// 初始化本地存储
|
||||
StorageService storageService = StorageService(initCall: () async {
|
||||
/// 初始化UserStore
|
||||
Get.put<UserStore>(UserStore()..init());
|
||||
Get.put<UserStore>(UserStore());
|
||||
|
||||
runApp(const MyApp());
|
||||
});
|
||||
|
|
|
|||
|
|
@ -68,6 +68,13 @@ class LoginLogic extends GetxController with RequestToolMixin {
|
|||
EasyLoading.show(status: 'loading...');
|
||||
try {
|
||||
await getClient().toLogin(userName, userPwd);
|
||||
String? nameidentifier = UserStore().userInfo.value?.nameidentifier;
|
||||
if (nameidentifier == null) {
|
||||
throw Exception('用户信息无效,请重试');
|
||||
}
|
||||
var data = await getClient().getUser(nameidentifier);
|
||||
print(data);
|
||||
|
||||
EasyLoading.dismiss();
|
||||
Get.offAllNamed(Routes.home);
|
||||
// if (resultData.code != 200 || userData?.accessToken == null || userData?.accessToken == '') {
|
||||
|
|
@ -105,7 +112,6 @@ class LoginLogic extends GetxController with RequestToolMixin {
|
|||
// return toMsg(msg ?? '登录失败,请重试');
|
||||
} finally {
|
||||
state.canLogin.value = true;
|
||||
// EasyLoading.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue