77 lines
2.3 KiB
Dart
77 lines
2.3 KiB
Dart
/// 用户模型。
|
||
///
|
||
/// 字段由 [AuthService] 从真实登录响应(/sys/login)与
|
||
/// 当前用户接口(/sys/user/info)映射而来。
|
||
class User {
|
||
const User({
|
||
required this.id,
|
||
required this.account,
|
||
required this.displayName,
|
||
required this.role,
|
||
required this.token,
|
||
this.orgId = '',
|
||
this.roleId = '',
|
||
this.orgType = 0,
|
||
this.superAdmin = false,
|
||
});
|
||
|
||
/// 用户唯一标识(真实模式下取 orgId,缺省回退为账号)。
|
||
final String id;
|
||
|
||
/// 登录账号。
|
||
final String account;
|
||
|
||
/// 显示名称。
|
||
final String displayName;
|
||
|
||
/// 角色(如:运维管理员;多个角色以 `/` 连接)。
|
||
final String role;
|
||
|
||
/// 登录令牌。
|
||
final String token;
|
||
|
||
/// 当前用户所属组织 ID(用于表单默认选中)。
|
||
final String orgId;
|
||
|
||
/// 当前用户角色 ID(用于表单默认选中)。
|
||
final String roleId;
|
||
|
||
/// 当前用户所属组织类型(来自登录响应 orgType):
|
||
/// 0=平台(管理员) 1=渠道(渠道商) 2=代理商。
|
||
/// 用于按账号类别显隐功能模块(用户管理 / 渠道商管理)。
|
||
final int orgType;
|
||
|
||
/// 是否超级管理员(来自登录响应 superAdmin);为 true 视为管理员。
|
||
final bool superAdmin;
|
||
|
||
/// 序列化为 JSON(用于本地持久化)。
|
||
Map<String, dynamic> toJson() => {
|
||
'id': id,
|
||
'account': account,
|
||
'displayName': displayName,
|
||
'role': role,
|
||
'token': token,
|
||
'orgId': orgId,
|
||
'roleId': roleId,
|
||
'orgType': orgType,
|
||
'superAdmin': superAdmin,
|
||
};
|
||
|
||
/// 从 JSON 反序列化。
|
||
factory User.fromJson(Map<String, dynamic> json) => User(
|
||
id: json['id']?.toString() ?? '',
|
||
account: json['account']?.toString() ?? '',
|
||
displayName: json['displayName']?.toString() ?? '',
|
||
role: json['role']?.toString() ?? '',
|
||
token: json['token']?.toString() ?? '',
|
||
orgId: json['orgId']?.toString() ?? '',
|
||
roleId: json['roleId']?.toString() ?? '',
|
||
orgType: json['orgType'] is int
|
||
? json['orgType'] as int
|
||
: int.tryParse(json['orgType']?.toString() ?? '') ?? 0,
|
||
superAdmin: json['superAdmin'] is bool
|
||
? json['superAdmin'] as bool
|
||
: false,
|
||
);
|
||
}
|