94 lines
2.4 KiB
Dart
94 lines
2.4 KiB
Dart
import 'package:ef/ef.dart';
|
||
|
||
enum APPDeviceUpgrade {
|
||
ALL, // 全部 1
|
||
success, // 成功 2
|
||
fail, // 失败 3
|
||
waiting, // 等待中 4
|
||
upgrading, // 升级中 5
|
||
nothing, // 扫描中 6(新加)
|
||
}
|
||
|
||
extension APPDeviceUpgradeExtension on APPDeviceUpgrade {
|
||
/// 获取整型值
|
||
int get value {
|
||
switch (this) {
|
||
case APPDeviceUpgrade.ALL:
|
||
return 1;
|
||
case APPDeviceUpgrade.success:
|
||
return 2;
|
||
case APPDeviceUpgrade.fail:
|
||
return 3;
|
||
case APPDeviceUpgrade.waiting:
|
||
return 4;
|
||
case APPDeviceUpgrade.upgrading:
|
||
return 5;
|
||
case APPDeviceUpgrade.nothing:
|
||
return 6;
|
||
}
|
||
}
|
||
|
||
/// 根据整型值解析为枚举
|
||
static APPDeviceUpgrade? fromInt(int? type) {
|
||
switch (type) {
|
||
case 1:
|
||
return APPDeviceUpgrade.ALL;
|
||
case 2:
|
||
return APPDeviceUpgrade.success;
|
||
case 3:
|
||
return APPDeviceUpgrade.fail;
|
||
case 4:
|
||
return APPDeviceUpgrade.waiting;
|
||
case 5:
|
||
return APPDeviceUpgrade.upgrading;
|
||
case 6:
|
||
return APPDeviceUpgrade.nothing;
|
||
default:
|
||
return null;
|
||
}
|
||
}
|
||
|
||
/// 根据整型值返回对应名称字符串
|
||
static String? nameFromInt(int? type) {
|
||
final upgrade = fromInt(type);
|
||
return upgrade?.description;
|
||
}
|
||
|
||
/// 获取描述文本
|
||
String get description {
|
||
switch (this) {
|
||
case APPDeviceUpgrade.ALL:
|
||
return "全部".tr;
|
||
case APPDeviceUpgrade.success:
|
||
return "成功".tr;
|
||
case APPDeviceUpgrade.fail:
|
||
return "失败".tr;
|
||
case APPDeviceUpgrade.waiting:
|
||
return "等待中".tr;
|
||
case APPDeviceUpgrade.upgrading:
|
||
return "升级中".tr;
|
||
case APPDeviceUpgrade.nothing:
|
||
return "".tr;
|
||
}
|
||
}
|
||
|
||
/// 下拉选项用 - label 列表(展示)
|
||
static List<String> get labelList => APPDeviceUpgrade.values
|
||
.where((e) => e != APPDeviceUpgrade.nothing)
|
||
.map((e) => e.description)
|
||
.toList();
|
||
|
||
/// 下拉选项用 - value 列表(对应值)
|
||
static List<int> get valueList => APPDeviceUpgrade.values
|
||
.where((e) => e != APPDeviceUpgrade.nothing)
|
||
.map((e) => e.value)
|
||
.toList();
|
||
|
||
/// 下拉选项用 - map 列表(不含 nothing)
|
||
static List<Map<String, dynamic>> get list => APPDeviceUpgrade.values
|
||
.where((e) => e != APPDeviceUpgrade.nothing)
|
||
.map((e) => {"id": e.value, "name": e.description})
|
||
.toList();
|
||
|
||
}
|