Browse Source

添加项目文件。

master
胡超1 1 year ago
parent
commit
1846636e45
  1. 37
      AksWebBrowser.sln
  2. 51
      CPF_Cef/AKS.EnterpriseLibrary.WebBrowser.csproj
  3. 16
      CPF_Cef/AssistEntity.cs
  4. 321
      CPF_Cef/Common/COMUtils.cs
  5. 58
      CPF_Cef/Common/ChunkedUpload.cs
  6. 82
      CPF_Cef/Common/Log.cs
  7. 21
      CPF_Cef/Common/Utils.cs
  8. 77
      CPF_Cef/CusWebBrowser.cs
  9. 202
      CPF_Cef/FrmMain.cs
  10. 1206
      CPF_Cef/MainModel.cs
  11. 25
      CPF_Cef/Parame.cs
  12. 38
      CPF_Cef/Program.cs
  13. BIN
      CPF_Cef/Recent.ico
  14. 51
      CPF_Cef/SetTaskStatus.cs
  15. 473
      CPF_Cef/StyleSheet.css

37
AksWebBrowser.sln

@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34622.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AKS.EnterpriseLibrary.WebBrowser", "CPF_Cef\AKS.EnterpriseLibrary.WebBrowser.csproj", "{76142658-6E83-4A1C-8CC9-C2574865CA7D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{76142658-6E83-4A1C-8CC9-C2574865CA7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76142658-6E83-4A1C-8CC9-C2574865CA7D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76142658-6E83-4A1C-8CC9-C2574865CA7D}.Debug|x64.ActiveCfg = Debug|x64
{76142658-6E83-4A1C-8CC9-C2574865CA7D}.Debug|x64.Build.0 = Debug|x64
{76142658-6E83-4A1C-8CC9-C2574865CA7D}.Debug|x86.ActiveCfg = Debug|x86
{76142658-6E83-4A1C-8CC9-C2574865CA7D}.Debug|x86.Build.0 = Debug|x86
{76142658-6E83-4A1C-8CC9-C2574865CA7D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76142658-6E83-4A1C-8CC9-C2574865CA7D}.Release|Any CPU.Build.0 = Release|Any CPU
{76142658-6E83-4A1C-8CC9-C2574865CA7D}.Release|x64.ActiveCfg = Release|x64
{76142658-6E83-4A1C-8CC9-C2574865CA7D}.Release|x64.Build.0 = Release|x64
{76142658-6E83-4A1C-8CC9-C2574865CA7D}.Release|x86.ActiveCfg = Release|x86
{76142658-6E83-4A1C-8CC9-C2574865CA7D}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BDDA2FFD-1C83-470F-82EE-DE0E448EEB6D}
EndGlobalSection
EndGlobal

51
CPF_Cef/AKS.EnterpriseLibrary.WebBrowser.csproj

@ -0,0 +1,51 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ApplicationIcon>Recent.ico</ApplicationIcon>
<StartupObject />
<AssemblyName>AksWebBrowser</AssemblyName>
<RootNamespace>AksWebBrowser</RootNamespace>
<Platforms>AnyCPU;x64;x86</Platforms>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants />
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants />
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<None Remove="StyleSheet.css" />
</ItemGroup>
<ItemGroup>
<Content Include="Recent.ico" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="StyleSheet.css" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NAudio" Version="2.2.1" />
<PackageReference Include="NAudio.Core" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.IO.Ports" Version="8.0.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="8.0.0" />
<PackageReference Include="Xhm.CPF" Version="0.9.6.7" />
<PackageReference Include="Xhm.CPF.Cef" Version="0.9.6.6" />
<PackageReference Include="Xhm.CPF.Windows" Version="0.9.6.7" />
<PackageReference Include="Xhm.CPF.Skia" Version="0.9.6.7" />
<PackageReference Include="Xhm.CPF.Mac" Version="0.9.6.7" />
<PackageReference Include="Xhm.CPF.Linux" Version="0.9.6.7" />
</ItemGroup>
</Project>

16
CPF_Cef/AssistEntity.cs

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AksWebBrowser
{
public enum LightTypeModel
{
FingerLight,
IDCardLight,
BottomLight,
BurnLight
}
}

321
CPF_Cef/Common/COMUtils.cs

@ -0,0 +1,321 @@
using AKS.EnterpriseLibrary.WebBrowser;
using AksWebBrowser;
using AKSWebBrowser.Commen;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using Timer = System.Timers.Timer;
namespace AKSWebBrowser.Common
{
public class COMUtils
{
private static SerialPort serialPort = new SerialPort();
public string jsonstr = string.Empty;
public string jsontemp = string.Empty;
public int maxCHunkSize = 1024;
public string callback = string.Empty;
public string ml = "COM4";
public COMUtils()
{
OpenCOM();
}
//打开COM口
public void OpenCOM()
{
try
{
//要执行的Linux命令
string[] cmd = LinuxCmdArea("ls /dev");
if (cmd.Length > 0)
{
string parm = string.Empty;
foreach (string line in cmd)
{
if (line.Contains("ttyCH341USB"))
{
parm = line;
break;
}
}
if (!string.IsNullOrEmpty(parm))
{
ml = "/dev/" + parm;
Log.Info("输出结果:" + ml);
//给管理权限
LinuxCmd(ml);
//打开串口
// 设置COM口,波特率,奇偶校验,数据位,停止位
serialPort.PortName = ml; // 请替换为你的串口名称
serialPort.BaudRate = 115200; // 设置波特率
serialPort.Parity = Parity.None;
serialPort.DataBits = 8;
serialPort.StopBits = StopBits.One;
serialPort.Handshake = Handshake.None;
serialPort.DtrEnable = true; //启用控制终端就续信号
//serialPort.ReadTimeout = 18000;
//serialPort.RtsEnable = true; //启用请求发送信号
serialPort.NewLine = "\n";
serialPort.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
if (!serialPort.IsOpen)
{
serialPort.Open();
}
Timer timer = new Timer(3000);//1秒钟的时间间隔
timer.Elapsed += OnTimedEvent;
timer.AutoReset = true;//重复执行
timer.Enabled = true;//启动定时器
Log.Info("浏览器COM服务启动成功");
}
else
{
Log.Info("串口类型不匹配");
}
}
else
{
Log.Info("当前设备没有串口设备");
}
}
catch (Exception ex)
{
Log.Info("服务启动异常ex: " + ex.Message + "");
}
}
//接受数据
public static string bsid = string.Empty;
public static string bsext = string.Empty;
public static string bspath = string.Empty;
public static bool sfjswc = false;
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
try
{
SerialPort sp = (SerialPort)sender;
string _jsonstr = sp.ReadExisting();
if (!string.IsNullOrEmpty(_jsonstr))
{
if (_jsonstr.Contains("\n"))
{
jsonstr = jsontemp + _jsonstr;
//向js发送数据
//CShaseBJavaScript(jsonstr);
//jsontemp = string.Empty;
//jsonstr = string.Empty;
}
else
{
jsontemp = jsontemp + _jsonstr;
}
}
}
catch (Exception ex)
{
Log.Info("接受数据数据异常: " + ex.Message + "");
jsonstr = MainModel.str2Base64("{\"callback\":\"" + this.callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "接受数据数据超时:" + ex.Message + "\"}");
// CShaseBJavaScript(jsonstr);
}
}
//打开串口
private void OnTimedEvent(Object source, ElapsedEventArgs e)
{
try
{
if (!serialPort.IsOpen)
{
serialPort.Open();
}
}
catch (Exception ex)
{
Log.Info("定时任务打开串口异常: " + ex.Message + "");
}
}
//发送数据
public string SendData(string data, string callback)
{
try
{
this.callback = callback;
if (serialPort.IsOpen)
{
jsontemp = string.Empty;
jsonstr = string.Empty;
//写入数据并以换行符结束
serialPort.WriteLine(data);
Log.Info("发送数据成功: " + data + "");
while (string.IsNullOrEmpty(jsonstr))
{
Task.Delay(10).Wait();
}
}
else
{
//重新打开串口
OpenCOM();
if (serialPort.IsOpen)
{
jsontemp = string.Empty;
jsonstr = string.Empty;
//写入数据并以换行符结束
serialPort.WriteLine(data);
Log.Info("发送数据成功: " + data + "");
while (string.IsNullOrEmpty(jsonstr))
{
Task.Delay(10).Wait();
}
}
else
{
jsontemp = string.Empty;
jsonstr = string.Empty;
Log.Info("发送数据失败");
jsonstr = MainModel.str2Base64("{\"callback\":\"" + this.callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "串口未打开" + "\"}");
//CShaseBJavaScript(jsonstr);
}
}
}
catch (Exception ex)
{
jsontemp = string.Empty;
jsonstr = string.Empty;
Log.Info("发送数据异常3: " + ex.Message + "");
jsonstr = MainModel.str2Base64("{\"callback\":\"" + this.callback + "\",\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "发送数据异常:" + ex.Message + "\"}");
//CShaseBJavaScript(jsonstr);
}
return jsonstr;
}
//关闭
public void ClosePort()
{
try
{
if (serialPort.IsOpen)
{
serialPort.Close(); // 关闭串口
}
}
catch (Exception ex)
{
Log.Error("关闭异常: " + ex.Message + "");
}
}
/// <summary>
/// COM接收文件
/// </summary>
public void NewMethod1(SerialPort sp, string path)
{
byte[] buffer = new byte[sp.ReadBufferSize];
int bytesRead = sp.Read(buffer, 0, buffer.Length);
using (FileStream fileStream = new FileStream(path, FileMode.Append))
{
fileStream.Write(buffer, 0, bytesRead);
fileStream.Close();
fileStream.Dispose();
}
}
/// <summary>
/// COM口公共发送文件
/// </summary>
/// <param name="url"></param>
public void NewMethod(string url, string id)
{
string ext = Path.GetExtension(url);
serialPort.WriteLine("Start_" + id + "_" + ext);
// 发送端
byte[] documentBytes = File.ReadAllBytes(url);
serialPort.Write(documentBytes, 0, documentBytes.Length);
serialPort.WriteLine("End");
}
//向js传输数据
public void CShaseBJavaScript(string param)
{
Task.Run(async () =>
{
param = MainModel.Base64str2(param);
Log.Info("返回数据:" + param);
JObject jo = (JObject)JsonConvert.DeserializeObject(param);
bool fieldExists = jo.ContainsKey("callback");
if (fieldExists)
{
string callback = jo["callback"].ToString();
Log.Info("回调js方法:" + callback);
string _parm = callback + "('" + param + "')";
await Parame.webBrowser.ExecuteJavaScript(_parm);
}
else
{
Log.Info("回调js方法为空");
}
});
}
//执行命令
public void LinuxCmd(string command)
{
command = $"echo 'aks@123456' sudo -S chmod 777 {command}";
Log.Info("执行命令:" + command);
// 启动进程
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "/bin/bash",
Arguments = $"-c \"{command}\"",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
}
};
process.Start();
string output = process.StandardOutput.ReadToEnd();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();
Log.Info("执行命令结果返回:" + output);
Log.Info("执行命令错误结果返回:" + error);
}
//执行命令返回数组
public string[] LinuxCmdArea(string command)
{
// 使用ProcessStartInfo设置启动参数
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = "/bin/bash", // 指定bash shell
Arguments = $"-c \"{command}\"", // 要执行的命令
RedirectStandardOutput = true, // 重定向标准输出
UseShellExecute = false, // 不使用系统外壳程序启动
CreateNoWindow = true // 不创建新窗口
};
// 启动进程
using (Process process = Process.Start(startInfo))
{
using (System.IO.StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd(); // 读取全部输出
return result.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); // 转换为字符串数组
}
}
}
}
}

58
CPF_Cef/Common/ChunkedUpload.cs

@ -0,0 +1,58 @@
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using CPF.Controls;
namespace AksWebBrowser.Common
{
public class ChunkedUpload
{
private readonly HttpClient _httpClient;
public ChunkedUpload(HttpClient httpClient)
{
_httpClient = httpClient;
}
public async Task<string> UploadFileAsync(string url, string filePath)
{
string ret = string.Empty;
using (var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
FileInfo fileInfo = new FileInfo(filePath);
int totalParts = 1;
int chunkNumber = 1;
// 读取文件流其实位置
var fileStreamPos = 0;
var uploadUrl = $"{url}?partNumber={chunkNumber}&chunks={totalParts}&size={fileInfo.Length}&start={fileStreamPos}&end={fileInfo.Length}&total={fileInfo.Length}&FileName={Path.GetFileName(filePath)}";
using (var client = new HttpClient())
{
var formData = new MultipartFormDataContent();
formData.Add(new StreamContent(fileStream, (int)fileStream.Length), "file", Path.GetFileName(filePath) + ".partNumber-1");
var response = await client.PostAsync(uploadUrl, formData);
var responseString = await response.Content.ReadAsStringAsync();
fileStream.Close();
fileStream.Dispose();
ret = responseString;
JObject jo = (JObject)JsonConvert.DeserializeObject(ret);
if (Convert.ToBoolean(jo["IsSucceed"].ToString()) == true)
{
string result = jo["result"].ToString();
JObject jo1 = (JObject)JsonConvert.DeserializeObject(result);
ret = jo1["url"].ToString();
}
}
}
return ret;
}
}
}

82
CPF_Cef/Common/Log.cs

@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AKSWebBrowser.Commen
{
public class Log
{
private static StreamWriter streamWriter; //写文件
public static void Error(string message)
{
try
{
//DateTime dt = new DateTime();
string directPath = AppDomain.CurrentDomain.BaseDirectory + @"/logs/error"; //在获得文件夹路径
if (!Directory.Exists(directPath)) //判断文件夹是否存在,如果不存在则创建
{
Directory.CreateDirectory(directPath);
}
directPath += string.Format(@"/{0}.log", DateTime.Now.ToString("yyyy-MM-dd"));
if (streamWriter == null)
{
streamWriter = !File.Exists(directPath) ? File.CreateText(directPath) : File.AppendText(directPath);
}
streamWriter.WriteLine("***********************************************************************");
streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss"));
streamWriter.WriteLine("输出信息:错误信息");
if (message != null)
{
streamWriter.WriteLine("异常信息:\r\n" + message);
}
}
finally
{
if (streamWriter != null)
{
streamWriter.Flush();
streamWriter.Dispose();
streamWriter = null;
}
}
}
public static void Info(string message)
{
try
{
//DateTime dt = new DateTime();
string directPath = AppDomain.CurrentDomain.BaseDirectory + @"/logs/Info"; //在获得文件夹路径
if (!Directory.Exists(directPath)) //判断文件夹是否存在,如果不存在则创建
{
Directory.CreateDirectory(directPath);
}
directPath += string.Format(@"/{0}.log", DateTime.Now.ToString("yyyy-MM-dd"));
if (streamWriter == null)
{
streamWriter = !File.Exists(directPath) ? File.CreateText(directPath) : File.AppendText(directPath);
}
streamWriter.WriteLine("***********************************************************************");
streamWriter.WriteLine(DateTime.Now.ToString("HH:mm:ss"));
streamWriter.WriteLine("输出信息:信息");
if (message != null)
{
streamWriter.WriteLine("信息:\r\n" + message);
}
}
finally
{
if (streamWriter != null)
{
streamWriter.Flush();
streamWriter.Dispose();
streamWriter = null;
}
}
}
}
}

21
CPF_Cef/Common/Utils.cs

@ -0,0 +1,21 @@
using CPF.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AksWebBrowser.Common
{
public class Utils
{
/// <summary>
/// 消息弹框
/// </summary>
/// <param name="mes"></param>
public static void MessagesBox(string mes) {
MessageBox.ShowSync(mes);
}
}
}

77
CPF_Cef/CusWebBrowser.cs

@ -0,0 +1,77 @@
using CPF;
using CPF.Cef;
using CPF.Cef.JSExtenstions;
using CPF.Mac.CoreText;
using CPF.Reflection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text;
using System.Threading.Tasks;
namespace AKS.EnterpriseLibrary.WebBrowser
{
public class CusWebBrowser : CPF.Cef.WebBrowser
{
public CusCefRequestHandler CusRequest = new CusCefRequestHandler();
public CusWebBrowser() { }
protected override CpfCefClient OnCreateWebBrowser(CefBrowserSettings settings)
{
CpfCefClient cefClient = base.OnCreateWebBrowser(settings);
cefClient.RequestHandler = CusRequest;
cefClient.ContextMenuHandler = new MenuHandler();
cefClient.DragHandler = new DragHandler();
return cefClient;
}
}
public class CusCefRequestHandler : CpfCefRequestHandler
{
public delegate void CusResquestDelegate(CefPostData postData, CefRequest request);
public event CusResquestDelegate CusResquestEvent;
public CusCefRequestHandler() { }
protected override CefResourceRequestHandler GetResourceRequestHandler(CefBrowser browser, CefFrame frame, CefRequest request, bool isNavigation, bool isDownload, string requestInitiator, ref bool disableDefaultHandling)
{
CusResquestEvent(request.PostData, request);
return null;
}
}
public class DragHandler : CpfCefDragHandler
{
protected override bool OnDragEnter(CefBrowser browser, CefDragData dragData, CefDragOperationsMask mask)
{
return true;
}
protected override void OnDraggableRegionsChanged(CefBrowser browser, CefFrame frame, CefDraggableRegion[] regions)
{
}
}
public class MenuHandler : CpfCefContextMenuHandler
{
protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model)
{
model.Clear();
}
protected override bool OnContextMenuCommand(CefBrowser browser, CefFrame frame, CefContextMenuParams state, int commandId, CefEventFlags eventFlags)
{
return false;
}
protected override void OnContextMenuDismissed(CefBrowser browser, CefFrame frame)
{
}
protected override bool RunContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams parameters, CefMenuModel model, CefRunContextMenuCallback callback)
{
return false;
}
}
}

202
CPF_Cef/FrmMain.cs

@ -0,0 +1,202 @@
using AksWebBrowser;
using CPF;
using CPF.Cef;
using CPF.Controls;
using CPF.Platform;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System;
using System.IO;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using AKSWebBrowser.Commen;
using System.Collections.Generic;
using System.Reflection.Metadata;
using AksWebBrowser.Common;
namespace AKS.EnterpriseLibrary.WebBrowser
{
public class FrmMain : Window
{
protected override void InitializeComponent()
{
LoadStyleFile("res://AksWebBrowser/StyleSheet.css");
//加载样式文件,文件需要设置为内嵌资源
Title = "控申业务专用浏览器";
CanResize = false;
ShowInTaskbar = true;
WindowState = WindowState.Maximized;
Children.Add(
new Border
{
Width = "100%",
Height = "100%",
Child = new Panel
{
Size = SizeField.Fill,
Children =
{
new CusWebBrowser
{
PresenterFor = this,
Name = nameof(Parame.webBrowser),
Bindings =
{
{
nameof(CusWebBrowser.Title),
"Title",
this,
BindingMode.OneWayToSource
},
},
MarginTop=0,
MarginLeft=0,
MarginRight=0,
MarginBottom=0,
},
}
}
}
);
}
private TextBox textBox;
protected override async void OnInitialized()
{
//窗体大小
this.Width = 1080;
this.Height = 1920;
//SetTaskStatus.Hidetask();
base.OnInitialized();
Parame.webBrowser = FindPresenterByName<CusWebBrowser>(nameof(Parame.webBrowser));
textBox = FindPresenterByName<TextBox>(nameof(textBox));
Parame.webBrowser.CusRequest.CusResquestEvent += CusRequest_CusResquestEvent;
//浏览器大小
Parame.webBrowser.Width = 1080;
Parame.webBrowser.Height = 1920;
Parame.webBrowser.Url = "http://192.168.0.34:8078/#/main-out";
//Parame.webBrowser.Url = Application.StartupPath + @"\html\index.html";
//开发者工具暂时只能支持Windows
//webBrowser.ShowDev();
//SetTaskStatus.Showtask();
Parame.webBrowser.LoadEnd += WebBrowser_LoadEnd;
this.Closing += MainWindow_Closing;
}
//关闭事件
private void MainWindow_Closing(object sender, ClosingEventArgs e)
{
new MainModel().CLoseCOM();
MainModel.KillProcessByName("AksWebBrowser");
}
bool showDev = false;
private void WebBrowser_LoadEnd(object sender, LoadEndEventArgs e)
{
if (!showDev)
{
showDev = true;
Parame.webBrowser.ShowDev();
}
//获取授权
GetSQObject();
}
public void Writelog(string str, string dirName = @"logs")
{
try
{
if (string.IsNullOrEmpty(str)) return;
var baseDir = AppDomain.CurrentDomain.BaseDirectory + dirName;
if (!Directory.Exists(baseDir))
{
Directory.CreateDirectory(baseDir);
}
string filePath = System.IO.Path.Combine(baseDir, DateTime.Now.ToString("yyyy-MM-dd") + "_log.txt");
using (StreamWriter sw = File.AppendText(filePath))
{
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "[" + str + "]" + "\r\n");
sw.Flush();
}
}
catch { }
}
private void CusRequest_CusResquestEvent(CefPostData postData, CefRequest request)
{
string postParams = string.Empty;
if (postData != null)
{
//取提交的参数
CefPostData cefPostData = postData;
var elements = cefPostData.GetElements();
foreach (var element in elements)
{
if (element.ElementType == CefPostDataElementType.Bytes)
{
var bytes = element.GetBytes();
postParams = Encoding.UTF8.GetString(bytes);
Console.WriteLine("请求参数:" + postParams);
}
}
}
Console.WriteLine("请求地址:" + request.Url.ToString());
}
//调用JS内的JS方法
async void InvokeJS(CpfObject obj, RoutedEventArgs eventArgs)
{
var r = await Parame.webBrowser.ExecuteJavaScript("callback('调用绑定到JS里的C#方法')");
}
/// <summary>
/// 或者可以用授权接口
/// </summary>
public void GetSQObject()
{
Task.Run(async () =>
{
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, $"{Parame.apiUrl}/api/Interface/Getlist?Ytjbm={Parame.key}");
var response = await client.SendAsync(request);
List<Func> list = new List<Func>();
if (response.StatusCode.ToString() == "200")
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
JObject jo = (JObject)JsonConvert.DeserializeObject(body);
if (jo["IsSucceed"].ToString() == "True")
{
string result = jo["result"].ToString();
if (!string.IsNullOrEmpty("result"))
{
JArray array = (JArray)JsonConvert.DeserializeObject(result);
foreach (JObject item in array)
{
Func func = new Func()
{
Id = item["Id"].ToString(),
Platform = item["Platform"].ToString(),
Interfaceaddress = item["Interfaceaddress"].ToString(),
};
list.Add(func);
}
}
else
{
Log.Info("未获取授权");
Utils.MessagesBox("未获取授权");
}
}
else
{
Log.Info("未获取授权");
Utils.MessagesBox("未获取授权");
}
}
Parame.FuncObject = list;
});
}
}
}

1206
CPF_Cef/MainModel.cs

File diff suppressed because it is too large Load Diff

25
CPF_Cef/Parame.cs

@ -0,0 +1,25 @@
using AKS.EnterpriseLibrary.WebBrowser;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AksWebBrowser
{
public class Parame
{
public static CusWebBrowser webBrowser { get; set; }
public static List<Func> FuncObject { get; set; }
//接口地址
public static string apiUrl = "http://192.168.0.34:92";
//授权key
public static string key = "1";
}
public struct Func
{
public string Id { get; set; }
public string Platform { get; set; }
public string Interfaceaddress { get; set; }
};
}

38
CPF_Cef/Program.cs

@ -0,0 +1,38 @@
using CPF.Cef;
using CPF.Linux;//如果需要支持Linux才需要
using CPF.Mac;//如果需要支持Mac才需要
using CPF.Platform;
using CPF.Skia;
using CPF.Windows;
using System;
namespace AKS.EnterpriseLibrary.WebBrowser
{
class Program
{
[STAThread]
static void Main(string[] args)
{
Application.Initialize(
(OperatingSystemType.Windows, new WindowsPlatform(), new SkiaDrawingFactory())
, (OperatingSystemType.OSX, new MacPlatform(), new SkiaDrawingFactory())//如果需要支持Mac才需要
, (OperatingSystemType.Linux, new LinuxPlatform(), new SkiaDrawingFactory())//如果需要支持Linux才需要
);
CefRuntime.Load();
var mainArgs = new CpfCefMainArgs(args);
var app = new CpfCefApp();
var exitCode = CefRuntime.ExecuteProcess(mainArgs, app, IntPtr.Zero);
if (exitCode != -1)
{
return;
}
CefRuntime.Initialize(mainArgs, new CefSettings{ }, app, IntPtr.Zero);
var model = new MainModel();
Application.Run(new FrmMain { DataContext = model, CommandContext = model });
CefRuntime.Shutdown();
}
}
}

BIN
CPF_Cef/Recent.ico

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

51
CPF_Cef/SetTaskStatus.cs

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace AksWebBrowser
{
public class SetTaskStatus
{
private const int SW_HIDE = 0; //隐藏任务栏
private const int SW_RESTORE = 9;//显示任务栏
[DllImport("user32.dll")]
private static extern int ShowWindow(int hwnd, int nCmdShow);
[DllImport("user32.dll")]
private static extern int FindWindow(string lpClassName, string lpWindowName);
/// <summary>
/// 显示任务栏
/// </summary>
public static void Showtask()
{
ShowWindow(FindWindow("Shell_TrayWnd", null), SW_RESTORE);
}
/// <summary>
/// 隐藏任务栏
/// </summary>
public static void Hidetask()
{
ShowWindow(FindWindow("Shell_TrayWnd", null), SW_HIDE);
}
// 设置窗体的显示状态
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
int X, int Y, int cx, int cy, uint uFlags);
// 窗体的句柄
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
public const uint SWP_SHOWWINDOW = 0x0040;
public const uint SWP_NOSIZE = 0x0001;
public const uint SWP_NOMOVE = 0x0002;
public const uint TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW;
}
}

473
CPF_Cef/StyleSheet.css

@ -0,0 +1,473 @@

@media windows {
* {
FontFamily: '微软雅黑'; /*不同系统的字体不同,自己根据情况改或者使用内嵌字体*/
}
}
@media osx {
* {
FontFamily: '苹方-简';
}
}
@media linux {
* {
FontFamily: '文泉驿正黑';
}
}
/*设置窗体标题栏背景颜色圆角*/
/*#caption {
IsAntiAlias: true;
Background: #2c2c2c;
CornerRadius:5,5,0,0;
}
#frame {
CornerRadius: 5;
IsAntiAlias: true;
}*/
Button {
BorderFill: #DCDFE6;
IsAntiAlias: True;
CornerRadius: 4,4,4,4;
Background: #FFFFFF;
}
Button[IsMouseOver=true] {
BorderFill: rgb(198,226,255);
Background: rgb(236,245,255);
Foreground: rgb(64,158,255);
}
Button[IsPressed=true] {
BorderFill: rgb(58,142,230);
}
Button.primary {
BorderFill: rgb(64,158,255);
CornerRadius: 4,4,4,4;
Background: rgb(64,158,255);
Foreground: #FFFFFF;
}
Button.primary[IsMouseOver=true] {
BorderFill: rgb(102,177,255);
Background: rgb(102,177,255);
Foreground: #FFFFFF;
}
Button.primary[IsPressed=true] {
BorderFill: rgb(58,142,230);
Background: rgb(58,142,230);
}
Button.success {
BorderFill: rgb(103,194,58);
CornerRadius: 4,4,4,4;
Background: rgb(103,194,58);
Foreground: #FFFFFF;
}
Button.success[IsMouseOver=true] {
BorderFill: rgb(133,206,97);
Background: rgb(133,206,97);
Foreground: #FFFFFF;
}
Button.success[IsPressed=true] {
BorderFill: rgb(93,175,52);
Background: rgb(93,175,52);
}
Button.danger {
BorderFill: rgb(245,108,108);
Background: rgb(245,108,108);
CornerRadius: 4,4,4,4;
Foreground: #FFFFFF;
}
Button.danger[IsMouseOver=true] {
BorderFill: rgb(247,137,137);
Background: rgb(247,137,137);
Foreground: #FFFFFF;
}
Button.danger[IsPressed=true] {
BorderFill: rgb(221,97,97);
Background: rgb(221,97,97);
}
TextBox, .textBox, DatePicker {
Background: #fff;
IsAntiAlias: true;
BorderFill: #DCDFE6;
CornerRadius: 4,4,4,4;
BorderStroke: 1;
}
.groupPanel TextBox, DatePicker TextBox, .textBox TextBox {
BorderStroke: 0;
}
.textBox[IsKeyboardFocusWithin=true] {
BorderFill: #1E9FFF;
}
.singleLine { /*单行文本框*/
AcceptsReturn: false;
HScrollBarVisibility: Hidden;
VScrollBarVisibility: Hidden;
}
.singleLine #contentPresenter {
Padding: 3;
}
.multiline { /*多行文本框*/
}
.slotLeft {
CornerRadius: 0,4,4,0;
BorderFill: #DCDFE6;
Background: #F5F7FA;
BorderThickness: 1,0,0,0;
BorderType: BorderThickness;
MarginTop: 0;
MarginBottom: 0;
MarginRight: 0;
}
RadioButton #radioButtonBorder {
StrokeFill: rgb(220,223,230);
}
RadioButton[IsChecked=true] #radioButtonBorder {
StrokeFill: #1E9FFF;
Fill: #1E9FFF;
}
RadioButton #optionMark {
StrokeFill: #1E9FFF;
Fill: #fff;
}
CheckBox #indeterminateMark {
Fill: #1E9FFF;
}
CheckBox #checkBoxBorder {
Background: #fff;
BorderFill: rgb(220,223,230);
}
CheckBox[IsChecked=true] #checkBoxBorder {
Background: #1E9FFF;
BorderFill: #1E9FFF;
}
CheckBox Polyline {
StrokeFill: #fff;
}
.radioGroup {
BorderType: BorderThickness;
BorderFill: rgb(220,223,230);
BorderThickness: 1,1,0,1;
}
.radioGroup RadioButton {
BorderType: BorderThickness;
BorderFill: rgb(220,223,230);
BorderThickness: 0,0,1,0;
}
.radioGroup RadioButton #markPanel {
Visibility: Collapsed;
}
.radioGroup RadioButton TextBlock {
Margin: 5;
}
.radioGroup RadioButton[IsChecked=true] {
Background: rgb(64,158,255);
Foreground: #fff;
}
.error {
Foreground: #f00;
Visibility: Collapsed;
}
.error[DesignMode=true] {
Visibility: Visible;
}
.twoLine[AttachedExtenstions.IsError=true] .error {
Visibility: Visible;
}
.twoLine[AttachedExtenstions.IsError=true] .textBox {
BorderFill: #f00;
}
ScrollBar {
Background: null;
}
ScrollBar Thumb {
IsAntiAlias: true;
CornerRadius: 5;
}
ScrollBar[Orientation=Horizontal] {
Height: 12;
}
ScrollBar[Orientation=Vertical] {
Width: 12;
}
ScrollBar #PART_LineUpButton, ScrollBar #PART_LineDownButton {
Visibility: Collapsed;
}
ComboBox {
Background: #fff;
IsAntiAlias: true;
BorderFill: #DCDFE6;
CornerRadius: 4,4,4,4;
BorderStroke: 1;
}
ComboBox[IsKeyboardFocusWithin=true] {
BorderFill: #1E9FFF;
}
#DropDownPanel TextBlock {
MarginLeft: 5;
MarginTop: 2;
MarginBottom: 2;
font-size: 14;
}
#dropDownBorder {
ShadowBlur: 2;
ShadowColor: rgba(0, 0, 0, 0.4);
BorderStroke: 0;
}
#DropDownPanel[IsMouseOver=false] ScrollBar {
Visibility: Collapsed;
}
#DropDownPanel ScrollBar[Orientation=Horizontal] {
Height: 10;
}
#DropDownPanel ScrollBar[Orientation=Vertical] {
Width: 10;
}
Slider {
IsAntiAlias: true;
}
Slider Thumb {
IsAntiAlias: true;
Width: 16;
Height: 16;
CornerRadius: 7;
BorderFill: rgb(64,158,255);
BorderStroke: 2;
Background: #fff;
ZIndex: 1;
}
Slider Thumb[IsMouseOver=true] {
animation-name: sliderMouseOver;
animation-duration: 0.1s;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
Slider #TrackBackground {
CornerRadius: 2;
Background: rgb(228,231,237);
BorderStroke: 0;
}
Slider #decreaseRepeatButton {
Background: rgb(64,158,255);
CornerRadius: 2;
}
Slider[Orientation=Horizontal] #decreaseRepeatButton {
Height: 4;
MarginLeft: 5;
}
Slider[Orientation=Vertical] #decreaseRepeatButton {
Width: 4;
MarginBottom: 5;
}
ProgressBar {
CornerRadius: 5;
IsAntiAlias: true;
BorderFill: null;
Background: rgb(235,238,245);
}
ProgressBar #Indicator, ProgressBar #Animation {
CornerRadius: 5;
}
NumericUpDown {
Background: #fff;
IsAntiAlias: true;
BorderFill: #DCDFE6;
CornerRadius: 4,4,4,4;
BorderStroke: 1;
}
NumericUpDown RepeatButton {
Width: 20;
Background: rgb(245,247,250);
}
NumericUpDown #decreaseBtn {
CornerRadius: 4,0,0,4;
}
NumericUpDown #increaseBtn {
CornerRadius: 0,4,4,0;
}
NumericUpDown #textBoxBorder {
BorderFill: #DCDFE6;
}
NumericUpDown TextBox {
BorderStroke: 0;
}
.widget {
IsAntiAlias: true;
BorderFill: #DCDFE6;
CornerRadius: 4,4,4,4;
BorderStroke: 1;
}
.widgetHead {
Background: linear-gradient(0 0,0 100%,#F7F7F7 0,#F0F0F0 1);
BorderType: BorderThickness;
BorderThickness: 0,0,0,1;
BorderFill: #DCDFE6;
}
DataGrid {
Foreground: #7a7a7a;
}
DataGridCellTemplate, DataGridRow, DataGrid, .DataGridCell {
BorderFill: rgb(235,238,245);
}
DataGridRow {
Height: 36;
}
DataGridRow[IsMouseOver=true] {
Background: rgb(245,247,250);
}
DataGridRow[IsSelected=true] {
Background: rgb(245,247,250);
}
DataGridColumnTemplate {
Height: 38;
FontSize: 15;
FontStyle: Bold;
Background: #fff;
BorderFill: rgb(235,238,245);
}
TabControl #headBorder {
Background: #fff;
}
TabItem > Border {
BorderThickness: 0,0,0,2;
}
TabItem[IsSelected=true] > Border {
BorderFill: #1E9FFF;
}
TabItem[IsSelected=true] {
Foreground: #1E9FFF;
}
TabControl[TabStripPlacement=Left] TabItem, TabControl[TabStripPlacement=Right] TabItem {
Width: 100%;
BorderType: BorderThickness;
BorderThickness: 0,0,0,1;
BorderFill: #e8e8e8;
}
TabControl[TabStripPlacement=Left] TabItem TextBlock {
MarginRight: 0;
}
TabControl[TabStripPlacement=Left] TabItem > Border {
Width: 100%;
}
TabControl[TabStripPlacement=Left] #headerPanel, TabControl[TabStripPlacement=Right] #headerPanel {
Width: 100;
Background: rgb(245,247,250);
}
.closeBtn[IsMouseOver=true] {
Fill: #171717;
}
.placeholder {
IsHitTestVisible: false;
Foreground: "192,196,204";
Visibility: Collapsed;
}
.textBox[AttachedExtenstions.IsEmpty=true] .placeholder {
Visibility: Visible;
}
.loginBox TextBox, .loginBox .placeholder {
FontSize: 16;
}
.loginBox CheckBox {
Foreground: #757575;
}
.searchBox Button {
CornerRadius: 0,4,4,0,
}
#MenuPop #menuPanel > Border, #MenuPop ContextMenu > Border {
Background: #fff;
ShadowColor: rgba(0, 0, 0, 0.4);
}
#MenuPop MenuItem[IsMouseOver=true] {
Background: #DCDFE6;
}
ListBoxItem {
Width: 100%;
}
Loading…
Cancel
Save