| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using TeamAAS.FlowEditor;
- using TeamAAS.FlowEditor.ProductModels;
- namespace Plugins.Vpp.Core
- {
- /// <summary>
- /// 「目标画面」名称下拉转换器:下拉项来自当前编辑产品的「画面列表」(ProductMeta.HomeFrames),
- /// 显示画面名称;选择名称后由 <see cref="Models.VppDisplayItem.FrameName"/> 映射回画面序号存储。
- /// 产品没有配置画面时允许手动输入名称/数字兜底。
- /// </summary>
- public class FrameNameConverter : StringConverter
- {
- /// <summary>当前编辑产品的画面列表(读不到返回空列表)</summary>
- internal static List<HomeFrameItem> GetFrames()
- {
- try
- {
- var pm = ProductManager.Instance;
- var cfg = pm.GetHomeFrameConfig(pm.CurrentProductName);
- return cfg?.HomeFrames ?? new List<HomeFrameItem>();
- }
- catch
- {
- return new List<HomeFrameItem>();
- }
- }
- /// <summary>第 no 个画面的显示名称(越界/空名时补"画面N")</summary>
- internal static string GetFrameName(List<HomeFrameItem> frames, int no)
- {
- if (frames != null && no >= 1 && no <= frames.Count)
- {
- var name = frames[no - 1]?.Name;
- if (!string.IsNullOrWhiteSpace(name)) return name;
- }
- return $"画面{no}";
- }
- /// <summary>画面名称 → 序号(重名取第一个;"画面N"格式兜底;纯数字直接解析;找不到返回 0)</summary>
- internal static int ResolveFrameNo(string name)
- {
- if (string.IsNullOrWhiteSpace(name)) return 0;
- name = name.Trim();
- var frames = GetFrames();
- for (int i = 0; i < frames.Count; i++)
- {
- if (string.Equals((frames[i]?.Name ?? "").Trim(), name, StringComparison.Ordinal))
- return i + 1;
- }
- if (int.TryParse(name, out int no)) return no;
- if (name.StartsWith("画面") && int.TryParse(name.Substring(2), out no)) return no;
- return 0;
- }
- public override bool GetStandardValuesSupported(ITypeDescriptorContext context) => true;
- // 有画面列表时排他(只能从下拉选),没有时允许手动输入
- public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) => GetFrames().Count > 0;
- public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
- {
- var frames = GetFrames();
- var names = new string[frames.Count];
- for (int i = 0; i < frames.Count; i++) names[i] = GetFrameName(frames, i + 1);
- return new StandardValuesCollection(names);
- }
- }
- }
|