Browse Source

代码优化 & 修复PC启动时最大化按钮显示不正确

loki.wu 2 years ago
parent
commit
7eaee93bd7

+ 1 - 1
fis/App.axaml.cs

@@ -36,7 +36,7 @@ namespace fis
         private async Task InitSlaveWindowsAsync() {
             try
             {
-                var manager = AppManager.Get<ISecondaryScreenManager>();
+                var manager = AppManager.Get<ISecondaryWindowManager>();
                 await manager.ShowWindowByTypeAsync(WindowType.Measure, "http://" + ShellConfig.Instance.AppHost+ "/index.html?page=measure&platformHost="+ ShellConfig.Instance.LocalApiHost, new System.Collections.Generic.Dictionary<string, string>(),false);
             }
             catch (Exception ex) {

+ 1 - 1
fis/IPlatformService.cs

@@ -221,7 +221,7 @@ namespace fis
         /// <summary>
         /// 跟据窗口名称获取窗口状态
         /// </summary>
-        Task<int> GetWindowStateAsync(string windowName);
+        int GetWindowStateAsync(string windowName);
         #endregion
     }
 

+ 11 - 8
fis/MainWindow.axaml.cs

@@ -13,13 +13,14 @@ namespace fis
 {
     public partial class MainWindow : BaseWindow
     {
-        private WindowState _windowState = WindowState.Normal;
+        private IWindowStateManager _windowStateManager;
 
         public override string WindowName { get ; protected set;} 
 
 
         public MainWindow()
         {
+            _windowStateManager = AppManager.Get<IWindowStateManager>();
             AvaloniaXamlLoader.Load(this);
             WindowName = "Main";
             InitializeComponent();
@@ -29,7 +30,7 @@ namespace fis
 
         protected override void HandleWindowStateChanged(WindowState state)
         {
-            _windowState = state;
+            _windowStateManager.SetWindowState(WindowName,state);
             BrowserManager.MainBrowser.ExcuteJS(TargetMethodName.OnWindowStateChange, new List<string> { ((int)state).ToString() });
         }
 
@@ -40,6 +41,7 @@ namespace fis
             BrowserManager.MainBrowser.BrowserInitialized += () =>
             {
                 WindowDragingHelper.MaximizeWindow(WindowName);
+                _windowStateManager.SetWindowState(WindowName, WindowState.Maximized);
 #if DEBUG
                 BrowserManager.MainBrowser.ShowDeveloperTools();
 #endif
@@ -56,7 +58,7 @@ namespace fis
                 {
                     if (e == WindowName)
                     {
-                        _windowState = WindowState.Normal;
+                        _windowStateManager.SetWindowState(WindowName, WindowState.Normal);
                         WindowDragingHelper.BeginWindowDrag(e);
                     }
                 };
@@ -72,12 +74,13 @@ namespace fis
                 {
                     if (e == WindowName)
                     {
-                        if (_windowState == WindowState.Maximized)
+                        var windowState = _windowStateManager.GetWindowStateByName(WindowName);
+                        if (windowState == WindowState.Maximized)
                         {
                             WindowDragingHelper.RestoreWindow(e);
                             return;
                         }
-                        _windowState = WindowState.Maximized;
+                        windowState = WindowState.Maximized;
                         WindowDragingHelper.MaximizeWindow(e);
                     }
                 };
@@ -85,7 +88,7 @@ namespace fis
                 {
                     if (e == WindowName)
                     {
-                        _windowState = WindowState.Minimized;
+                        _windowStateManager.SetWindowState(WindowName,WindowState.Minimized);
                         WindowDragingHelper.MinimizeWindow(e);
                     }
                 };
@@ -93,7 +96,7 @@ namespace fis
                 {
                     if (e == WindowName)
                     {
-                        _windowState = WindowState.Normal;
+                        _windowStateManager.SetWindowState(WindowName, WindowState.Normal);
                         WindowDragingHelper.RestoreWindow(e);
                     }
                 };
@@ -123,7 +126,7 @@ namespace fis
                 //UnRegister the main window.
                 WindowDragingHelper.UnRegisterWindow(WindowName);
             }
-            var manager = AppManager.Get<ISecondaryScreenManager>();
+            var manager = AppManager.Get<ISecondaryWindowManager>();
             manager.Dispose();
         }
     }

+ 2 - 1
fis/Managers/AppManager.cs

@@ -88,7 +88,8 @@ namespace fis.Managers
             RegisterManager<IVidManager>(new VidManager());
             RegisterManager<IFileExporterManager>(new FileExporterManager());
             RegisterManager<IFileStorageManager>(new FileStorageManager());
-            RegisterManager<ISecondaryScreenManager>(new SecondaryScreenManager());
+            RegisterManager<ISecondaryWindowManager>(new SecondaryWindowManager());
+            RegisterManager<IWindowStateManager>(new WindowStateManager());
             RegisterManager<IUltra3DManager>(new Ultra3DManager());
             _initialized = true;
         }

+ 1 - 1
fis/Managers/Interfaces/ISecondaryScreenManager.cs → fis/Managers/Interfaces/ISecondaryWindowManager.cs

@@ -4,7 +4,7 @@ using System.Threading.Tasks;
 
 namespace fis.Managers.Interfaces
 {
-    internal interface ISecondaryScreenManager : IFisManager
+    internal interface ISecondaryWindowManager : IFisManager
     {
         SlaveWindow? SlaveWindow { get; }
 

+ 21 - 0
fis/Managers/Interfaces/IWindowStateManager.cs

@@ -0,0 +1,21 @@
+using Avalonia.Controls;
+
+namespace fis.Managers.Interfaces
+{
+    internal interface  IWindowStateManager :IFisManager
+    {
+        /// <summary>
+        /// 设置指定Window的状态
+        /// </summary>
+        /// <param name="name"></param>
+        /// <param name="state"></param>
+        void SetWindowState(string name, WindowState state);
+
+        /// <summary>
+        /// 根据名称获取Window状态
+        /// </summary>
+        /// <param name="name"></param>
+        /// <returns></returns>
+        WindowState GetWindowStateByName(string name);
+    }
+}

+ 10 - 1
fis/Managers/SecondaryScreenManager.cs → fis/Managers/SecondaryWindowManager.cs

@@ -9,12 +9,21 @@ using System.Threading.Tasks;
 
 namespace fis.Managers
 {
-    internal class SecondaryScreenManager: ISecondaryScreenManager
+    internal class SecondaryWindowManager: ISecondaryWindowManager
     {
+        /// <summary>
+        /// 副窗口
+        /// </summary>
         public SlaveWindow? SlaveWindow { get; private set; }
 
+        /// <summary>
+        /// 是否使用第二窗口,默认情况下多窗口才启用
+        /// </summary>
         public bool IsUseSecondWindow { get; private set; } = false;
 
+        /// <summary>
+        /// 是否展示
+        /// </summary>
         public bool IsVisible { get; private set; } = false;
 
         public async Task ShowWindowByTypeAsync(WindowType windowType, string host, Dictionary<string, string> keyValuePairs,bool isShowWindow = true) 

+ 37 - 0
fis/Managers/WindowStateManager.cs

@@ -0,0 +1,37 @@
+using Avalonia.Controls;
+using fis.Managers.Interfaces;
+using System;
+using System.Collections.Generic;
+
+namespace fis.Managers
+{
+    internal class WindowStateManager : IWindowStateManager
+    {
+        private Dictionary<string, WindowState> _windowStates = new();
+
+        public void SetWindowState(string name,WindowState state) {
+            if (_windowStates.ContainsKey(name))
+            {
+                _windowStates[name] = state;
+            }
+            else 
+            {
+                _windowStates.Add(name, state);
+            }
+        }
+
+        public WindowState GetWindowStateByName(string name) 
+        {
+            if (_windowStates.ContainsKey(name)) 
+            {
+                return _windowStates[name];
+            }
+            return WindowState.Normal;
+        }
+
+        public void Dispose()
+        {
+           // 
+        }
+    }
+}

+ 7 - 7
fis/PlatformService.cs

@@ -38,7 +38,7 @@ namespace fis
         /// 副窗口Token过期时,关闭第二窗口,通知主窗口退出登录
         /// </summary>
         public void CloseSlaveWindow() {
-            var manager = AppManager.Get<ISecondaryScreenManager>();
+            var manager = AppManager.Get<ISecondaryWindowManager>();
             var window = manager.SlaveWindow;
             if (window != null)
             {
@@ -62,7 +62,7 @@ namespace fis
             dictionary.Add("patientCode", patientCode);
             dictionary.Add("remedicalCode", remedicalCode);
             dictionary.Add("recordCode", recordCode);
-            var manager = AppManager.Get<ISecondaryScreenManager>();
+            var manager = AppManager.Get<ISecondaryWindowManager>();
             await manager.ShowWindowByTypeAsync(WindowType.Measure,"http://" + ShellConfig.Instance.AppHost + "/#/measure/measure_home", dictionary);
             return true;
         }
@@ -82,7 +82,7 @@ namespace fis
             dictionary.Add("reportCode", reportCode);
             dictionary.Add("recordCode", recordCode);
             dictionary.Add("referralRecordCode", referralRecordCode);
-            var manager = AppManager.Get<ISecondaryScreenManager>();
+            var manager = AppManager.Get<ISecondaryWindowManager>();
             manager.ShowWindowByTypeAsync(WindowType.ReportEdit, "http://" + ShellConfig.Instance.AppHost + "/#/remedical/report/report_edit", dictionary).GetAwaiter().GetResult();
             return true;
         }
@@ -100,7 +100,7 @@ namespace fis
             dictionary.Add("token", token);
             dictionary.Add("reportCode", reportCode);
             dictionary.Add("recordCode", recordCode);
-            var manager = AppManager.Get<ISecondaryScreenManager>();
+            var manager = AppManager.Get<ISecondaryWindowManager>();
             manager.ShowWindowByTypeAsync(WindowType.ReportEdit, "http://" + ShellConfig.Instance.AppHost + "/#/remedical/report/report_edit", dictionary).GetAwaiter().GetResult();
             return true;
         }
@@ -111,7 +111,7 @@ namespace fis
         /// <returns></returns>
         public bool OpenReportDesigner(string templateId, string name, string type, string token)
         {
-            var manager = AppManager.Get<ISecondaryScreenManager>();
+            var manager = AppManager.Get<ISecondaryWindowManager>();
             var dictionary = new Dictionary<string, string>();
             dictionary.Add("templateId", templateId);
             dictionary.Add("templateName", name);
@@ -130,7 +130,7 @@ namespace fis
         /// <param name="templateJson"></param>
         public void SaveReportTemplate(string templateId, string name, string useObject, string templateJson) 
         {
-            var manager = AppManager.Get<ISecondaryScreenManager>();
+            var manager = AppManager.Get<ISecondaryWindowManager>();
             var window =  manager.SlaveWindow;
             var args = new List<string>();
             args.Add(templateId);
@@ -232,7 +232,7 @@ namespace fis
             //
         }
 
-        public virtual async Task<int> GetWindowStateAsync(string windowName)
+        public virtual int GetWindowStateAsync(string windowName)
         {
             return 0;
         }

+ 12 - 20
fis/SlaveWindow.axaml.cs

@@ -2,27 +2,21 @@ using Avalonia;
 using Avalonia.Controls;
 using Avalonia.Markup.Xaml;
 using Avalonia.Threading;
-using fis.Mac;
 using fis.Managers;
+using fis.Managers.Interfaces;
 using fis.Utilities;
-using fis.Win;
 using fis.Win.Utilities;
 using System;
 using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Reflection;
-using System.Runtime.InteropServices;
 using System.Threading;
 using System.Threading.Tasks;
-using Xilium.CefGlue.Avalonia;
 
 namespace fis
 {
     public partial class SlaveWindow : BaseWindow
     {
-        private string _host = "";
-        private Dictionary<string, string> _parameters = new Dictionary<string, string>();
+
+        private IWindowStateManager _windowStateManager;
 
         /// <summary>
         /// 副窗口是否强制关闭,false则是点击关闭时隐藏,true则是窗口直接关闭
@@ -34,12 +28,18 @@ namespace fis
         public SlaveWindow()
         {
             WindowName = "Slave";
+            _windowStateManager = AppManager.Get<IWindowStateManager>();
             AvaloniaXamlLoader.Load(this);
             InitializeComponent();
             InitializeSlaveComponent();
             Closing += SlaveWindow_Closing;
         }
 
+        protected override void HandleWindowStateChanged(WindowState state)
+        {
+            _windowStateManager.SetWindowState(WindowName, state);
+        }
+
         private void InitializeSlaveComponent()
         {
             var scriptObj = new FisBrowserScriptObject(PlateformName, BrowserManager.SlaveBrowser);
@@ -61,14 +61,12 @@ namespace fis
         /// <param name="dictionary"></param>
         public void InitParameters(string host, Dictionary<string, string> dictionary)
         {
-            _parameters = dictionary;
-            _host = host;
             var parameter = "";
             var index = 0;
-            foreach (var p in _parameters)
+            foreach (var p in dictionary)
             {
                 parameter += p.Key + "=" + p.Value;
-                if (index < _parameters.Count - 1)
+                if (index < dictionary.Count - 1)
                 {
                     parameter += "&";
                 }
@@ -80,10 +78,6 @@ namespace fis
                 var url = "http://" + ShellConfig.Instance.AppHost + "/index.html?page=measure&" + parameter;
                 BrowserManager.SlaveBrowser.Address = url;
             }
-            else
-            {
-                BrowserManager.SlaveBrowser.Address = _host;
-            }
             WindowStartupLocation = WindowStartupLocation.Manual;
             Position = new PixelPoint();
             WindowState = WindowState.Maximized;
@@ -97,10 +91,8 @@ namespace fis
         internal async Task ChangeContentViewAsync(string host, Dictionary<string, string> keyValuePairs, WindowType windowType)
         {
             TargetMethodName targetMethodName;
-            _host = host;
-            _parameters = keyValuePairs;
             var arguments = new List<string>();
-            foreach (var p in _parameters)
+            foreach (var p in keyValuePairs)
             {
                 arguments.Add(p.Value);
             }

+ 1 - 1
fis/Utilities/FisBrowserScriptObject.cs

@@ -380,7 +380,7 @@ namespace fis.Utilities
 
         public void CloseSlaveWindow(int WindowType = 0)
         {
-            var manager = AppManager.Get<ISecondaryScreenManager>();
+            var manager = AppManager.Get<ISecondaryWindowManager>();
              Dispatcher.UIThread.InvokeAsync(() =>
              {
                  var slaveWindow = manager.SlaveWindow;

+ 3 - 13
fis/Win/WinService.cs

@@ -64,20 +64,10 @@ namespace fis.Win
         }
 
 
-        public override async Task<int> GetWindowStateAsync(string windowName)
+        public override int GetWindowStateAsync(string windowName)
         {
-            var state = (int)WindowState.Normal;
-            await Dispatcher.UIThread.InvokeAsync(() =>
-            {
-                var slaveWindowManager = AppManager.Get<ISecondaryScreenManager>();
-                if (windowName == AppManager.MainWindow.WindowName)
-                {
-                    state = (int)AppManager.MainWindow.WindowState;
-                }
-                else if (slaveWindowManager.SlaveWindow != null && windowName == slaveWindowManager.SlaveWindow.WindowName) {
-                    state = (int)slaveWindowManager.SlaveWindow.WindowState;
-                }
-            });
+            var windowStateManager = AppManager.Get<IWindowStateManager>();
+            var state = (int)windowStateManager.GetWindowStateByName(windowName);
             return state;
         }
     }