item_metas.dart 2.3 KB

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