5 changed files with 107 additions and 13 deletions
@ -0,0 +1,14 @@ |
|||||
|
<Page x:Class="BBWYB.Client.Views.WebB.WebB_KPI" |
||||
|
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:BBWYB.Client.Views.WebB" |
||||
|
mc:Ignorable="d" |
||||
|
d:DesignHeight="450" d:DesignWidth="800" |
||||
|
Title="WebB_KPI"> |
||||
|
|
||||
|
<Grid x:Name="grid"> |
||||
|
|
||||
|
</Grid> |
||||
|
</Page> |
@ -0,0 +1,87 @@ |
|||||
|
using CommunityToolkit.Mvvm.Messaging; |
||||
|
using CommunityToolkit.Mvvm.Messaging.Messages; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using System; |
||||
|
using System.Windows; |
||||
|
using System.Windows.Controls; |
||||
|
|
||||
|
namespace BBWYB.Client.Views.WebB |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// WebB_KPI.xaml 的交互逻辑
|
||||
|
/// </summary>
|
||||
|
public partial class WebB_KPI : Page |
||||
|
{ |
||||
|
private WebView2Manager w2m; |
||||
|
private bool isNavigated; |
||||
|
|
||||
|
private GlobalContext globalContext; |
||||
|
public WebB_KPI() |
||||
|
{ |
||||
|
InitializeComponent(); |
||||
|
|
||||
|
this.Loaded += WebB_KPI_Loaded; ; |
||||
|
this.Unloaded += WebB_KPI_Unloaded; |
||||
|
|
||||
|
WeakReferenceMessenger.Default.Register<Message_WebBKPI_Refresh>(this, (o, x) => |
||||
|
{ |
||||
|
this.Dispatcher.Invoke(() => |
||||
|
{ |
||||
|
_ = w2m.wb2.ExecuteScriptAsync("window.location.reload();"); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void WebB_KPI_Unloaded(object sender, RoutedEventArgs e) |
||||
|
{ |
||||
|
grid.Children.Remove(w2m.wb2); |
||||
|
w2m.Close(); |
||||
|
WeakReferenceMessenger.Default.UnregisterAll(this); |
||||
|
} |
||||
|
|
||||
|
private void WebB_KPI_Loaded(object sender, RoutedEventArgs e) |
||||
|
{ |
||||
|
var sp = (App.Current as App).ServiceProvider; |
||||
|
using (var s = sp.CreateScope()) |
||||
|
{ |
||||
|
w2m = s.ServiceProvider.GetRequiredService<WebView2Manager>(); |
||||
|
globalContext = s.ServiceProvider.GetRequiredService<GlobalContext>(); |
||||
|
} |
||||
|
|
||||
|
#if DEBUG
|
||||
|
var url = "http://localhost:8080/#/performance"; |
||||
|
var registerName = "webTestContext"; |
||||
|
#else
|
||||
|
var url = "http://qtbbwy.qiyue666.com/#/performance"; |
||||
|
var registerName = "webContext"; |
||||
|
#endif
|
||||
|
w2m.CoreWebView2InitializationCompleted = (e) => |
||||
|
{ |
||||
|
w2m.wb2.CoreWebView2.AddHostObjectToScript(registerName, this.globalContext); |
||||
|
isNavigated = true; |
||||
|
w2m.wb2.CoreWebView2.Navigate(url); |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
w2m.Init("bbwyb_web"); |
||||
|
w2m.wb2.SetValue(Grid.RowProperty, 1); |
||||
|
w2m.wb2.Margin = new Thickness(1, 0, 1, 0); |
||||
|
//grid.Children.Clear();
|
||||
|
grid.Children.Add(w2m.wb2); |
||||
|
|
||||
|
if (w2m.IsInitializationCompleted && !isNavigated) |
||||
|
{ |
||||
|
w2m.wb2.CoreWebView2.Navigate(url); |
||||
|
//w2m.wb2.CoreWebView2.NavigateToString(content);
|
||||
|
isNavigated = true; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public class Message_WebBKPI_Refresh : ValueChangedMessage<object> |
||||
|
{ |
||||
|
public Message_WebBKPI_Refresh(object value) : base(value) |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue