You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
140 lines
4.3 KiB
140 lines
4.3 KiB
import 'package:dating_touchme_app/im/im_manager.dart';
|
|
import 'package:dating_touchme_app/oss/oss_manager.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
import 'package:get_storage/get_storage.dart';
|
|
import '../../model/mine/authentication_data.dart';
|
|
import '../../model/mine/user_data.dart';
|
|
import '../../network/user_api.dart';
|
|
import '../../pages/mine/user_info_page.dart';
|
|
import '../../pages/main/main_page.dart';
|
|
import '../global.dart';
|
|
|
|
class UserController extends GetxController {
|
|
|
|
// UserApi实例
|
|
late UserApi _userApi;
|
|
final storage = GetStorage();
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
// 从全局依赖中获取UserApi
|
|
_userApi = Get.find<UserApi>();
|
|
}
|
|
|
|
/// 获取环信用户token
|
|
Future<String?> getHxUserToken() async {
|
|
|
|
try {
|
|
// 调用获取环信用户token接口
|
|
final response = await _userApi.getHxUserToken();
|
|
|
|
// 处理响应
|
|
if (response.data.isSuccess) {
|
|
// 保存token到本地存储
|
|
String? token = response.data.data;
|
|
if (token != null) {
|
|
// 打印获取的token
|
|
print('获取环信用户token成功: $token');
|
|
IMManager.instance.login(token);
|
|
return token;
|
|
} else {
|
|
SmartDialog.showToast('获取的环信用户token为空');
|
|
return null;
|
|
}
|
|
} else {
|
|
SmartDialog.showToast(response.data.message);
|
|
return null;
|
|
}
|
|
} catch (e) {
|
|
print('获取环信用户token失败: $e');
|
|
SmartDialog.showToast('获取环信用户token失败,请重试');
|
|
return null;
|
|
}
|
|
}
|
|
|
|
bool _checkInformation(UserData information){
|
|
if(information.id == null){
|
|
return true;
|
|
}
|
|
if(information.id!.isEmpty){
|
|
return true;
|
|
}
|
|
if(information.genderCode == null){
|
|
return true;
|
|
}
|
|
if(information.genderCode!.isNaN){
|
|
return true;
|
|
}
|
|
if(information.birthYear == null){
|
|
return true;
|
|
}
|
|
if(information.nickName == null){
|
|
return true;
|
|
}
|
|
if(information.nickName!.isEmpty){
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/// 获取用户基础信息
|
|
Future<void> getBaseUserInfo(String userId, bool isMain) async {
|
|
try {
|
|
final response = await _userApi.getBaseUserInfo(userId);
|
|
|
|
if (response.data.isSuccess && response.data.data != null) {
|
|
// 成功获取基础信息后,调用获取婚姻信息详情接口
|
|
final baseInfo = response.data.data!;
|
|
final result = await _userApi.getMarriageInformationDetail();
|
|
// print(result.data);
|
|
if (result.data.isSuccess) {
|
|
if(result.data.data == null){
|
|
var information = UserData();
|
|
information.matchmakerFlag = baseInfo.matchmakerFlag;
|
|
information.realName = baseInfo.realName;
|
|
information.phone = baseInfo.phone;
|
|
GlobalData().userData = information;
|
|
if(isMain){
|
|
SmartDialog.showToast('转到完善信息');
|
|
Get.to(() => UserInfoPage());
|
|
} else {
|
|
Get.offAll(() => UserInfoPage());
|
|
}
|
|
// await storage.write('userId', GlobalData().userId);
|
|
return;
|
|
}
|
|
final information = result.data.data!;
|
|
information.matchmakerFlag = baseInfo.matchmakerFlag;
|
|
information.realName = baseInfo.realName;
|
|
information.phone = baseInfo.phone;
|
|
GlobalData().userData = information;
|
|
|
|
// await storage.write('userId', GlobalData().userId);
|
|
if (_checkInformation(information)) {
|
|
//跳转到完善信息
|
|
SmartDialog.showToast('转到完善信息');
|
|
// 导航到完善信息页面
|
|
if(isMain){
|
|
SmartDialog.showToast('转到完善信息');
|
|
Get.to(() => UserInfoPage());
|
|
} else {
|
|
Get.offAll(() => UserInfoPage());
|
|
}
|
|
} else if(!isMain){
|
|
await storage.write('userId', userId);
|
|
Get.offAll(MainPage());
|
|
}
|
|
}
|
|
} else {
|
|
SmartDialog.showToast(response.data.message);
|
|
}
|
|
} catch (e) {
|
|
// 获取用户信息失败不影响登录流程
|
|
SmartDialog.showToast('获取用户信息失败');
|
|
print('获取用户信息失败: $e');
|
|
}
|
|
}
|
|
|
|
}
|