base_model.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import 'package:fis_common/json_convert.dart';
  2. class RpcResult<T> {
  3. final bool isSuccess;
  4. final int errorCode;
  5. final String msg;
  6. T? data;
  7. RpcResult({
  8. required this.isSuccess,
  9. required this.errorCode,
  10. required this.msg,
  11. this.data,
  12. });
  13. factory RpcResult.fromJson(Map<String, dynamic> map) {
  14. T? data;
  15. if (map['data'] != null) {
  16. data = FJsonConvert.fromJson<T>(map['data']);
  17. }
  18. return RpcResult(
  19. isSuccess: map['isSuccess'] == true,
  20. errorCode: map['errorCode'],
  21. msg: map['msg'],
  22. data: data,
  23. );
  24. }
  25. }
  26. /// 分页数据
  27. class PagedData<T> {
  28. PagedData({
  29. required this.currentPage,
  30. required this.pageSize,
  31. required this.dataCount,
  32. this.pageData = const [],
  33. });
  34. factory PagedData.fromJson(Map<String, dynamic> map) {
  35. List<T> dataList = [];
  36. if (map['PageData'] != null) {
  37. dataList.addAll(
  38. (map['PageData'] as List).map((e) => FJsonConvert.fromJson<T>(e)!));
  39. }
  40. return PagedData(
  41. currentPage: map['CurrentPage'],
  42. pageSize: map['PageSize'],
  43. dataCount: map['DataCount'],
  44. pageData: dataList,
  45. );
  46. }
  47. Map<String, dynamic> toJson() {
  48. Map<String, dynamic> map = {};
  49. map['CurrentPage'] = this.currentPage;
  50. map['PageSize'] = this.pageSize;
  51. map['DataCount'] = this.dataCount;
  52. map['PageData'] = this.pageData.map((dynamic e) => e.toJson()).toList();
  53. return map;
  54. }
  55. final int currentPage;
  56. final int pageSize;
  57. final int dataCount;
  58. final List<T> pageData;
  59. }
  60. /// 分页请求
  61. class PagedRequest {
  62. PagedRequest({
  63. this.currentPage = 1,
  64. this.pageSize = 10,
  65. });
  66. int currentPage;
  67. int pageSize;
  68. Map<String, dynamic> toJson() {
  69. Map<String, dynamic> map = {};
  70. map['currentPage'] = this.currentPage;
  71. map['pageSize'] = this.pageSize;
  72. return map;
  73. }
  74. }