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.
 
 
 
 
 

117 lines
3.7 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 '../../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;
@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;
}
}
/// 获取用户基础信息
Future<void> getBaseUserInfo(String userId) async {
try {
final response = await _userApi.getBaseUserInfo(userId);
if (response.data.isSuccess && response.data.data != null) {
// 成功获取基础信息后,调用获取婚姻信息详情接口
await getMarriageInformationDetail(false);
} else {
SmartDialog.showToast(response.data.message);
}
} catch (e) {
// 获取用户信息失败不影响登录流程
SmartDialog.showToast('获取用户信息失败');
}
}
/// 获取用户婚姻信息详情
Future<void> getMarriageInformationDetail(bool isMain) async {
try {
final response = await _userApi.getMarriageInformationDetail();
if (response.data.isSuccess) {
// 检查data是否为null或者是空对象
print(78111);
if(response.data.data == null){
if(isMain){
SmartDialog.showToast('转到完善信息');
Get.to(() => UserInfoPage());
} else {
Get.offAll(() => UserInfoPage());
}
return;
}
final information = response.data.data!;
if (information.id.isNotEmpty) {
final result = await _userApi.getCertificationList(information.id);
List<AuthenticationData> list = result.data.data!;
final record = list.firstWhere((item) => item.authenticationCode == 0);
information.realAuth = record.status == 1;
}
GlobalData().userData = information;
print(95111);
print(GlobalData().userData);
if (information.id.isEmpty || information.genderCode.isNaN || information.birthYear == null) {
//跳转到完善信息
SmartDialog.showToast('转到完善信息');
// 导航到完善信息页面
if(isMain){
SmartDialog.showToast('转到完善信息');
Get.to(() => UserInfoPage());
} else {
Get.offAll(() => UserInfoPage());
}
} else if(!isMain){
Get.offAll(MainPage());
}
}
} catch (e) {
// 获取婚姻信息失败不影响登录流程
print('获取婚姻信息异常: $e');
}
}
}