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.
62 lines
1.5 KiB
62 lines
1.5 KiB
import 'dart:async';
|
|
import 'package:get/get.dart';
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
import '../../network/user_api.dart';
|
|
|
|
class AuthController extends GetxController {
|
|
final isLoading = false.obs;
|
|
final List<AuthCard> dataList = [];
|
|
// 是否正在登录中
|
|
final isLoggingIn = false.obs;
|
|
// 从GetX依赖注入中获取UserApi实例
|
|
late UserApi _userApi;
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
// 从全局依赖中获取UserApi
|
|
_userApi = Get.find<UserApi>();
|
|
_loadInitialData();
|
|
}
|
|
void _loadInitialData() {
|
|
isLoading.value = true;
|
|
dataList.assignAll([
|
|
AuthCard( title: '手机绑定', desc: '防止账号丢失', index: 1, authed: true),
|
|
AuthCard( title: '真实头像', desc: '提高交友成功率', index: 2, authed: false),
|
|
AuthCard( title: '实名认证', desc: '提高交友成功率', index: 3, authed: false),
|
|
]);
|
|
isLoading.value = false;
|
|
}
|
|
|
|
// 登录方法
|
|
Future<void> login() async {
|
|
try {
|
|
// 调用登录接口
|
|
final response = await _userApi.login({});
|
|
// 处理响应
|
|
if (response.data.isSuccess) {
|
|
|
|
} else {
|
|
SmartDialog.showToast(response.data.message);
|
|
}
|
|
} catch (e) {
|
|
SmartDialog.showToast('网络请求失败,请检查网络连接');
|
|
} finally {
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
class AuthCard {
|
|
final String title;
|
|
final String desc;
|
|
final int index;
|
|
final bool authed;
|
|
|
|
AuthCard({
|
|
required this.desc,
|
|
required this.title,
|
|
required this.index,
|
|
required this.authed,
|
|
});
|
|
}
|