item_metas.dart 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. import 'package:vid/us/vid_us_unit.dart';
  2. /// 测量项配置元信息
  3. class ItemMeta {
  4. /// 名称
  5. String name;
  6. /// 描述
  7. String description;
  8. /// 简介注释
  9. String briefAnnotation;
  10. /// 测量类型
  11. String measureType;
  12. /// 计算输出元信息
  13. List<ItemOutputMeta> outputs;
  14. /// 子项元信息集合
  15. List<ItemMeta> childItems;
  16. /// 当前测量项的购买状态
  17. /// 0: Free 免费
  18. /// 1: Probation 试用中
  19. /// 2: Unpaid 未购买
  20. /// 3: Purchased 已购买
  21. /// /// 【TODO】 暂时屏蔽 buyStatus
  22. // WorkingItemStatusEnum? buyStatus;
  23. ItemMeta(
  24. this.name, {
  25. required this.measureType,
  26. required this.description,
  27. required this.outputs,
  28. // this.buyStatus,
  29. this.briefAnnotation = '',
  30. this.childItems = const [],
  31. });
  32. /// 根据名称获取子项
  33. ItemMeta? getChildByName(String name) {
  34. final matchList = childItems.where((e) => e.name == name);
  35. if (matchList.isNotEmpty) {
  36. return matchList.first;
  37. }
  38. return null;
  39. }
  40. /// 根据类型获取子项
  41. ItemMeta? getChildByType(String type) {
  42. final matchList = childItems.where((e) => e.measureType == type);
  43. if (matchList.isNotEmpty) {
  44. return matchList.first;
  45. }
  46. return null;
  47. }
  48. }
  49. class ItemOutputMeta {
  50. /// 名称
  51. String name;
  52. /// 描述
  53. String description;
  54. /// 单位
  55. VidUsUnit unit;
  56. /// 简介注释
  57. String? briefAnnotation;
  58. /// 额外注释
  59. String? additionalAnnotation;
  60. /// 小数精度
  61. int fractionalDigits;
  62. ItemOutputMeta(
  63. this.name,
  64. this.description,
  65. this.unit, {
  66. this.briefAnnotation,
  67. this.additionalAnnotation,
  68. this.fractionalDigits = 2,
  69. });
  70. ItemOutputMeta copyWith({
  71. String? name,
  72. String? description,
  73. VidUsUnit? unit,
  74. String? briefAnnotation,
  75. String? additionalAnnotation,
  76. int? fractionalDigits,
  77. }) {
  78. final meta = ItemOutputMeta(
  79. name ?? this.name,
  80. description ?? this.description,
  81. unit ?? this.unit,
  82. additionalAnnotation: additionalAnnotation ?? this.additionalAnnotation,
  83. fractionalDigits: fractionalDigits ?? this.fractionalDigits,
  84. );
  85. return meta;
  86. }
  87. }