123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import 'package:sport/bean/page.dart';
- import '../Converter.dart';
- class Resp {
- int code = -1;
- String msg;
- Resp(this.code, this.msg);
- factory Resp.fromJson(Map<String, dynamic> json) {
- return Resp(json['code'], json['msg'] ?? "");
- }
- }
- class RespData<T> extends Resp {
- T? data;
- RespData(code, msg, this.data) : super(code, msg);
- factory RespData.fromJson(Map<String, dynamic> json) {
- return RespData(json['code'], json['msg'], json['data'] != null ? Converter.fromJson<T>(json['data']) : null);
- }
- }
- class RespList<T> extends Resp {
- List<T> results;
- RespList(code, msg, this.results) : super(code, msg);
- factory RespList.fromJson(Map<String, dynamic> json) {
- List<T> results = [];
- if (json['data'] != null) {
- (json['data'] as List).forEach((element) {
- var item = Converter.fromJson<T>(element);
- if (item != null) results.add(item);
- });
- }
- return RespList(json['code'], json['msg'], results);
- }
- }
- class PageResult<T> {
- List<T>? results;
- Page? page;
- int count;
- PageResult({this.results, this.page, this.count = 0});
- }
- class RespPage<T> extends Resp {
- PageResult<T> pageResult;
- RespPage(code, msg, this.pageResult) : super(code, msg);
- factory RespPage.fromJson(Map<String, dynamic> json) {
- PageResult<T> pageResult = PageResult();
- List<T> results = [];
- if (json['data'] != null) {
- Map<String, dynamic> data = json['data'];
- if (data['list'] != null) {
- (data['list'] as List).forEach((element) {
- var item = Converter.fromJson<T>(element);
- if (item != null) results.add(item);
- });
- pageResult.results = results;
- } else if (data['data'] != null) {
- (data['data'] as List).forEach((element) {
- var item = Converter.fromJson<T>(element);
- if (item != null) results.add(item);
- });
- pageResult.results = results;
- }
- Page page = Page();
- if (data['pages'] != null) {
- page = Page.fromJson(data['pages'] as Map<String, dynamic>);
- pageResult.page = page;
- }
- if (data['count'] != null) {
- pageResult.count = Converter.toInt(data['count']);
- }
- }
- return RespPage(json['code'], json['msg'], pageResult);
- }
- }
|