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.
68 lines
2.2 KiB
68 lines
2.2 KiB
import 'package:dating_touchme_app/model/discover/rtc_channel_model.dart';
|
|
import 'package:dating_touchme_app/network/network_service.dart';
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
import 'package:get/get.dart';
|
|
|
|
/// 发现页相关控制器
|
|
class DiscoverController extends GetxController {
|
|
DiscoverController({NetworkService? networkService})
|
|
: _networkService = networkService ?? Get.find<NetworkService>();
|
|
|
|
final NetworkService _networkService;
|
|
|
|
/// RTC 频道列表
|
|
final rtcChannelList = <RtcChannelModel>[].obs;
|
|
|
|
/// 加载状态
|
|
final isLoading = false.obs;
|
|
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
// 初始化时加载数据
|
|
loadRtcChannelPage();
|
|
}
|
|
|
|
/// 获取 RTC 频道分页列表
|
|
Future<void> loadRtcChannelPage() async {
|
|
try {
|
|
isLoading.value = true;
|
|
final response = await _networkService.rtcApi.getRtcChannelPage();
|
|
final base = response.data;
|
|
print('API 响应: isSuccess=${base.isSuccess}, data=${base.data}');
|
|
if (base.isSuccess) {
|
|
if (base.data != null) {
|
|
// base.data 是 PaginatedResponse<RtcChannelModel>
|
|
final paginatedData = base.data!;
|
|
print(
|
|
'分页数据: total=${paginatedData.total}, records长度=${paginatedData.records.length}',
|
|
);
|
|
|
|
// 从 PaginatedResponse 的 records 中提取数据
|
|
rtcChannelList.assignAll(paginatedData.records);
|
|
print('更新后的列表长度: ${rtcChannelList.length}');
|
|
} else {
|
|
print('base.data 为 null');
|
|
rtcChannelList.clear();
|
|
}
|
|
} else {
|
|
final message = base.message.isNotEmpty ? base.message : '获取频道列表失败';
|
|
print('API 请求失败: $message');
|
|
SmartDialog.showToast(message);
|
|
rtcChannelList.clear();
|
|
}
|
|
} catch (e, stackTrace) {
|
|
print('获取频道列表异常: $e');
|
|
print('堆栈: $stackTrace');
|
|
SmartDialog.showToast('获取频道列表异常:$e');
|
|
rtcChannelList.clear();
|
|
} finally {
|
|
isLoading.value = false;
|
|
}
|
|
}
|
|
|
|
/// 刷新 RTC 频道列表
|
|
Future<void> refreshRtcChannelPage() async {
|
|
await loadRtcChannelPage();
|
|
}
|
|
}
|