Browse Source

自动获取手机号

qianyi
shanji 3 years ago
parent
commit
ebb81529d0
  1. 1
      BBWY.Client/ViewModels/Order/OrderListViewModel.cs
  2. 5
      BBWY.Client/Views/Order/GrabJDMibole.xaml
  3. 16
      BBWY.Client/Views/Order/GrabJDMibole.xaml.cs
  4. 15
      BBWY.Client/WebView2Manager.cs

1
BBWY.Client/ViewModels/Order/OrderListViewModel.cs

@ -251,7 +251,6 @@ namespace BBWY.Client.ViewModels
var grab = new GrabJDMibole(order.Id);
if (grab.ShowDialog() == true)
plaintextMobile = grab.Tag.ToString();
return;
IsLoading = true;
Task.Factory.StartNew(() => orderService.DecodeConsignee(order.Id, plaintextMobile)).ContinueWith(t =>
{

5
BBWY.Client/Views/Order/GrabJDMibole.xaml

@ -8,9 +8,6 @@
WindowStartupLocation="CenterScreen"
Title="GrabJDMibole" Height="350" Width="400">
<Grid x:Name="grid">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<TextBlock x:Name="txtMsg" Text="Initialize Webview2" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="16"/>
</Grid>
</Window>

16
BBWY.Client/Views/Order/GrabJDMibole.xaml.cs

@ -4,6 +4,8 @@ using Microsoft.Web.WebView2.Wpf;
using System;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using io = System.IO;
namespace BBWY.Client.Views.Order
@ -16,6 +18,7 @@ namespace BBWY.Client.Views.Order
private WebView2Manager w2m;
//private Stopwatch sw;
private string orderId;
private bool isNavigated;
public GrabJDMibole(string orderId)
{
@ -40,8 +43,12 @@ namespace BBWY.Client.Views.Order
}
grid.Children.Add(w2m.wb2);
if(w2m.IsInitializationCompleted)
txtMsg.Text = "Grabbing Mobile";
w2m.CoreWebView2InitializationCompleted = (e) =>
{
isNavigated = true;
w2m.wb2.CoreWebView2.Navigate($"https://neworder.shop.jd.com/order/orderDetail?orderId={orderId}");
};
w2m.OnNavigationCompleted = async (e) =>
@ -55,6 +62,9 @@ namespace BBWY.Client.Views.Order
else if (w2m.wb2.CoreWebView2.Source.StartsWith("https://neworder.shop.jd.com/order/orderDetail"))
{
//进入订单详情页面,触发点击查看手机号
txtMsg.Text = "Grabbing Mobile";
w2m.wb2.Width = 0.1;
w2m.wb2.Height = 0.1;
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();";
@ -68,6 +78,12 @@ namespace BBWY.Client.Views.Order
this.DialogResult = true;
this.Close();
};
if (w2m.IsInitializationCompleted && !isNavigated)
{
w2m.wb2.CoreWebView2.Navigate($"https://neworder.shop.jd.com/order/orderDetail?orderId={orderId}");
isNavigated = true;
}
}
}
}

15
BBWY.Client/WebView2Manager.cs

@ -2,6 +2,7 @@
using Microsoft.Web.WebView2.Core;
using Microsoft.Web.WebView2.Wpf;
using System;
using System.Diagnostics;
using System.Reflection;
using io = System.IO;
@ -39,11 +40,10 @@ namespace BBWY.Client
private void Wb2_CoreWebView2InitializationCompleted(object sender, CoreWebView2InitializationCompletedEventArgs e)
{
isInitializationCompleted = true;
CoreWebView2InitializationCompleted?.Invoke(e);
isInitializationCompleted = true;
}
public void Close()
{
if (wb2 != null && wb2.CoreWebView2 != null)
@ -54,16 +54,13 @@ namespace BBWY.Client
var udf = wb2.CoreWebView2.Environment.UserDataFolder;
var wb2ProcessId = wb2.CoreWebView2.BrowserProcessId;
wb2.Dispose();
int timeout = 10;
try
{
while (System.Diagnostics.Process.GetProcessById(Convert.ToInt32(wb2ProcessId)) != null && timeout < 2000)
{
System.Threading.Thread.Sleep(10);
timeout += 10;
}
var wb2Process = Process.GetProcessById(Convert.ToInt32(wb2ProcessId));
if (wb2Process != null)
wb2Process.Kill();
}
catch { }
catch (Exception ex) { Console.WriteLine(ex.Message); }
io.Directory.Delete(udf, true);
}
}

Loading…
Cancel
Save