From 9b14713fb3ade1ba1cde68993054e8c8a9a9c064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=C2=B7=C3=A6?= <279202647@qq.com> Date: Thu, 21 Oct 2021 12:03:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E7=9B=B8=E9=97=9C=E6=B7=98?= =?UTF-8?q?=E5=AE=9D=E7=95=8C=E9=9D=A2=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserControls/BrowerControl.xaml.cs | 103 +++++++++++++++--- 1 file changed, 85 insertions(+), 18 deletions(-) diff --git a/客户端/齐越慧眼/齐越慧眼/UserControls/BrowerControl.xaml.cs b/客户端/齐越慧眼/齐越慧眼/UserControls/BrowerControl.xaml.cs index 01c7966..13c1155 100644 --- a/客户端/齐越慧眼/齐越慧眼/UserControls/BrowerControl.xaml.cs +++ b/客户端/齐越慧眼/齐越慧眼/UserControls/BrowerControl.xaml.cs @@ -1,19 +1,9 @@ using CefSharp; using CefSharp.Wpf; -using System; -using System.Collections.Generic; -using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace 齐越慧眼.UserControls { @@ -25,8 +15,8 @@ namespace 齐越慧眼.UserControls ChromiumWebBrowser web; public BrowerControl() { - InitializeComponent(); - + InitializeComponent(); + web = new ChromiumWebBrowser("https://www.taobao.com") { BrowserSettings = @@ -43,6 +33,11 @@ namespace 齐越慧眼.UserControls grid.Children.Add(web); Loaded += BrowerControl_Loaded; + + web.JavascriptObjectRepository.Settings.LegacyBindingEnabled = true; + + web.JavascriptObjectRepository.Settings.LegacyBindingEnabled = true; + web.JavascriptObjectRepository.Register("hyCoreModel", new CefAsyncJS(), BindingOptions.DefaultBinder); } @@ -120,12 +115,32 @@ namespace 齐越慧眼.UserControls /// private bool AddOptionDiv() { + ///添加js事件 + DoJavaScript(@" + window.optClick= function (ele,type){ + var itemid= $(ele).parent().parent().find(""a"").attr(""data-nid""); + var infoDiv=$($(ele).parent().parent().parent().parent().find("".J_IconMoreNew"")); + var price=infoDiv.find("".g_price"").text(); + var sales=infoDiv.find("".deal-cnt"").text(); + var title=infoDiv.find("".title"").text(); + var img=$(ele).parent().parent().find(""img"").attr(""src""); + hyCoreModel.setItemData(price+""\r\n""+sales+""\r\n""+title+""\r\n""+img+""\r\n""+itemid); + }; - DoJavaScript("$('div#mainsrp-itemlist .items .item .pic').before('
我擦
')"); + "); - ///添加css - return DoJavaScript(@"$('head').append('')".Replace("\n","").Replace("\r\n","")); + + .bgGreen + { + background: rgba(99, 161, 3, 0.8); + } + .bgPig + { + background: rgba(236, 128, 141, 0.8); + } + .bgZs + { + background: rgba(194, 128, 255, 0.8); + } + .bgYellow + { + background: rgba(245, 154, 35, 0.8); + font-size:20px; + color:red; + display: flex; + align-items: center; + justify-content: center; + flex-direction: column; + float: right; + font-family: ""global-iconfont""; + font-weight: 999; + } + ')".Replace("\n", "").Replace("\r\n", "")); } - + /// /// 执行js @@ -188,7 +241,7 @@ namespace 齐越慧眼.UserControls /// private bool DoJavaScript(string js) { - js = js.Replace("\n", "").Replace("\r\n", "").Replace(System.Environment.NewLine,"").Replace("\r",""); + js = js.Replace("\n", "").Replace("\r\n", "").Replace(System.Environment.NewLine, "").Replace("\r", ""); Task task = null; Application.Current.Dispatcher.Invoke(() => @@ -202,4 +255,18 @@ namespace 齐越慧眼.UserControls return result.Success; } } + + public class CefAsyncJS + { + + public string getTest() + { + return "我草"; + } + public void setItemData(string data) + { + MessageBox.Show(data); + } + + } }