88 lines
2.6 KiB
Dart
Executable File
88 lines
2.6 KiB
Dart
Executable File
import '../response/kr_node_group_list.dart';
|
|
import 'kr_group_outbound_list.dart';
|
|
|
|
import '../response/kr_node_list.dart';
|
|
import 'kr_outbound_item.dart';
|
|
|
|
/// 表示出站项列表的模型类
|
|
class KrOutboundsList {
|
|
|
|
|
|
|
|
/// 服务器分组
|
|
final List<KRGroupOutboundList> groupOutboundList = []; // 存储服务器分组的列表
|
|
|
|
/// 国家分组,包含所有国家
|
|
final List<KRCountryOutboundList> countryOutboundList = []; // 存储国家分组的列表
|
|
|
|
/// 全部列表
|
|
final List<KROutboundItem> allList = []; // 存储国家分组的列表
|
|
|
|
// 配置json
|
|
final List<Map<String,dynamic>> configJsonList = [];
|
|
|
|
/// 标签列表
|
|
final Map<String,KROutboundItem> keyList = {}; // 存储国家分组的列表
|
|
|
|
|
|
/// 处理出站项并将其分组
|
|
/// [list] 是要处理的出站项列表
|
|
void processOutboundItems(List<KrNodeListItem> list,List<KRNodeGroupListItem> groupList) {
|
|
final Map<String, List<KROutboundItem>> tagGroups = {};
|
|
final Map<String, List<KROutboundItem>> countryGroups = {};
|
|
|
|
// 用于追踪已使用的标签
|
|
final Map<String, int> tagCounter = {};
|
|
|
|
for (var element in list) {
|
|
// 生成唯一标签
|
|
var baseName = element.name;
|
|
if (tagCounter.containsKey(baseName)) {
|
|
tagCounter[baseName] = tagCounter[baseName]! + 1;
|
|
element.name = "${baseName}_${tagCounter[baseName]}";
|
|
} else {
|
|
tagCounter[baseName] = 0;
|
|
}
|
|
|
|
final KROutboundItem item = KROutboundItem(element);
|
|
allList.add(item);
|
|
|
|
// 根据标签分组出站项
|
|
for (var tag in element.tags) {
|
|
tagGroups.putIfAbsent(tag, () => []);
|
|
tagGroups[tag]?.add(item);
|
|
}
|
|
|
|
// 根据国家分组出站项
|
|
countryGroups.putIfAbsent(element.country, () => []);
|
|
countryGroups[element.country]?.add(item);
|
|
|
|
configJsonList.add(item.config);
|
|
keyList[item.tag] = item;
|
|
}
|
|
|
|
// 将标签分组转换为 KRGroupOutboundList 并添加到 groupOutboundList
|
|
for (var tag in tagGroups.keys) {
|
|
final item = KRGroupOutboundList(
|
|
tag: tag, outboundList: tagGroups[tag]!);
|
|
|
|
for (var group in groupList) {
|
|
if (item.tag == group.name) {
|
|
item.icon = group.icon;
|
|
break;
|
|
}
|
|
}
|
|
groupOutboundList.add(item); // 添加标签分组到列表
|
|
}
|
|
|
|
// 将国家分组转换为 KRCountryOutboundList 并添加到 countryOutboundList
|
|
for (var country in countryGroups.keys) {
|
|
countryOutboundList.add(KRCountryOutboundList(
|
|
country: country,
|
|
outboundList: countryGroups[country]!)); // 添加国家分组到列表
|
|
}
|
|
|
|
|
|
}
|
|
}
|