42 lines
1.2 KiB
Dart
42 lines
1.2 KiB
Dart
import 'package:dio/dio.dart';
|
||
import 'package:maibu_satabot_v2/core/consts/http_api_consts.dart';
|
||
import 'package:maibu_satabot_v2/features/v2/home/data/datasources/site_datasource.dart';
|
||
import 'package:maibu_satabot_v2/features/v2/home/domain/entities/site_entity.dart';
|
||
|
||
class SiteDataSourceImpl implements SiteDataSource {
|
||
final Dio dio;
|
||
|
||
SiteDataSourceImpl(this.dio);
|
||
|
||
@override
|
||
Future<List<SiteEntity>> getSiteList(int orgId) async {
|
||
// 构建查询参数:orgId 为 0 时不传递
|
||
final queryParams = <String, dynamic>{
|
||
'pageNum': 1,
|
||
'pageSize': 9999,
|
||
};
|
||
|
||
if (orgId != 0) {
|
||
queryParams['orgId'] = orgId;
|
||
}
|
||
|
||
final response = await dio.get(
|
||
HttpApiConsts.getSiteList,
|
||
queryParameters: queryParams,
|
||
);
|
||
|
||
if (response.statusCode != 200) {
|
||
throw Exception('网络请求失败: ${response.statusCode}');
|
||
}
|
||
|
||
final responseData = response.data;
|
||
|
||
if (responseData['code'] != 200) {
|
||
throw Exception(responseData['msg'] ?? '业务异常');
|
||
}
|
||
|
||
final List<dynamic> rows = responseData['rows'] ?? [];
|
||
return rows.map((item) => SiteEntity.fromJson(item)).toList();
|
||
}
|
||
}
|