4 changed files with 70 additions and 3 deletions
@ -0,0 +1,13 @@ |
|||||
|
<Page x:Class="BBWY.Client.Views.Web.Web" |
||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||
|
xmlns:local="clr-namespace:BBWY.Client.Views.Web" |
||||
|
mc:Ignorable="d" |
||||
|
d:DesignHeight="450" d:DesignWidth="800" |
||||
|
Title="Web"> |
||||
|
<Grid x:Name="grid"> |
||||
|
|
||||
|
</Grid> |
||||
|
</Page> |
@ -0,0 +1,54 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using System.Windows.Controls; |
||||
|
|
||||
|
namespace BBWY.Client.Views.Web |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Web.xaml 的交互逻辑
|
||||
|
/// </summary>
|
||||
|
public partial class Web : Page |
||||
|
{ |
||||
|
private WebView2Manager w2m; |
||||
|
private GlobalContext globalContext; |
||||
|
private bool isNavigated = false; |
||||
|
|
||||
|
#if DEBUG
|
||||
|
private string url = "http://192.168.1.4:8881/"; |
||||
|
#else
|
||||
|
private string url= "http://bbwyweb.qiyue666.com"; |
||||
|
#endif
|
||||
|
|
||||
|
public Web() |
||||
|
{ |
||||
|
InitializeComponent(); |
||||
|
this.Loaded += Web_Loaded; |
||||
|
} |
||||
|
|
||||
|
private void Web_Loaded(object sender, System.Windows.RoutedEventArgs e) |
||||
|
{ |
||||
|
var sp = (App.Current as App).ServiceProvider; |
||||
|
using (var s = sp.CreateScope()) |
||||
|
{ |
||||
|
globalContext = s.ServiceProvider.GetRequiredService<GlobalContext>(); |
||||
|
} |
||||
|
using (var s = sp.CreateScope()) |
||||
|
{ |
||||
|
w2m = s.ServiceProvider.GetRequiredService<WebView2Manager>(); |
||||
|
} |
||||
|
w2m.Init(globalContext.User.Shop.ShopId.ToString()); |
||||
|
grid.Children.Add(w2m.wb2); |
||||
|
|
||||
|
w2m.CoreWebView2InitializationCompleted = (e) => |
||||
|
{ |
||||
|
isNavigated = true; |
||||
|
// w2m.wb2.CoreWebView2.Navigate($"https://neworder.shop.jd.com/order/orderDetail?orderId={orderId}");
|
||||
|
w2m.wb2.CoreWebView2.Navigate(url); |
||||
|
}; |
||||
|
if(w2m.IsInitializationCompleted && !isNavigated) |
||||
|
{ |
||||
|
w2m.wb2.CoreWebView2.Navigate(url); |
||||
|
isNavigated = true; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue