|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Web.WebView2.Core;
|
|
|
|
using Microsoft.Web.WebView2.Wpf;
|
|
|
|
using System;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Windows;
|
|
|
|
using io = System.IO;
|
|
|
|
|
|
|
|
namespace BBWY.Client.Views.Order
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// GrabJDMibole.xaml 的交互逻辑
|
|
|
|
/// </summary>
|
|
|
|
public partial class GrabJDMibole : Window
|
|
|
|
{
|
|
|
|
private WebView2Manager w2m;
|
|
|
|
//private Stopwatch sw;
|
|
|
|
private string orderId;
|
|
|
|
|
|
|
|
public GrabJDMibole(string orderId)
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
this.orderId = orderId;
|
|
|
|
this.Loaded += GrabJDMibole_Loaded;
|
|
|
|
this.Unloaded += GrabJDMibole_Unloaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void GrabJDMibole_Unloaded(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
grid.Children.Remove(w2m.wb2);
|
|
|
|
w2m = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void GrabJDMibole_Loaded(object sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
var sp = (App.Current as App).ServiceProvider;
|
|
|
|
using (var s = sp.CreateScope())
|
|
|
|
{
|
|
|
|
w2m = s.ServiceProvider.GetRequiredService<WebView2Manager>();
|
|
|
|
}
|
|
|
|
grid.Children.Add(w2m.wb2);
|
|
|
|
|
|
|
|
w2m.CoreWebView2InitializationCompleted = (e) =>
|
|
|
|
{
|
|
|
|
w2m.wb2.CoreWebView2.Navigate($"https://neworder.shop.jd.com/order/orderDetail?orderId={orderId}");
|
|
|
|
};
|
|
|
|
w2m.OnNavigationCompleted = async (e) =>
|
|
|
|
{
|
|
|
|
if (w2m.wb2.CoreWebView2.Source.StartsWith("https://passport.shop.jd.com/login"))
|
|
|
|
{
|
|
|
|
//首次打开需要登录
|
|
|
|
await w2m.wb2.CoreWebView2.ExecuteScriptAsync("window.scrollTo(790,150)");
|
|
|
|
await w2m.wb2.CoreWebView2.ExecuteScriptAsync("document.querySelector(\"div[data-tab-id='form']\").click()");
|
|
|
|
}
|
|
|
|
else if (w2m.wb2.CoreWebView2.Source.StartsWith("https://neworder.shop.jd.com/order/orderDetail"))
|
|
|
|
{
|
|
|
|
//进入订单详情页面,触发点击查看手机号
|
|
|
|
var js = @"var mobileNode = document.getElementById('mobile');
|
|
|
|
mobileNode.addEventListener('DOMNodeInserted',function(e){ var m=mobileNode.innerText; window.chrome.webview.postMessage(m);});
|
|
|
|
document.getElementById('viewOrderMobile').click();";
|
|
|
|
_ = await w2m.wb2.CoreWebView2.ExecuteScriptAsync(js);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
w2m.OnWebMessageReceived = (e) =>
|
|
|
|
{
|
|
|
|
var mobole = e.TryGetWebMessageAsString();
|
|
|
|
this.Tag = mobole;
|
|
|
|
this.DialogResult = true;
|
|
|
|
this.Close();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|