Browse Source

webb准备套页面

updatebug
shanji 2 years ago
parent
commit
9b5aed56e4
  1. 6
      BBWYB.Client/GlobalContext.cs
  2. 4
      BBWYB.Client/Views/WebB/WebB.xaml
  3. 47
      BBWYB.Client/Views/WebB/WebB.xaml.cs

6
BBWYB.Client/GlobalContext.cs

@ -1,5 +1,6 @@
using BBWYB.Client.Models;
using CommunityToolkit.Mvvm.ComponentModel;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace BBWYB.Client
@ -27,6 +28,11 @@ namespace BBWYB.Client
public string BBWYApiHost { get; set; }
public string MDSApiHost { get; set; }
public string GetUserString()
{
return JsonConvert.SerializeObject(User);
}
#endregion
}
}

4
BBWYB.Client/Views/WebB/WebB.xaml

@ -6,9 +6,9 @@
xmlns:local="clr-namespace:BBWYB.Client.Views.WebB"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="WebB" Background="Red">
Title="WebB">
<Grid>
<Grid x:Name="grid">
</Grid>
</Page>

47
BBWYB.Client/Views/WebB/WebB.xaml.cs

@ -1,4 +1,8 @@
using System.Windows.Controls;
using BBWYB.Client.APIServices;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
namespace BBWYB.Client.Views.WebB
{
@ -10,9 +14,50 @@ namespace BBWYB.Client.Views.WebB
private WebView2Manager w2m;
private bool isNavigated;
private IList<string> managerDepartment;
private MdsApiService mdsApiService;
private ShopService shopService;
private GlobalContext globalContext;
public WebB()
{
InitializeComponent();
this.Loaded += WebB_Loaded;
}
private void WebB_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
var sp = (App.Current as App).ServiceProvider;
using (var s = sp.CreateScope())
{
w2m = s.ServiceProvider.GetRequiredService<WebView2Manager>();
globalContext = s.ServiceProvider.GetRequiredService<GlobalContext>();
mdsApiService = s.ServiceProvider.GetRequiredService<MdsApiService>();
shopService = s.ServiceProvider.GetRequiredService<ShopService>();
}
var url = "http://qtbbwy.qiyue666.com";
w2m.CoreWebView2InitializationCompleted = (e) =>
{
w2m.wb2.CoreWebView2.AddHostObjectToScript("qtbbwybContext", this.globalContext);
isNavigated = true;
w2m.wb2.CoreWebView2.Navigate(url);
};
w2m.Init();
w2m.wb2.SetValue(Grid.RowProperty, 1);
w2m.wb2.Margin = new Thickness(1, 0, 1, 0);
grid.Children.Add(w2m.wb2);
if (w2m.IsInitializationCompleted && !isNavigated)
{
w2m.wb2.CoreWebView2.Navigate(url);
//w2m.wb2.CoreWebView2.NavigateToString(content);
isNavigated = true;
}
}
}
}

Loading…
Cancel
Save