修补登录BUG
This commit is contained in:
parent
97f9e1af3f
commit
6c38852db4
|
|
@ -15,7 +15,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);
|
||||
|
|
|
|||
|
|
@ -85,7 +85,6 @@ 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: '', label: "登录用户的token"),
|
||||
xToken(value: '', label: "登录用户的Xtoken,刷新token信息"),
|
||||
userMobile(value: '', label: "用户输入过的手机号码"),
|
||||
userInfo(value: '', label: "登录用户的基本信息 及 token过期时间"),
|
||||
userDetailInfo(value: '', label: "用户的详细信息");
|
||||
token(value: 'TOKEN', label: "登录用户的token"),
|
||||
xToken(value: 'XTOKEN', label: "登录用户的Xtoken,刷新token信息"),
|
||||
userMobile(value: 'USERMOBILE', label: "用户输入过的手机号码"),
|
||||
userInfo(value: 'USERINFO', label: "登录用户的基本信息 及 token过期时间"),
|
||||
userDetailInfo(value: 'USERDETAILINFO', label: "用户的详细信息");
|
||||
|
||||
final String label;
|
||||
final String value;
|
||||
|
|
|
|||
|
|
@ -6,15 +6,6 @@ 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();
|
||||
|
||||
/// 是否登录
|
||||
|
|
@ -28,8 +19,9 @@ class UserStore extends GetxController {
|
|||
/// 用户详细信息
|
||||
Rx<UserInfoDetail?> userDetailInfo = Rx(null);
|
||||
|
||||
void init() {
|
||||
token = StorageService.to.read(AppStorageKey.token.value) ?? '';
|
||||
UserStore init() {
|
||||
token = StorageService.to.read(AppStorageKey.token.value);
|
||||
xToken = StorageService.to.read(AppStorageKey.xToken.value);
|
||||
try {
|
||||
userInfo.value = StorageService.to.read(AppStorageKey.userInfo.value);
|
||||
userDetailInfo.value = StorageService.to.read(AppStorageKey.userDetailInfo.value);
|
||||
|
|
@ -43,6 +35,7 @@ class UserStore extends GetxController {
|
|||
isLogin.value = false;
|
||||
Get.toNamed(Routes.login);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/// 保存 token
|
||||
|
|
|
|||
|
|
@ -2,23 +2,14 @@ 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<void> _init() async {
|
||||
Future<StorageService> init() async {
|
||||
await GetStorage.init();
|
||||
_getStorage = GetStorage();
|
||||
return this;
|
||||
}
|
||||
|
||||
T? read<T>(String key) {
|
||||
|
|
|
|||
|
|
@ -15,15 +15,14 @@ void main() async {
|
|||
Get.testMode = true;
|
||||
|
||||
/// 初始化本地存储
|
||||
StorageService storageService = StorageService(initCall: () async {
|
||||
/// 初始化UserStore
|
||||
Get.put<UserStore>(UserStore());
|
||||
await Get.putAsync(() => StorageService().init());
|
||||
|
||||
/// 初始化UserStore
|
||||
Get.put<UserStore>(UserStore().init());
|
||||
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class LoginLogic extends GetxController with RequestToolMixin {
|
|||
EasyLoading.show(status: 'loading...');
|
||||
try {
|
||||
await getClient().toLogin(userName, userPwd);
|
||||
String? nameidentifier = UserStore().userInfo.value?.nameidentifier;
|
||||
String? nameidentifier = UserStore.to.userInfo.value?.nameidentifier;
|
||||
if (nameidentifier == null) {
|
||||
throw Exception('用户信息无效,请重试');
|
||||
}
|
||||
|
|
@ -108,8 +108,10 @@ class LoginLogic extends GetxController with RequestToolMixin {
|
|||
// RouterManager.router.navigateTo(context, RouterManager.root, clearStack: true, transition: getTransition());
|
||||
});*/
|
||||
} catch (e) {
|
||||
print(e);
|
||||
// FastData.getInstance().cleanShared();
|
||||
// return toMsg(msg ?? '登录失败,请重试');
|
||||
toMsg('登录失败,请重试');
|
||||
EasyLoading.dismiss();
|
||||
} finally {
|
||||
state.canLogin.value = true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue