feat:增加公共组件
This commit is contained in:
56
lib/models/common_model.dart
Normal file
56
lib/models/common_model.dart
Normal file
@@ -0,0 +1,56 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import '../widget/chart.dart';
|
||||
|
||||
part 'common_model.g.dart';
|
||||
|
||||
@JsonSerializable(genericArgumentFactories: true)
|
||||
class PageResult<T> {
|
||||
@JsonKey(name: 'records')
|
||||
final List<T> records;
|
||||
|
||||
@JsonKey(name: 'total')
|
||||
final int total;
|
||||
|
||||
@JsonKey(name: 'size')
|
||||
final int size;
|
||||
|
||||
@JsonKey(name: 'current')
|
||||
final int current;
|
||||
|
||||
@JsonKey(name: 'pages')
|
||||
final int pages;
|
||||
|
||||
const PageResult({
|
||||
required this.records,
|
||||
required this.total,
|
||||
required this.size,
|
||||
required this.current,
|
||||
required this.pages,
|
||||
});
|
||||
|
||||
factory PageResult.fromJson(
|
||||
Map<String, dynamic> json,
|
||||
T Function(Object? json) fromJsonT,
|
||||
) =>
|
||||
_$PageResultFromJson(json, fromJsonT);
|
||||
|
||||
Map<String, dynamic> toJson(Object? Function(T value) toJsonT) =>
|
||||
_$PageResultToJson(this, toJsonT);
|
||||
}
|
||||
|
||||
@JsonSerializable(genericArgumentFactories: true)
|
||||
class ChartData {
|
||||
@JsonKey(name: 'name')
|
||||
final String name;
|
||||
|
||||
@JsonKey(name: 'value')
|
||||
final num value;
|
||||
|
||||
const ChartData({required this.name, required this.value});
|
||||
|
||||
factory ChartData.fromJson(Map<String, dynamic> json) =>
|
||||
_$ChartDataFromJson(json);
|
||||
|
||||
Map<String, dynamic> toJson() => _$ChartDataToJson(this);
|
||||
}
|
||||
Reference in New Issue
Block a user