item_metas.dart 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. ItemMeta(
  17. this.name, {
  18. required this.measureType,
  19. required this.description,
  20. required this.outputs,
  21. this.briefAnnotation = '',
  22. this.childItems = const [],
  23. });
  24. /// 根据名称获取子项
  25. ItemMeta? getChildByName(String name) {
  26. final matchList = childItems.where((e) => e.name == name);
  27. if (matchList.isNotEmpty) {
  28. return matchList.first;
  29. }
  30. return null;
  31. }
  32. /// 根据类型获取子项
  33. ItemMeta? getChildByType(String type) {
  34. final matchList = childItems.where((e) => e.measureType == type);
  35. if (matchList.isNotEmpty) {
  36. return matchList.first;
  37. }
  38. return null;
  39. }
  40. }
  41. class ItemOutputMeta {
  42. /// 名称
  43. String name;
  44. /// 描述
  45. String description;
  46. /// 单位
  47. VidUsUnit unit;
  48. /// 简介注释
  49. String? briefAnnotation;
  50. /// 额外注释
  51. String? additionalAnnotation;
  52. /// 小数精度
  53. int fractionalDigits;
  54. ItemOutputMeta(
  55. this.name,
  56. this.description,
  57. this.unit, {
  58. this.briefAnnotation,
  59. this.additionalAnnotation,
  60. this.fractionalDigits = 2,
  61. });
  62. }