auth_model.dart 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import 'package:json_annotation/json_annotation.dart';
  2. part 'auth_model.g.dart';
  3. /// 机构信息模型
  4. @JsonSerializable()
  5. class InstitutionInfo {
  6. final int id;
  7. final String uuid;
  8. final String name;
  9. InstitutionInfo({
  10. required this.id,
  11. required this.uuid,
  12. required this.name,
  13. });
  14. /// 从 JSON 创建 InstitutionInfo
  15. factory InstitutionInfo.fromJson(Map<String, dynamic> json) =>
  16. _$InstitutionInfoFromJson(json);
  17. /// 转换为 JSON
  18. Map<String, dynamic> toJson() => _$InstitutionInfoToJson(this);
  19. }
  20. /// 用户信息模型
  21. @JsonSerializable()
  22. class UserInfo {
  23. final int id;
  24. final String uuid;
  25. @JsonKey(name: 'institution_uuid')
  26. final String institutionUuid;
  27. final String name;
  28. final int gender;
  29. final String? avatar;
  30. @JsonKey(name: 'base_uuid')
  31. final String baseUuid;
  32. final String username;
  33. final String mobile;
  34. UserInfo({
  35. required this.id,
  36. required this.uuid,
  37. required this.institutionUuid,
  38. required this.name,
  39. required this.gender,
  40. this.avatar,
  41. required this.baseUuid,
  42. required this.username,
  43. required this.mobile,
  44. });
  45. /// 从 JSON 创建 UserInfo
  46. factory UserInfo.fromJson(Map<String, dynamic> json) =>
  47. _$UserInfoFromJson(json);
  48. /// 转换为 JSON
  49. Map<String, dynamic> toJson() => _$UserInfoToJson(this);
  50. }
  51. /// 认证响应模型
  52. @JsonSerializable()
  53. class AuthModel {
  54. @JsonKey(name: 'access_token')
  55. final String accessToken;
  56. @JsonKey(name: 'refresh_token')
  57. final String? refreshToken;
  58. @JsonKey(name: 'institution_info')
  59. final List<InstitutionInfo> institutionInfo;
  60. @JsonKey(name: 'user_info')
  61. final UserInfo userInfo;
  62. AuthModel({
  63. required this.accessToken,
  64. this.refreshToken,
  65. required this.institutionInfo,
  66. required this.userInfo,
  67. });
  68. /// 从 JSON 创建 AuthModel
  69. factory AuthModel.fromJson(Map<String, dynamic> json) =>
  70. _$AuthModelFromJson(json);
  71. /// 转换为 JSON
  72. Map<String, dynamic> toJson() => _$AuthModelToJson(this);
  73. }