|
@@ -0,0 +1,125 @@
|
|
|
+using Avalonia.Controls;
|
|
|
+using Avalonia.Threading;
|
|
|
+using fis.Log;
|
|
|
+using fis.Managers;
|
|
|
+using fis.Win.Dev.Helpers;
|
|
|
+using fis.Win.Dev.Managers.Interfaces;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Text;
|
|
|
+using System.Threading;
|
|
|
+using System.Threading.Tasks;
|
|
|
+
|
|
|
+namespace fis.Win.Dev.Utilities
|
|
|
+{
|
|
|
+ internal class FisBrowserScriptObject
|
|
|
+ {
|
|
|
+ IPlatformService _platformService;
|
|
|
+ TextBlock _title;
|
|
|
+ internal FisBrowserScriptObject(TextBlock title, IPlatformService platformService)
|
|
|
+ {
|
|
|
+ _title = title;
|
|
|
+ _platformService = platformService;
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 获取平台名
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ public string GetPlatformName() => _platformService.GetPlatformName();
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 写日志
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="message"></param>
|
|
|
+ /// <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>
|
|
|
+ /// <param name="title">标题</param>
|
|
|
+ public void SetTitle(string title)
|
|
|
+ {
|
|
|
+ MainWindow.MainThreadSyncContext?.Send(new SendOrPostCallback((args) =>
|
|
|
+ {
|
|
|
+ if (_title != null)
|
|
|
+ {
|
|
|
+ _title.Text = title;
|
|
|
+ }
|
|
|
+ }), this);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void CloseWindow(WindowType windowType)
|
|
|
+ {
|
|
|
+ var manager = AppManager.Get<ISecondaryScreenManager>();
|
|
|
+ Dispatcher.UIThread.InvokeAsync(() =>
|
|
|
+ {
|
|
|
+ var slaveWindow = manager.GetWindowByType(windowType);
|
|
|
+ slaveWindow?.Close();
|
|
|
+
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ public void RefershReports()
|
|
|
+ {
|
|
|
+ CloseWindow(WindowType.ReportEdit);
|
|
|
+ ExecuteJS("externalNotification",TargetMethodName.RefershReports, new List<string>());
|
|
|
+ }
|
|
|
+
|
|
|
+ public int Age { get; set; }
|
|
|
+ }
|
|
|
+}
|