Browse Source

报告模板闭环

loki.wu 2 years ago
parent
commit
7cf0bb03fc

+ 11 - 1
fis/IPlatformService.cs

@@ -50,7 +50,17 @@ namespace fis
         /// 打开报告模板设计器
         /// </summary>
         /// <returns></returns>
-        bool OpenReportDesigner();
+        bool OpenReportDesigner(string templateId, string name, string type, string token);
+
+        /// <summary>
+        /// 保存报告模板
+        /// </summary>
+        /// <param name="templateId"></param>
+        /// <param name="name"></param>
+        /// <param name="useObject"></param>
+        /// <param name="templateJson"></param>
+        void SaveReportTemplate(string templateId,string name,string useObject,string templateJson);
+
         #endregion
 
         #region File Storage

+ 57 - 2
fis/MainWindow.axaml.cs

@@ -15,6 +15,9 @@ using System.Threading;
 using System.Runtime.InteropServices;
 using fis.Managers;
 using fis.Win.Dev.Helpers;
+using fis.Win.Dev.Utilities;
+using System.Collections.Generic;
+using fis.Win.Dev.Managers.Interfaces;
 
 namespace fis
 {
@@ -32,7 +35,7 @@ namespace fis
             ExtendClientAreaTitleBarHeightHint = -1;
             MainThreadSyncContext = SynchronizationContext.Current;
 #if DEBUG
-          //  this.AttachDevTools();
+            this.AttachDevTools();
          
 #endif
         }
@@ -67,7 +70,7 @@ namespace fis
             _browser.BrowserInitialized += () =>
             {
 #if DEBUG
-                //_browser!.ShowDeveloperTools();
+                _browser!.ShowDeveloperTools();
 #endif
             };
             browserContainer.Child = _browser;
@@ -137,6 +140,58 @@ namespace fis
         /// <returns></returns>
         public void WriteLog(string message) => Logger.Write(message);
 
+        /// <summary>
+        /// 保存报告模板
+        /// </summary>
+        /// <param name="templateId"></param>
+        /// <param name="name"></param>
+        /// <param name="useObject"></param>
+        /// <param name="templateJson"></param>
+        public void SaveTemplate(string templateId, string name, string useObject, string templateJson)
+        {
+            List<string> args = new List<string>();
+            args.Add(templateId);
+            args.Add(name);
+            args.Add(useObject);
+            args.Add(templateJson);
+            ExecuteJS("externalNotification", TargetMethodName.SaveReportTemplate, args);
+        }
+
+
+        /// <summary>
+        /// 执行Js方法
+        /// </summary>
+        /// <param name="methodName"></param>
+        /// <param name="targetMethodName"></param>
+        /// <param name="arguments"></param>
+        private void ExecuteJS(string methodName, TargetMethodName targetMethodName, List<string> arguments)
+        {
+            string callString = methodName + "(";
+            if (arguments != null)
+            {
+                string comma = ", ";
+                var argumentsStr = "";
+                int index = 0;
+                foreach (var e in arguments)
+                {
+                    if (index == arguments.Count - 1)
+                    {
+                        argumentsStr += e;
+                    }
+                    else
+                    {
+                        argumentsStr += e + "&";
+                    }
+                    index++;
+                }
+                var escaped = System.Web.HttpUtility.JavaScriptStringEncode(argumentsStr, true);
+                callString += (int)targetMethodName + comma + escaped;
+            }
+            callString += ");";
+
+            AvaloniaCefBrowserHelper.browser?.ExecuteJavaScript(callString, null, 0);
+        }
+
         /// <summary>
         /// 设置窗体标题
         /// </summary>

+ 7 - 0
fis/Managers/Interfaces/ISecondaryScreenManager.cs

@@ -18,5 +18,12 @@ namespace fis.Win.Dev.Managers.Interfaces
         /// <param name="keyValuePairs"></param>
         /// <returns></returns>
         Task ShowWindowByTypeAsync(WindowType windowType, string host, Dictionary<string, string> keyValuePairs);
+
+        /// <summary>
+        /// 获取Window
+        /// </summary>
+        /// <param name="windowType"></param>
+        /// <returns></returns>
+        SlaveWindow? GetWindowByType(WindowType windowType);
     }
 }

+ 10 - 0
fis/Managers/SecondaryScreenManager.cs

@@ -43,6 +43,16 @@ namespace fis.Win.Dev.Managers
             });
         }
 
+        public SlaveWindow? GetWindowByType(WindowType windowType) {
+            if (windows.ContainsKey(windowType))
+            {
+                return windows[windowType];
+            }
+            else {
+                return null;
+            }
+        }
+
         private void Window_Closed(object? sender, EventArgs e)
         {
             if (windows.Any(w => w.Value == sender)) {

+ 0 - 4
fis/Models/Vid/Processors/BaseProcessor.cs

@@ -1,8 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace fis.Models.Vid.Processors
 {

+ 62 - 4
fis/PlatformService.cs

@@ -44,22 +44,80 @@ namespace fis
             dictionary.Add("index", index);
             dictionary.Add("imageIndex", imageIndex);
             var manager = AppManager.Get<ISecondaryScreenManager>();
-            manager.ShowWindowByTypeAsync(WindowType.Measure,"http://" + ShellConfig.Instance.AppHost + "/#/measure/measure_home", dictionary);
-            return  true;
+            manager.ShowWindowByTypeAsync(WindowType.Measure,"http://" + ShellConfig.Instance.AppHost + "/#/measure/measure_home", dictionary).GetAwaiter().GetResult();
+            return true;
         }
 
         /// <summary>
         /// 打开报告设计器
         /// </summary>
         /// <returns></returns>
-        public bool OpenReportDesigner()
+        public bool OpenReportDesigner(string templateId, string name, string type, string token)
         {
             var manager = AppManager.Get<ISecondaryScreenManager>();
             var dictionary = new Dictionary<string, string>();
-            manager.ShowWindowByTypeAsync(WindowType.TemplateDesigner,"http://" + ShellConfig.Instance.DistHost + "/index.html", dictionary);
+            var parameterStr = "?id="+ templateId +"&name=" +name+"&type="+type+ "&category=0";
+            manager.ShowWindowByTypeAsync(WindowType.TemplateDesigner,"http://" + ShellConfig.Instance.DistHost + parameterStr, dictionary);
             return true;
         }
 
+        /// <summary>
+        /// 保存报告模板
+        /// </summary>
+        /// <param name="templateId"></param>
+        /// <param name="name"></param>
+        /// <param name="useObject"></param>
+        /// <param name="templateJson"></param>
+        public void SaveReportTemplate(string templateId, string name, string useObject, string templateJson) 
+        {
+            var manager = AppManager.Get<ISecondaryScreenManager>();
+            var window =  manager.GetWindowByType(WindowType.Measure);
+            List<String> args = new List<string>();
+            args.Add(templateId);
+            args.Add(name);
+            args.Add(useObject);
+            args.Add(templateJson);
+            if (window != null) 
+            {
+                ExecuteJS("externalNotification", TargetMethodName.SaveReportTemplate, args);
+            }
+        }
+
+        /// <summary>
+        /// 执行Js方法
+        /// </summary>
+        /// <param name="methodName"></param>
+        /// <param name="targetMethodName"></param>
+        /// <param name="arguments"></param>
+        public void ExecuteJS(string methodName, TargetMethodName targetMethodName, List<string> arguments)
+        {
+            string callString = methodName + "(";
+            if (arguments != null)
+            {
+                string comma = ", ";
+                var argumentsStr = "";
+                int index = 0;
+                foreach (var e in arguments)
+                {
+                    if (index == arguments.Count - 1)
+                    {
+                        argumentsStr += e;
+                    }
+                    else
+                    {
+                        argumentsStr += e + "$";
+                    }
+                    index++;
+                }
+                var escaped = System.Web.HttpUtility.JavaScriptStringEncode(argumentsStr, true);
+                callString += (int)targetMethodName + comma + escaped + comma + "";
+            }
+            callString += ");";
+
+            AvaloniaCefBrowserHelper.browser?.ExecuteJavaScript(callString, null, 0);
+        }
+
+
         public LoadVidResult LoadVid(string url)
         {
             var result = new LoadVidResult();

+ 2 - 2
fis/ShellConfig.cs

@@ -14,8 +14,8 @@ namespace fis
         /// <summary>
         /// ±¨¸æÄ£°åÉè¼ÆÆ÷
         /// </summary>
-        public string DistHost { get; set; } = "dist.fis.plus";
-
+        public string DistHost { get; set; } = "2.flyinsono.com/report/#/reportTemplateDesigner";
+        
         //Gets or sets the App resource path, which stores the web content and its resources.
         public string AppResourcePath { get; set; } = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App", "flyinsono");
 

+ 21 - 11
fis/SlaveWindow.axaml.cs

@@ -12,6 +12,7 @@ using System.Threading;
 using System.Runtime.InteropServices;
 using System.Collections.Generic;
 using Xilium.CefGlue.Common.Handlers;
+using fis.Win.Dev.Utilities;
 
 namespace fis
 {
@@ -30,7 +31,7 @@ namespace fis
             ExtendClientAreaTitleBarHeightHint = -1;
             MainThreadSyncContext = SynchronizationContext.Current;
 #if DEBUG
-             this.AttachDevTools();
+            this.AttachDevTools();
 #endif
         }
 
@@ -42,7 +43,8 @@ namespace fis
         internal void ChangeContent(string host, Dictionary<string, string> keyValuePairs)
         {
             var browserContainer = this.FindControl<Border>("BrowserBorder");
-
+            _host = host;
+            _parameters = keyValuePairs;
             var parameter = "";
             var index = 0;
             foreach (var p in _parameters)
@@ -58,6 +60,8 @@ namespace fis
             browserContainer.Child = _browser;
         }
 
+
+
         /// <summary>
         /// 初始化参数和组件
         /// </summary>
@@ -68,7 +72,6 @@ namespace fis
             _parameters = dictionary;
             _host = host;
             InitializeComponent();
-
         }
 
         private void InitializeComponent()
@@ -93,9 +96,10 @@ namespace fis
             {
                 throw new NotSupportedException($"Platform {Environment.OSVersion.Platform} is not suppoorted.");
             }
+   
             if (_host.Contains(ShellConfig.Instance.DistHost))
             {
-                var appHandler = new FileSystemHostHandler(ShellConfig.Instance.DistHost + "/index.html", ShellConfig.Instance.DistResourcePath);
+                var appHandler = new FileSystemHostHandler(ShellConfig.Instance.DistHost , ShellConfig.Instance.DistResourcePath);
                 var handler = new HostRequestHandler();
                 handler.RegisterHostHandler(appHandler);
                 _browser = new AvaloniaCefBrowser
@@ -137,15 +141,9 @@ namespace fis
             _browser.BrowserInitialized += () =>
             {
 #if DEBUG
-               _browser!.ShowDeveloperTools();
+              _browser!.ShowDeveloperTools();
 #endif
             };
-            browserContainer.Child = _browser;
-            WindowStartupLocation = WindowStartupLocation.Manual;
-            Position = new PixelPoint();
-            WindowState = WindowState.Maximized;
-            MinWidth = 1366;
-            MinHeight = 768;
             var language = CultureInfo.CurrentCulture.Name;
             if (_title != null)
             {
@@ -158,6 +156,18 @@ namespace fis
                     _title.Text = "FLYINSONO";
                 }
             }
+            if (_title != null)
+            {
+                var scriptObj = new FisBrowserScriptObject(_title, platformService);
+                _browser.RegisterJavascriptObject(scriptObj, "FisShellApi");
+            }
+            browserContainer.Child = _browser;
+            WindowStartupLocation = WindowStartupLocation.Manual;
+            Position = new PixelPoint();
+            WindowState = WindowState.Maximized;
+            MinWidth = 1366;
+            MinHeight = 768;
+         
             var assembly = Assembly.GetExecutingAssembly();
             Stream? resourceStream = null;
             if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))

+ 22 - 0
fis/Utilities/Entities/ReportTemplate.cs

@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace fis.Win.Dev.Utilities.Entities
+{
+    internal class ReportTemplate
+    {
+   
+
+      public string Token { get; set; }
+
+      public string ReportTemplateCode { get; set; }
+
+      public string ReportTemplateName { get; set; }
+      public string ReportTemplateJson { get; set; }
+
+
+    }
+}

+ 27 - 0
fis/Utilities/Entities/RpcShell.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace fis.Win.Dev.Utilities.Entities
+{
+    internal class RpcShell
+    {
+        ///rpc版本
+        public string jsonrpc { get; set; } = "2.0";
+
+        /// <summary>
+        ///rpc接口名
+        /// </summary>
+        public string method { get; set; }
+      
+        /// <summary>
+        /// 结果Id
+        /// </summary>
+        public string id { get; set; } = "1";
+
+
+        public List<dynamic> param{get;set;}
+    }
+}

+ 7 - 0
fis/Utilities/TargetMethodName.cs

@@ -0,0 +1,7 @@
+namespace fis.Win.Dev.Utilities
+{
+    public enum TargetMethodName
+    {
+        SaveReportTemplate
+    }
+}