garage_repository.dart 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import 'package:domain/constants/api_constants.dart';
  2. import 'package:domain/entity/server_time.dart';
  3. import 'package:plugin_platform/platform_export.dart';
  4. import 'package:plugin_platform/http/dio_engine.dart';
  5. import 'package:plugin_platform/http/http_result.dart';
  6. import 'package:riverpod_annotation/riverpod_annotation.dart';
  7. import 'package:shared/utils/util.dart';
  8. import 'package:flutter_riverpod/flutter_riverpod.dart';
  9. import 'package:plugin_basic/provider/http_provider/http_provider.dart';
  10. import 'garage_state.dart';
  11. part 'garage_repository.g.dart';
  12. @Riverpod(keepAlive: true)
  13. GarageRepository garageRepository(Ref ref) {
  14. final dioEngine = ref.watch(dioEngineProvider);
  15. return GarageRepository(dioEngine: dioEngine);
  16. }
  17. /*
  18. * 数据仓库
  19. */
  20. class GarageRepository {
  21. DioEngine dioEngine;
  22. GarageRepository({required this.dioEngine});
  23. Future<HttpResult<Object>> fetchGarageList(
  24. Map<String, dynamic>? data, {
  25. CancelToken? cancelToken,
  26. }) async {
  27. Map<String, dynamic> params = {};
  28. // if (!Utils.isEmpty(type)) {
  29. // params["type"] = type!;
  30. // }
  31. params = data!;
  32. Map<String, String> headers = {};
  33. headers["Content-Type"] = "application/x-www-form-urlencoded";
  34. headers["Accept"] = "application/x.yyjobs-api.v1+json";
  35. final result = await dioEngine.requestNetResult(
  36. // ApiConstants.apiServerTime, // api 地址
  37. '/index.php/api/employee/extra/time', // api 地址
  38. params: params,
  39. headers: headers,
  40. method: HttpMethod.GET,
  41. isShowLoadingDialog: true, //是否展示默认的Loading弹窗
  42. networkDebounce: true, //是否防抖防止重复请求
  43. cancelToken: cancelToken,
  44. );
  45. //根据返回的结果,封装原始数据为Bean/Entity对象
  46. if (result.isSuccess) {
  47. //重新赋值data或list
  48. final json = result.getDataJson();
  49. var data = GarageState.fromMap(json!);
  50. //重新赋值data或list
  51. return result.convert<GarageState>(data: data);
  52. }
  53. return result.convert();
  54. }
  55. }