| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using Newtonsoft.Json;
- using PropertyGridLib.Attributes;
- namespace TeamAAS.FlowEditor.ProductModels
- {
- /// <summary>主页画面排列方式</summary>
- public enum FrameArrangeMode
- {
- 水平优先 = 1,
- 垂直优先 = 2
- }
- /// <summary>主页画面项:一个画面框的名称 + 状态圆点开关(在属性编辑器的画面列表中添加/删除)</summary>
- [Serializable]
- public class HomeFrameItem
- {
- [DisplayName("1.画面名称")]
- [Description("显示在画面框顶部标题栏")]
- public string Name { get; set; } = "";
- [DisplayName("2.显示状态圆点")]
- [Description("勾选后该画面框右上角显示 OK/NG 状态圆点")]
- public bool ShowDot { get; set; } = false;
- public override string ToString() => Name;
- }
- /// <summary>产品元数据:画面列表 / 排列 / 描述 / 序号,持久化到 Products/<productName>/product.json。</summary>
- [Serializable]
- public class ProductMeta
- {
- [Browsable(false)]
- public int Sequence { get; set; }
- [Browsable(false)]
- public string Name { get; set; } = "";
- [Category("I.基本信息")]
- [DisplayName("1.画面列表")]
- [Description("添加/删除主页画面;空列表 = 主页面不显示画面框")]
- [CollectionEditor(CanAdd = true, CanRemove = true, CanSort = true)]
- public List<HomeFrameItem> HomeFrames { get; set; } = new List<HomeFrameItem>();
- [Category("I.基本信息")]
- [DisplayName("2.画面排列")]
- [Description("水平优先 = 按行铺设;垂直优先 = 按列铺设")]
- public FrameArrangeMode HomeFrameArrange { get; set; } = FrameArrangeMode.水平优先;
- [Category("I.基本信息")]
- [DisplayName("3.产品描述")]
- [Description("产品的备注说明")]
- public string Description { get; set; } = "";
- // ── 以下为旧版画面配置字段(画面数/分号名称/分号圆点),仅用于旧配置自动迁移,不再使用 ──
- [Browsable(false)]
- public int HomeFrameCount { get; set; } = 0;
- [Browsable(false)]
- public string HomeFrameNames { get; set; } = "";
- [Browsable(false)]
- public string HomeFrameShowDot { get; set; } = "";
- /// <summary>取第 index 个画面名称(越界/缺失时补"画面N")</summary>
- public string GetFrameName(int index)
- {
- if (index >= 0 && HomeFrames != null && index < HomeFrames.Count)
- {
- var name = HomeFrames[index].Name;
- if (!string.IsNullOrWhiteSpace(name)) return name;
- }
- return $"画面{index + 1}";
- }
- /// <summary>取第 index 个画面是否显示状态圆点(越界/缺失时 false=不显示)</summary>
- public bool GetFrameShowDot(int index)
- {
- if (index >= 0 && HomeFrames != null && index < HomeFrames.Count)
- return HomeFrames[index].ShowDot;
- return false;
- }
- /// <summary>
- /// 旧版配置迁移:把旧字段(画面数/分号名称/分号圆点)转换成 HomeFrames 列表。
- /// 在 LoadProductMeta 反序列化后调用一次;新格式(HomeFrames 非空)直接跳过。
- /// </summary>
- public void MigrateLegacyFrames()
- {
- if (HomeFrames != null && HomeFrames.Count > 0) return; // 已是新格式
- if (HomeFrameCount <= 0) return;
- var names = (HomeFrameNames ?? "").Split(new[] { ';', ';' }, StringSplitOptions.RemoveEmptyEntries);
- var dots = (HomeFrameShowDot ?? "").Split(new[] { ';', ';' }, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < HomeFrameCount; i++)
- {
- var name = i < names.Length ? names[i].Trim() : "";
- if (string.IsNullOrWhiteSpace(name)) name = $"画面{i + 1}";
- bool showDot = i < dots.Length && bool.TryParse(dots[i].Trim(), out var d) && d;
- HomeFrames.Add(new HomeFrameItem { Name = name, ShowDot = showDot });
- }
- // 迁移完成,清空旧字段避免重复迁移
- HomeFrameCount = 0;
- HomeFrameNames = "";
- HomeFrameShowDot = "";
- }
- /// <summary>主页画面框水平排列(HomeFrameArrange=水平优先)</summary>
- [JsonIgnore]
- public bool IsHorizontalArrange
- {
- get => HomeFrameArrange == FrameArrangeMode.水平优先;
- set { if (value) HomeFrameArrange = FrameArrangeMode.水平优先; }
- }
- /// <summary>主页画面框垂直排列(HomeFrameArrange=垂直优先)</summary>
- [JsonIgnore]
- public bool IsVerticalArrange
- {
- get => HomeFrameArrange == FrameArrangeMode.垂直优先;
- set { if (value) HomeFrameArrange = FrameArrangeMode.垂直优先; }
- }
- }
- }
|