using Prism.Commands; using TeamAAS.Communication; using TeamAAS.Communication.Models; using TeamAAS.FlowEditor.Execution; namespace TeamAAS.ViewModels { /// /// 设置页 - 全局固定变量(Global 作用域,不随产品变)。 /// 产品级(Product 作用域)变量在产品右键“全局变量”弹窗中编辑,不在此页。 /// 采用克隆-编辑-提交:编辑器工作集与 live 列表解耦,点“保存”才提交并落盘 Config\global_vars.json。 /// public partial class SettingViewModel { #region 全局固定变量(Global 作用域) /// Global 作用域变量编辑器(工作集克隆)。绑定 GlobalVarEditorView。 public GlobalVarEditorViewModel GlobalVarEditor { get; private set; } /// 保存 Global 固定变量命令。 public DelegateCommand SaveGlobalVarsCommand { get; } /// (重新)从 live 列表克隆 Global 变量到编辑器工作集。进入该区/延迟加载/保存后调用。 public void InitGlobalVarEditor() { GlobalVarEditor = new GlobalVarEditorViewModel( VarScope.Global, GlobalVariableManager.Instance.CloneScoped(VarScope.Global)); RaisePropertyChanged(nameof(GlobalVarEditor)); } /// 提交 Global 工作集到 live 列表并落盘 Config\global_vars.json。 private void SaveGlobalVars() { if (GlobalVarEditor == null) return; GlobalVariableManager.Instance.ReplaceScoped(VarScope.Global, GlobalVarEditor.Items); GlobalVariableManager.Instance.SaveGlobalScoped(); ResultRegistry.RefreshGlobals(); DialogHelper.Success("全局固定变量已保存"); InitGlobalVarEditor(); } #endregion } }