Compare commits
No commits in common. "5a18eb5f7a079f06f8a9dec3fc3174584e144072" and "f9ef3ec77663de2f93db06bb59c2fec1a72a813d" have entirely different histories.
5a18eb5f7a
...
f9ef3ec776
|
|
@ -16,7 +16,7 @@ abstract class RetrofitClient {
|
|||
Future toLogin(@Field() String account, @Field() String password);
|
||||
|
||||
@GET("/api/rbac/User/GetUser")
|
||||
Future<UserInfoDetail?> getUser(@Query('userId') String userId);
|
||||
Future<UserInfoDetail> getUser(@Query('userId') String userId);
|
||||
|
||||
@GET("/api/hms/Homework/GetList")
|
||||
Future<WorkStudent> getWorkList(@Queries() WorkStudentParams params);
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ class AuthInterceptor extends Interceptor {
|
|||
|
||||
if (null != token && token.isNotEmpty) {
|
||||
headers["Authorization"] = token; //添加自己项目中的请求头 进行保存
|
||||
headers["x-Authorization"] = token; //添加自己项目中的请求头 进行保存
|
||||
}
|
||||
|
||||
if ((userInfo?.isExpired() ?? false) && (xToken?.isNotEmpty ?? false)) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/// 本地存储信息
|
||||
|
||||
enum AppStorageKey {
|
||||
token(value: 'TOKEN', label: "登录用户的token"),
|
||||
xToken(value: 'XTOKEN', label: "登录用户的Xtoken,刷新token信息"),
|
||||
userMobile(value: 'USERMOBILE', label: "用户输入过的手机号码"),
|
||||
userInfo(value: 'USERINFO', label: "登录用户的基本信息 及 token过期时间"),
|
||||
userDetailInfo(value: 'USERDETAILINFO', label: "用户的详细信息");
|
||||
token(value: '', label: "登录用户的token"),
|
||||
xToken(value: '', label: "登录用户的Xtoken,刷新token信息"),
|
||||
userMobile(value: '', label: "用户输入过的手机号码"),
|
||||
userInfo(value: '', label: "登录用户的基本信息 及 token过期时间"),
|
||||
userDetailInfo(value: '', label: "用户的详细信息");
|
||||
|
||||
final String label;
|
||||
final String value;
|
||||
|
|
|
|||
|
|
@ -8,9 +8,19 @@ import 'package:school_asignment_app/common/store/app_storage_key.dart';
|
|||
import 'package:school_asignment_app/routes/app_pages.dart';
|
||||
|
||||
class UserStore extends GetxController with RequestToolMixin{
|
||||
UserStore._privateConstructor() {
|
||||
init();
|
||||
}
|
||||
|
||||
static final UserStore _instance = UserStore._privateConstructor();
|
||||
factory UserStore() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
static UserStore get to => Get.find();
|
||||
|
||||
/// 是否登录
|
||||
final isLogin = false.obs;
|
||||
String? token;
|
||||
String? xToken;
|
||||
|
||||
|
|
@ -20,11 +30,10 @@ class UserStore extends GetxController with RequestToolMixin{
|
|||
/// 用户详细信息
|
||||
Rx<UserInfoDetail?> userDetailInfo = Rx(null);
|
||||
|
||||
RxList<EnumSubject> subjectList = RxList();
|
||||
RxList<EnumSubject> subjectList = RxList();
|
||||
|
||||
UserStore init() {
|
||||
token = StorageService.to.read(AppStorageKey.token.value);
|
||||
xToken = StorageService.to.read(AppStorageKey.xToken.value);
|
||||
void init() {
|
||||
token = StorageService.to.read(AppStorageKey.token.value) ?? '';
|
||||
try {
|
||||
userInfo.value = StorageService.to.read(AppStorageKey.userInfo.value);
|
||||
userDetailInfo.value = StorageService.to.read(AppStorageKey.userDetailInfo.value);
|
||||
|
|
@ -33,21 +42,22 @@ class UserStore extends GetxController with RequestToolMixin{
|
|||
StorageService.to.remove(AppStorageKey.userDetailInfo.value);
|
||||
}
|
||||
if ((token?.isNotEmpty ?? false) && userInfo.value != null) {
|
||||
isLogin.value = true;
|
||||
} else {
|
||||
isLogin.value = false;
|
||||
Get.toNamed(Routes.login);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/// 保存 token
|
||||
void setToken(String token) {
|
||||
this.token = token;
|
||||
token = token;
|
||||
StorageService.to.write(AppStorageKey.token.value, token);
|
||||
}
|
||||
|
||||
/// 更新Xtoken的匙
|
||||
void setXToken(String xtoken) {
|
||||
xToken = xtoken;
|
||||
xtoken = xtoken;
|
||||
StorageService.to.write(AppStorageKey.xToken.value, xtoken);
|
||||
}
|
||||
|
||||
|
|
@ -63,14 +73,7 @@ class UserStore extends GetxController with RequestToolMixin{
|
|||
StorageService.to.write(AppStorageKey.userDetailInfo.value, info);
|
||||
}
|
||||
|
||||
void erase() {
|
||||
userInfo.value = null;
|
||||
userDetailInfo.value = null;
|
||||
token = null;
|
||||
xToken = null;
|
||||
}
|
||||
|
||||
//获取科目
|
||||
//获取科目
|
||||
getSubjectList() async {
|
||||
var res = await getClient().getEnumSubjectList('EnumSubject');
|
||||
subjectList.value = res['EnumSubject']!;
|
||||
|
|
|
|||
|
|
@ -2,14 +2,23 @@ import 'package:get/get.dart';
|
|||
import 'package:get_storage/get_storage.dart';
|
||||
|
||||
class StorageService extends GetxService {
|
||||
StorageService._();
|
||||
static final StorageService _instance = StorageService._();
|
||||
factory StorageService({Future Function()? initCall}) {
|
||||
// 具体初始化代码.
|
||||
_instance._init().then((value) {
|
||||
if (initCall != null) initCall();
|
||||
});
|
||||
return _instance;
|
||||
}
|
||||
|
||||
static StorageService get to => Get.find();
|
||||
late final GetStorage _getStorage;
|
||||
get storage => _getStorage;
|
||||
|
||||
Future<StorageService> init() async {
|
||||
Future<void> _init() async {
|
||||
await GetStorage.init();
|
||||
_getStorage = GetStorage();
|
||||
return this;
|
||||
}
|
||||
|
||||
T? read<T>(String key) {
|
||||
|
|
@ -27,8 +36,4 @@ class StorageService extends GetxService {
|
|||
bool hasData(String key) {
|
||||
return _getStorage.hasData(key);
|
||||
}
|
||||
|
||||
Future erase() async {
|
||||
await _getStorage.erase();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,14 +15,15 @@ void main() async {
|
|||
Get.testMode = true;
|
||||
|
||||
/// 初始化本地存储
|
||||
await Get.putAsync(() => StorageService().init());
|
||||
|
||||
/// 初始化UserStore
|
||||
Get.put<UserStore>(UserStore().init());
|
||||
StorageService storageService = StorageService(initCall: () async {
|
||||
/// 初始化UserStore
|
||||
Get.put<UserStore>(UserStore());
|
||||
|
||||
runApp(const MyApp());
|
||||
});
|
||||
Get.put(storageService);
|
||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.top, SystemUiOverlay.bottom]); // 屏幕刘海
|
||||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); // 屏幕强制竖屏
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import 'package:school_asignment_app/common/job/user_info.dart';
|
|||
import 'package:school_asignment_app/common/job/user_login.dart';
|
||||
import 'package:school_asignment_app/common/mixins/request_tool_mixin.dart';
|
||||
import 'package:school_asignment_app/common/store/user_store.dart';
|
||||
import 'package:school_asignment_app/common/utils/storage.dart';
|
||||
import 'package:school_asignment_app/common/utils/toast_utils.dart';
|
||||
import 'package:school_asignment_app/common/utils/utils.dart';
|
||||
import 'package:school_asignment_app/routes/app_pages.dart';
|
||||
|
|
@ -69,15 +68,13 @@ class LoginLogic extends GetxController with RequestToolMixin {
|
|||
EasyLoading.show(status: 'loading...');
|
||||
try {
|
||||
await getClient().toLogin(userName, userPwd);
|
||||
String? nameidentifier = UserStore.to.userInfo.value?.nameidentifier;
|
||||
String? nameidentifier = UserStore().userInfo.value?.nameidentifier;
|
||||
if (nameidentifier == null) {
|
||||
throw Exception('用户信息无效,请重试');
|
||||
}
|
||||
var data = await getClient().getUser(nameidentifier);
|
||||
if (data == null) {
|
||||
throw Exception('用户信息获取失败');
|
||||
}
|
||||
UserStore.to.setUserDetailInfo(data);
|
||||
print(data);
|
||||
//获取科目
|
||||
UserStore.to.getSubjectList();
|
||||
EasyLoading.dismiss();
|
||||
Get.offAllNamed(Routes.home);
|
||||
|
|
@ -112,18 +109,8 @@ class LoginLogic extends GetxController with RequestToolMixin {
|
|||
// RouterManager.router.navigateTo(context, RouterManager.root, clearStack: true, transition: getTransition());
|
||||
});*/
|
||||
} catch (e) {
|
||||
print('进来异常');
|
||||
EasyLoading.dismiss();
|
||||
StorageService.to.erase();
|
||||
UserStore.to.erase();
|
||||
if (e is Exception) {
|
||||
try {
|
||||
toMsg(e.toString().split(":")[1]);
|
||||
return;
|
||||
// ignore: empty_catches
|
||||
} catch (e) {}
|
||||
}
|
||||
toMsg('登录失败,请重试');
|
||||
// FastData.getInstance().cleanShared();
|
||||
// return toMsg(msg ?? '登录失败,请重试');
|
||||
} finally {
|
||||
state.canLogin.value = true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue