Files
CloudHome-Ops/lib/models/sys_menu.dart

73 lines
1.6 KiB
Dart
Raw Permalink Normal View History

/// 系统菜单模型。
///
/// 对应后端 /sys/menu/* 接口的菜单实体。
/// type 取值:0=目录 1=菜单 2=按钮。
class SysMenu {
const SysMenu({
required this.menuId,
required this.name,
required this.url,
required this.type,
required this.icon,
required this.parentId,
required this.orderNum,
required this.perms,
required this.show,
});
/// 菜单 ID。
final String menuId;
/// 菜单名称。
final String name;
/// 路由地址。
final String url;
/// 类型(0=目录 1=菜单 2=按钮)。
final int type;
/// 图标。
final String icon;
/// 父级 ID。
final String parentId;
/// 排序号。
final int orderNum;
/// 权限标识。
final String perms;
/// 是否显示(0=显示 1=隐藏)。
final int show;
factory SysMenu.fromJson(Map<String, dynamic> json) {
return SysMenu(
menuId: (json['menuId'] ?? json['id'])?.toString() ?? '',
name: json['name']?.toString() ?? '',
url: json['url']?.toString() ?? '',
type: int.tryParse(json['type']?.toString() ?? '0') ?? 0,
icon: json['icon']?.toString() ?? '',
parentId: json['parentId']?.toString() ?? '',
orderNum: int.tryParse(json['orderNum']?.toString() ?? '0') ?? 0,
perms: json['perms']?.toString() ?? '',
show: int.tryParse(json['show']?.toString() ?? '0') ?? 0,
);
}
Map<String, dynamic> toJson() {
return {
'menuId': menuId,
'name': name,
'url': url,
'type': type,
'icon': icon,
'parentId': parentId,
'orderNum': orderNum,
'perms': perms,
'show': show,
};
}
}