62 lines
1.6 KiB
Dart
62 lines
1.6 KiB
Dart
// models/route_model.dart
|
|
import 'dart:convert';
|
|
|
|
class RouteModel {
|
|
final String target;
|
|
final List<RouteModel> children;
|
|
final bool hasMenu;
|
|
final String parentId;
|
|
final String routeId;
|
|
final String component;
|
|
final String path;
|
|
final String title;
|
|
final String parentIds;
|
|
final String meta;
|
|
final String routeOrder;
|
|
|
|
RouteModel({
|
|
required this.target,
|
|
required this.children,
|
|
required this.hasMenu,
|
|
required this.parentId,
|
|
required this.routeId,
|
|
required this.component,
|
|
required this.title,
|
|
required this.path,
|
|
required this.parentIds,
|
|
required this.meta,
|
|
required this.routeOrder,
|
|
});
|
|
|
|
factory RouteModel.fromJson(Map<String, dynamic> json) {
|
|
return RouteModel(
|
|
target: json['target'] ?? '',
|
|
children: (json['children'] as List<dynamic>? ?? [])
|
|
.map((child) => RouteModel.fromJson(child))
|
|
.toList(),
|
|
hasMenu: json['hasMenu'] ?? false,
|
|
parentId: json['parent_ID'] ?? '',
|
|
routeId: json['route_ID'] ?? '',
|
|
component: json['component'] ?? '',
|
|
parentIds: json['parent_IDS'] ?? '',
|
|
meta: json['meta'] ?? '',
|
|
path: json['path'] ?? '',
|
|
title: json['path'] ?? '',
|
|
routeOrder: json['route_ORDER'] ?? '0',
|
|
);
|
|
}
|
|
|
|
// // 解析meta字段获取title
|
|
// String get title {
|
|
// if (meta.isEmpty) return '';
|
|
// try {
|
|
// final metaMap = jsonDecode(meta) as Map<String, dynamic>;
|
|
// return metaMap['title'] ?? '';
|
|
// } catch (e) {
|
|
// return '';
|
|
// }
|
|
// }
|
|
|
|
// 判断是否是叶子节点(没有子节点的路由)
|
|
bool get isLeaf => children.isEmpty;
|
|
} |