item_metas.dart 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. int? rimWidth;
  24. ItemMeta(
  25. this.name, {
  26. required this.measureType,
  27. required this.description,
  28. required this.outputs,
  29. // this.buyStatus,
  30. this.rimWidth,
  31. this.briefAnnotation = '',
  32. this.childItems = const [],
  33. });
  34. /// 根据名称获取子项
  35. ItemMeta? getChildByName(String name) {
  36. final matchList = childItems.where((e) => e.name == name);
  37. if (matchList.isNotEmpty) {
  38. return matchList.first;
  39. }
  40. return null;
  41. }
  42. /// 根据类型获取子项
  43. ItemMeta? getChildByType(String type) {
  44. final matchList = childItems.where((e) => e.measureType == type);
  45. if (matchList.isNotEmpty) {
  46. return matchList.first;
  47. }
  48. return null;
  49. }
  50. }
  51. class ItemOutputMeta {
  52. /// 名称
  53. String name;
  54. /// 描述
  55. String description;
  56. /// 单位
  57. VidUsUnit unit;
  58. /// 简介注释
  59. String? briefAnnotation;
  60. /// 额外注释
  61. String? additionalAnnotation;
  62. /// 小数精度
  63. int fractionalDigits;
  64. ItemOutputMeta(
  65. this.name,
  66. this.description,
  67. this.unit, {
  68. this.briefAnnotation,
  69. this.additionalAnnotation,
  70. this.fractionalDigits = 2,
  71. });
  72. ItemOutputMeta copyWith({
  73. String? name,
  74. String? description,
  75. VidUsUnit? unit,
  76. String? briefAnnotation,
  77. String? additionalAnnotation,
  78. int? fractionalDigits,
  79. }) {
  80. final meta = ItemOutputMeta(
  81. name ?? this.name,
  82. description ?? this.description,
  83. unit ?? this.unit,
  84. additionalAnnotation: additionalAnnotation ?? this.additionalAnnotation,
  85. fractionalDigits: fractionalDigits ?? this.fractionalDigits,
  86. );
  87. return meta;
  88. }
  89. }