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);
+ }
+
+ }
}