You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.8 KiB
95 lines
2.8 KiB
using CommunityToolkit.Mvvm.Messaging;
|
|
using CommunityToolkit.Mvvm.Messaging.Messages;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using SJ.Controls;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
|
|
namespace BBWYB.Client.Views
|
|
{
|
|
/// <summary>
|
|
/// Web.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class Web : BWindow
|
|
{
|
|
private WebView2Manager w2m;
|
|
private bool isNavigated;
|
|
private GlobalContext globalContext;
|
|
|
|
public Web()
|
|
{
|
|
InitializeComponent();
|
|
this.Width = SystemParameters.WorkArea.Size.Width * 0.8;
|
|
this.Height = SystemParameters.WorkArea.Size.Height * 0.7;
|
|
var sp = (App.Current as App).ServiceProvider;
|
|
using (var s = sp.CreateScope())
|
|
{
|
|
w2m = new WebView2Manager();
|
|
globalContext = s.ServiceProvider.GetRequiredService<GlobalContext>();
|
|
}
|
|
|
|
|
|
|
|
WeakReferenceMessenger.Default.Register<Message_WebB_LoginCompleted>(this, (o, x) =>
|
|
{
|
|
this.Dispatcher.BeginInvoke(initWebView);
|
|
});
|
|
}
|
|
|
|
//public void InitCookieList()
|
|
//{
|
|
|
|
//}
|
|
|
|
|
|
private void Web_Loaded(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
private void initWebView()
|
|
{
|
|
#if DEBUG
|
|
var url = "http://qtbbwy.qiyue666.com";
|
|
var registerName = "webContext";
|
|
//var url = "http://192.168.1.2:8080";
|
|
//var registerName = "webTestContext";//webTestContext
|
|
//var url = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "s.html");
|
|
#else
|
|
var url = "http://qtbbwy.qiyue666.com";
|
|
var registerName = "webContext";
|
|
#endif
|
|
//var url = "http://qtbbwy.qiyue666.com";
|
|
w2m.CoreWebView2InitializationCompleted = (e) =>
|
|
{
|
|
globalContext.CurryWindow = this;
|
|
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_WebB_LoginCompleted : ValueChangedMessage<object>
|
|
{
|
|
public Message_WebB_LoginCompleted(object value) : base(value)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|