ProductMeta.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using Newtonsoft.Json;
  5. using PropertyGridLib.Attributes;
  6. namespace TeamAAS.FlowEditor.ProductModels
  7. {
  8. /// <summary>主页画面排列方式</summary>
  9. public enum FrameArrangeMode
  10. {
  11. 水平优先 = 1,
  12. 垂直优先 = 2
  13. }
  14. /// <summary>主页画面项:一个画面框的名称 + 状态圆点开关(在属性编辑器的画面列表中添加/删除)</summary>
  15. [Serializable]
  16. public class HomeFrameItem
  17. {
  18. [DisplayName("1.画面名称")]
  19. [Description("显示在画面框顶部标题栏")]
  20. public string Name { get; set; } = "";
  21. [DisplayName("2.显示状态圆点")]
  22. [Description("勾选后该画面框右上角显示 OK/NG 状态圆点")]
  23. public bool ShowDot { get; set; } = false;
  24. public override string ToString() => Name;
  25. }
  26. /// <summary>产品元数据:画面列表 / 排列 / 描述 / 序号,持久化到 Products/&lt;productName&gt;/product.json。</summary>
  27. [Serializable]
  28. public class ProductMeta
  29. {
  30. [Browsable(false)]
  31. public int Sequence { get; set; }
  32. [Browsable(false)]
  33. public string Name { get; set; } = "";
  34. [Category("I.基本信息")]
  35. [DisplayName("1.画面列表")]
  36. [Description("添加/删除主页画面;空列表 = 主页面不显示画面框")]
  37. [CollectionEditor(CanAdd = true, CanRemove = true, CanSort = true)]
  38. public List<HomeFrameItem> HomeFrames { get; set; } = new List<HomeFrameItem>();
  39. [Category("I.基本信息")]
  40. [DisplayName("2.画面排列")]
  41. [Description("水平优先 = 按行铺设;垂直优先 = 按列铺设")]
  42. public FrameArrangeMode HomeFrameArrange { get; set; } = FrameArrangeMode.水平优先;
  43. [Category("I.基本信息")]
  44. [DisplayName("3.产品描述")]
  45. [Description("产品的备注说明")]
  46. public string Description { get; set; } = "";
  47. // ── 以下为旧版画面配置字段(画面数/分号名称/分号圆点),仅用于旧配置自动迁移,不再使用 ──
  48. [Browsable(false)]
  49. public int HomeFrameCount { get; set; } = 0;
  50. [Browsable(false)]
  51. public string HomeFrameNames { get; set; } = "";
  52. [Browsable(false)]
  53. public string HomeFrameShowDot { get; set; } = "";
  54. /// <summary>取第 index 个画面名称(越界/缺失时补"画面N")</summary>
  55. public string GetFrameName(int index)
  56. {
  57. if (index >= 0 && HomeFrames != null && index < HomeFrames.Count)
  58. {
  59. var name = HomeFrames[index].Name;
  60. if (!string.IsNullOrWhiteSpace(name)) return name;
  61. }
  62. return $"画面{index + 1}";
  63. }
  64. /// <summary>取第 index 个画面是否显示状态圆点(越界/缺失时 false=不显示)</summary>
  65. public bool GetFrameShowDot(int index)
  66. {
  67. if (index >= 0 && HomeFrames != null && index < HomeFrames.Count)
  68. return HomeFrames[index].ShowDot;
  69. return false;
  70. }
  71. /// <summary>
  72. /// 旧版配置迁移:把旧字段(画面数/分号名称/分号圆点)转换成 HomeFrames 列表。
  73. /// 在 LoadProductMeta 反序列化后调用一次;新格式(HomeFrames 非空)直接跳过。
  74. /// </summary>
  75. public void MigrateLegacyFrames()
  76. {
  77. if (HomeFrames != null && HomeFrames.Count > 0) return; // 已是新格式
  78. if (HomeFrameCount <= 0) return;
  79. var names = (HomeFrameNames ?? "").Split(new[] { ';', ';' }, StringSplitOptions.RemoveEmptyEntries);
  80. var dots = (HomeFrameShowDot ?? "").Split(new[] { ';', ';' }, StringSplitOptions.RemoveEmptyEntries);
  81. for (int i = 0; i < HomeFrameCount; i++)
  82. {
  83. var name = i < names.Length ? names[i].Trim() : "";
  84. if (string.IsNullOrWhiteSpace(name)) name = $"画面{i + 1}";
  85. bool showDot = i < dots.Length && bool.TryParse(dots[i].Trim(), out var d) && d;
  86. HomeFrames.Add(new HomeFrameItem { Name = name, ShowDot = showDot });
  87. }
  88. // 迁移完成,清空旧字段避免重复迁移
  89. HomeFrameCount = 0;
  90. HomeFrameNames = "";
  91. HomeFrameShowDot = "";
  92. }
  93. /// <summary>主页画面框水平排列(HomeFrameArrange=水平优先)</summary>
  94. [JsonIgnore]
  95. public bool IsHorizontalArrange
  96. {
  97. get => HomeFrameArrange == FrameArrangeMode.水平优先;
  98. set { if (value) HomeFrameArrange = FrameArrangeMode.水平优先; }
  99. }
  100. /// <summary>主页画面框垂直排列(HomeFrameArrange=垂直优先)</summary>
  101. [JsonIgnore]
  102. public bool IsVerticalArrange
  103. {
  104. get => HomeFrameArrange == FrameArrangeMode.垂直优先;
  105. set { if (value) HomeFrameArrange = FrameArrangeMode.垂直优先; }
  106. }
  107. }
  108. }